Blame SOURCES/tuned-2.3.0-assignment-modifiers.patch

684be3
From 1d1c3a389c393afa1e88d5629f5dff85824fc92b Mon Sep 17 00:00:00 2001
684be3
From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= <jskarvad@redhat.com>
684be3
Date: Wed, 7 May 2014 17:02:59 +0200
684be3
Subject: tuned: Added support for >, < assignment modifiers in tuned.conf
684be3
MIME-Version: 1.0
684be3
Content-Type: text/plain; charset=UTF-8
684be3
Content-Transfer-Encoding: 8bit
684be3
684be3
These modifiers can specify when to assign new value considering
684be3
the old value.
684be3
684be3
E.g.:
684be3
readahead=>4096
684be3
684be3
means assign readahead 4096 only if the current value of readahaed
684be3
is lower than 4096 (i.e. the readahaed will be at least 4096).
684be3
684be3
Similarly for the < operator, it will assign the value only
684be3
if the current value is higher.
684be3
684be3
The modifiers are part of the value, not part of the equality
684be3
operator, thus the following is correct:
684be3
readahead= >4096
684be3
684be3
But the following isn't correct, but will probably also work
684be3
due to the nature how the value is parsed:
684be3
readahead=> 4096
684be3
684be3
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
684be3
684be3
diff --git a/profiles/throughput-performance/tuned.conf b/profiles/throughput-performance/tuned.conf
684be3
index dae02dc..42473a9 100644
684be3
--- a/profiles/throughput-performance/tuned.conf
684be3
+++ b/profiles/throughput-performance/tuned.conf
684be3
@@ -11,7 +11,7 @@ min_perf_pct=100
684be3
 transparent_hugepages=always
684be3
 
684be3
 [disk]
684be3
-readahead=4096
684be3
+readahead=>4096
684be3
 
684be3
 [sysctl]
684be3
 # ktune sysctl settings for rhel6 servers, maximizing i/o throughput
684be3
diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py
684be3
index bad487f..f0faf38 100644
684be3
--- a/tuned/plugins/base.py
684be3
+++ b/tuned/plugins/base.py
684be3
@@ -212,7 +212,7 @@ class Plugin(object):
684be3
 
684be3
 	def _instance_apply_dynamic(self, instance, device):
684be3
 		for option in filter(lambda opt: self._storage_get(instance, self._commands[opt], device) is None, self._options_used_by_dynamic):
684be3
-			self._save_current_value(instance, self._commands[option], device)
684be3
+			self._check_and_save_value(instance, self._commands[option], device)
684be3
 
684be3
 		self._instance_update_dynamic(instance, device)
684be3
 
684be3
@@ -317,27 +317,50 @@ class Plugin(object):
684be3
 			for device in devices:
684be3
 				self._execute_device_command(instance, command, device, new_value)
684be3
 
684be3
-	def _save_current_value(self, instance, command, device = None):
684be3
+	def _check_and_save_value(self, instance, command, device = None, new_value = None):
684be3
 		if device is not None:
684be3
 			current_value = command["get"](device)
684be3
 		else:
684be3
 			current_value = command["get"]()
684be3
+		if new_value is not None:
684be3
+			nws = str(new_value)
684be3
+			op = nws[:1]
684be3
+			val = nws[1:]
684be3
+			try:
684be3
+				if op == ">":
684be3
+					if int(val) > int(current_value):
684be3
+						new_value = val;
684be3
+					else:
684be3
+						current_value = None
684be3
+						new_value = None
684be3
+				elif op == "<":
684be3
+					if int(val) < int(current_value):
684be3
+						new_value = val;
684be3
+					else:
684be3
+						current_value = None
684be3
+						new_value = None
684be3
+			except ValueError:
684be3
+				log.warn("cannot compare new value '%s' with current value '%s' by operator '%s', using '%s' directly as new value" % (val, current_value, op, new_value))
684be3
+
684be3
 		if current_value is not None:
684be3
 			self._storage_set(instance, command, current_value, device)
684be3
+		return new_value
684be3
 
684be3
 	def _execute_device_command(self, instance, command, device, new_value):
684be3
 		if command["custom"] is not None:
684be3
 			command["custom"](True, new_value, device)
684be3
 		else:
684be3
-			self._save_current_value(instance, command, device)
684be3
-			command["set"](new_value, device)
684be3
+			new_value = self._check_and_save_value(instance, command, device, new_value)
684be3
+			if new_value is not None:
684be3
+				command["set"](new_value, device)
684be3
 
684be3
 	def _execute_non_device_command(self, instance, command, new_value):
684be3
 		if command["custom"] is not None:
684be3
 			command["custom"](True, new_value)
684be3
 		else:
684be3
-			self._save_current_value(instance, command)
684be3
-			command["set"](new_value)
684be3
+			new_value = self._check_and_save_value(instance, command, None, new_value)
684be3
+			if new_value is not None:
684be3
+				command["set"](new_value)
684be3
 
684be3
 	def _cleanup_all_non_device_commands(self, instance):
684be3
 		for command in filter(lambda command: not command["per_device"], self._commands.values()):
684be3
-- 
684be3
cgit v0.10.1
684be3