Skip to contentSkip to conversation

KVM test: KSM (kernel shared memory) overcommit test

PATCH New Lucas Meneghel Rodrigues 1 participant 1 message Jan 12, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM test: KSM (kernel shared memory) overcommit test

Functionality:
KSM test start guests. They are connect to guest over ssh. Copy and run allocator.py to guests.
Host can run any python command over allocator.py loop on client side.

Start run_ksm_overcommit.
Define host and guest reserve variables (host_reserver,guest_reserver). Calculate amount of virtual machine and their memory based on variables host_mem and overcommit.
Check KSM status.
Create and start virtual guests.
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.

---
 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    |  230 ++++++++++++
 client/tests/kvm/tests/ksm_overcommit.py |  573 ++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample   |   18 +
 6 files changed, 889 insertions(+), 1 deletions(-)
 create mode 100644 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
index 02ec0cf..7d96d6e 100644
@@ -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
index 2bbbe22..0118742 100644
@@ -713,6 +713,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
index 7229b79..e52f826 100755
@@ -690,6 +690,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 +230 -0

230 lines not on this page · raw message

client/tests/kvm/tests/ksm_overcommit.py new file +573 -0

573 lines not on this page · raw message

client/tests/kvm/tests_base.cfg.sample +18 -0
index b8f25f4..24c789d 100644
@@ -270,6 +270,24 @@ 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
+        ksm_swap = yes
+        no hugepages
+        # Overcommit of host memmory
+        ksm_overcommit_ratio = 3
+        # Max paralel runs machine
+        ksm_parallel_ratio = 4
+        variants:
+            - ksm_serial
+                ksm_test_size = "serial"
+            - ksm_parallel
+                ksm_test_size = "parallel"
+
 # NICs
 variants:
     - @rtl8139:
Signature · 1 line
1.6.5.2