From b078feecdf92a43be65240b100ceb16062b7416b Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Mon, 28 Jan 2013 14:49:14 +0100 Subject: [PATCH] vm plugin: migrate to new plugin interface --- tuned/plugins/plugin_vm.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tuned/plugins/plugin_vm.py b/tuned/plugins/plugin_vm.py index 69fb36b..78d2122 100644 --- a/tuned/plugins/plugin_vm.py +++ b/tuned/plugins/plugin_vm.py @@ -13,38 +13,37 @@ class VMPlugin(base.Plugin): Plugin for tuning memory management. """ - @classmethod - def tunable_devices(self): - return ["vm"] - - def _post_init(self): - self._dynamic_tuning = False - - @classmethod - def _get_default_options(cls): + def _get_config_options(self): return { "transparent_hugepages" : None, } - @classmethod + def _instance_init(self, instance): + instance._has_static_tuning = True + instance._has_dynamic_tuning = False + + def _instance_cleanup(self, instance): + pass + def _thp_file(self): return "/sys/kernel/mm/redhat_transparent_hugepage/enabled" @command_set("transparent_hugepages") def _set_transparent_hugepages(self, value): if value not in ["always", "never"]: - log.warn("Incorrect transparent_hugepages value.") + log.warn("Incorrect 'transparent_hugepages' value.") return - sys_file = VMPlugin._thp_file() - if not os.path.exists(sys_file): - return - - tuned.utils.commands.write_to_file(sys_file, value) + sys_file = self._thp_file() + if os.path.exists(sys_file): + tuned.utils.commands.write_to_file(sys_file, value) + else: + log.warn("Option 'transparent_hugepages' is not supported on current hardware.") @command_get("transparent_hugepages") def _get_transparent_hugepages(self): - sys_file = VMPlugin._thp_file() - if not os.path.exists(sys_file): + sys_file = self._thp_file() + if os.path.exists(sys_file): + return tuned.utils.commands.get_active_option(tuned.utils.commands.read_file(sys_file)) + else: return None - return tuned.utils.commands.get_active_option(tuned.utils.commands.read_file(sys_file))