KVM test: Adding KSM overcommit test
PATCH 1/1 KVM test: Adding KSM overcommit test
This is an implementation of KSM testing. The basic idea behind the test is to start guests, copy the script allocator.py to them. Once executed, the process accepts input commands on its main loop.
The script will allow to fill up memory pages of the guests, according to patterns, this way it's possible to have a large portion of guests memory exactly the same, so KSM can do memory merge.
Then we can easily split memory by filling memory of some guests with other values, and verify how KSM behaves according to each operation.
Test :
a] serial
1) initialize, merge all mem to single page
2) separate first guset mem
3) separate rest of guest up to fill all mem
4) kill all guests except for the last
5) check if mem of last guest is ok
6) kill guest
b] parallel
1) initialize, merge all mem to single page
2) separate mem of guest
3) verification of guest mem
4) merge mem to one block
5) verification of guests mem
6) separate mem of guests by 96B
7) check if mem is all right
8) kill guest
allocator.py (client side script)
After start they wait for command witch they make in client side. mem_fill class implement commands to fill, check mem and return error to host.
git-svn-id: svn://test.kernel.org/autotest/trunk@4264 592f7852-d20e-0410-864c-8624ca9c26a4
--- client/tests/kvm/kvm_test_utils.py | 36 ++- client/tests/kvm/kvm_utils.py | 16 + client/tests/kvm/kvm_vm.py | 17 + client/tests/kvm/scripts/allocator.py | 234 +++++++++++++ client/tests/kvm/tests/ksm_overcommit.py | 559 ++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 23 ++ 6 files changed, 884 insertions(+), 1 deletions(-) create mode 100755 client/tests/kvm/scripts/allocator.py create mode 100644 client/tests/kvm/tests/ksm_overcommit.py
client/tests/kvm/kvm_test_utils.py +35 -1
@@ -22,7 +22,8 @@ More specifically: """ import time, os, logging, re, commands -from autotest_lib.client.common_lib import utils, error +from autotest_lib.client.common_lib import error +from autotest_lib.client.bin import utils import kvm_utils, kvm_vm, kvm_subprocess
@@ -203,3 +204,36 @@ def get_time(session, time_command, time_filter_re, time_format): s = re.findall(time_filter_re, s)[0] guest_time = time.mktime(time.strptime(s, time_format)) return (host_time, guest_time) + + +def get_memory_info(lvms): + """ + Get memory information from host and guests in format: + Host: memfree = XXXM; Guests memsh = {XXX,XXX,...} + + @params lvms: List of VM objects + @return: String with memory info report + """ + if not isinstance(lvms, list): + raise error.TestError("Invalid list passed to get_stat: %s " % lvms) + + try: + meminfo = "Host: memfree = " + meminfo += str(int(utils.freememtotal()) / 1024) + "M; " + meminfo += "swapfree = " + mf = int(utils.read_from_meminfo("SwapFree")) / 1024 + meminfo += str(mf) + "M; " + except Exception, e: + raise error.TestFail("Could not fetch host free memory info, " + "reason: %s" % e) + + meminfo += "Guests memsh = {" + for vm in lvms: + shm = vm.get_shared_meminfo() + if shm is None: + raise error.TestError("Could not get shared meminfo from " + "VM %s" % vm) + meminfo += "%dM; " % shm + meminfo = meminfo[0:-2] + "}" + + return meminfo
client/tests/kvm/kvm_utils.py +16 -0
@@ -696,6 +696,22 @@ def generate_random_string(length): return str +def generate_tmp_file_name(file, ext=None, dir='/tmp/'): + """ + Returns a temporary file name. The file is not created. + """ + while True: + file_name = (file + '-' + time.strftime("%Y%m%d-%H%M%S-") + + generate_random_string(4)) + if ext: + file_name += '.' + ext + file_name = os.path.join(dir, file_name) + if not os.path.exists(file_name): + break + + return file_name + + def format_str_for_message(str): """ Format str so that it can be appended to a message.
client/tests/kvm/kvm_vm.py +17 -0
@@ -748,6 +748,23 @@ class VM: return self.process.get_pid() + def get_shared_meminfo(self): + """ + Returns the VM's shared memory information. + + @return: Shared memory used by VM (MB) + """ + if self.is_dead(): + logging.error("Could not get shared memory info from dead VM.") + return None + + cmd = "cat /proc/%d/statm" % self.params.get('pid_' + self.name) + shm = int(os.popen(cmd).readline().split()[2]) + # statm stores informations in pages, translate it to MB + shm = shm * 4 / 1024 + return shm + + def remote_login(self, nic_index=0, timeout=10): """ Log into the guest via SSH/Telnet/Netcat.
client/tests/kvm/scripts/allocator.py new file +234 -0
234 lines not on this page · raw message
client/tests/kvm/tests/ksm_overcommit.py new file +559 -0
559 lines not on this page · raw message
client/tests/kvm/tests_base.cfg.sample +23 -0
@@ -255,6 +255,28 @@ variants: type = physical_resources_check catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}' + - ksm_overcommit: + # Don't preprocess any vms as we need to change its params + vms = '' + image_snapshot = yes + kill_vm_gracefully = no + type = ksm_overcommit + # Make host use swap (a value of 'no' will turn off host swap) + ksm_swap = yes + no hugepages + # Overcommit of host memmory + ksm_overcommit_ratio = 3 + # Max paralel runs machine + ksm_parallel_ratio = 4 + # Host memory reserve + ksm_host_reserve = 512 + ksm_guest_reserve = 1024 + variants: + - ksm_serial + ksm_mode = "serial" + - ksm_parallel + ksm_mode = "parallel" + # system_powerdown, system_reset and shutdown *must* be the last ones # defined (in this order), since the effect of such tests can leave # the VM on a bad state.
@@ -278,6 +300,7 @@ variants: kill_vm_gracefully = no # Do not define test variants below shutdown + # NICs variants: - @rtl8139:
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest