From 9b9a712ec4e96e2af2d05476cb7e48c8d1602f16 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 9 Feb 2017 11:57:45 +0000 Subject: [PATCH] Lower vm.swappiness to reduce guest memory latency Lowering the value of vm.swappiness to 1 (minimum amount of swapping without disabling it entirely) should reduce the guest memory latency. The default of 1 in the charm can be changed by the user by explicitly setting vm.swappiness in the sysctl charm setting. Change-Id: If9d3a9a0d15a84b86cfa7ba3620b66e7ea61d414 Closes-Bug: 1660248 --- hooks/nova_compute_hooks.py | 10 +++++++--- unit_tests/test_nova_compute_hooks.py | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hooks/nova_compute_hooks.py b/hooks/nova_compute_hooks.py index 9b917650..a5919ff5 100755 --- a/hooks/nova_compute_hooks.py +++ b/hooks/nova_compute_hooks.py @@ -17,6 +17,7 @@ import platform import sys import uuid +import yaml from charmhelpers.core.hookenv import ( Hooks, @@ -149,9 +150,12 @@ def config_changed(): do_openstack_upgrade(CONFIGS) send_remote_restart = True - sysctl_dict = config('sysctl') - if sysctl_dict: - create_sysctl(sysctl_dict, '/etc/sysctl.d/50-nova-compute.conf') + sysctl_settings = config('sysctl') + if sysctl_settings: + sysctl_dict = yaml.safe_load(sysctl_settings) + sysctl_dict['vm.swappiness'] = sysctl_dict.get('vm.swappiness', 1) + create_sysctl(yaml.dump(sysctl_dict), + '/etc/sysctl.d/50-nova-compute.conf') destroy_libvirt_network('default') diff --git a/unit_tests/test_nova_compute_hooks.py b/unit_tests/test_nova_compute_hooks.py index f48114a1..a879d0da 100644 --- a/unit_tests/test_nova_compute_hooks.py +++ b/unit_tests/test_nova_compute_hooks.py @@ -236,9 +236,24 @@ class NovaComputeRelationsTests(CharmTestCase): @patch.object(hooks, 'compute_joined') def test_config_changed_with_sysctl(self, compute_joined): self.git_install_requested.return_value = False - self.test_config.set('sysctl', '{ kernel.max_pid : "1337" }') + self.test_config.set( + 'sysctl', + '{ kernel.max_pid : "1337", vm.swappiness : 10 }') hooks.config_changed() - self.assertTrue(self.create_sysctl.called) + self.create_sysctl.assert_called_with( + "{kernel.max_pid: '1337', vm.swappiness: 10}\n", + '/etc/sysctl.d/50-nova-compute.conf') + + @patch.object(hooks, 'compute_joined') + def test_config_changed_with_sysctl_swappy_default(self, compute_joined): + self.git_install_requested.return_value = False + self.test_config.set( + 'sysctl', + '{ kernel.max_pid : "1337" }') + hooks.config_changed() + self.create_sysctl.assert_called_with( + "{kernel.max_pid: '1337', vm.swappiness: 1}\n", + '/etc/sysctl.d/50-nova-compute.conf') @patch.object(hooks, 'config_value_changed') def test_config_changed_git(self, config_val_changed):