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