From patchwork Mon Jun 14 13:35:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?THVrw6HFoSBEb2t0b3I=?= X-Patchwork-Id: 105957 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5EDa1dY008705 for ; Mon, 14 Jun 2010 13:36:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753830Ab0FNNf6 (ORCPT ); Mon, 14 Jun 2010 09:35:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14087 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753289Ab0FNNf6 (ORCPT ); Mon, 14 Jun 2010 09:35:58 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5EDZtsP018583 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Jun 2010 09:35:55 -0400 Received: from localhost.localdomain (vpn2-9-253.ams2.redhat.com [10.36.9.253]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5EDZjXe012794; Mon, 14 Jun 2010 09:35:49 -0400 From: Lukas Doktor To: ldoktor@redhat.com Cc: jzupka@redhat.com, kvm@vger.kernel.org, autotest@test.kernel.org, jasowang@redhat.com Subject: [PATCH] Adds support for newer (sysfs) ksm interface Date: Mon, 14 Jun 2010 14:35:42 +0100 Message-Id: <1276522542-2559-2-git-send-email-ldoktor@redhat.com> In-Reply-To: <1276522542-2559-1-git-send-email-ldoktor@redhat.com> References: <1276522542-2559-1-git-send-email-ldoktor@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 14 Jun 2010 13:36:02 +0000 (UTC) diff --git a/client/tests/kvm/tests/ksm_overcommit.py b/client/tests/kvm/tests/ksm_overcommit.py index 2b791f1..a19b815 100644 --- a/client/tests/kvm/tests/ksm_overcommit.py +++ b/client/tests/kvm/tests/ksm_overcommit.py @@ -59,6 +59,18 @@ def run_ksm_overcommit(test, params, env): return (match, data) + def get_ksmstat(): + """ + Return sharing memory by ksm in MB + + @return: memory in MB + """ + f = open('/sys/kernel/mm/ksm/pages_sharing') + ksm_pages = int(f.read()) + f.close() + return ((ksm_pages*4096)/1e6) + + def initialize_guests(): """ Initialize guests (fill their memories with specified patterns). @@ -88,21 +100,25 @@ def run_ksm_overcommit(test, params, env): # Let allocator.py do its job # (until shared mem reaches expected value) shm = 0 - i = 0 + j = 0 logging.debug("Target shared meminfo for guest %s: %s", vm.name, ksm_size) - while shm < ksm_size: - if i > 64: + while ((new_ksm and (shm < (ksm_size*(i+1)))) or + (not new_ksm and (shm < (ksm_size)))): + if j > 64: logging.debug(kvm_test_utils.get_memory_info(lvms)) raise error.TestError("SHM didn't merge the memory until " "the DL on guest: %s" % vm.name) st = ksm_size / 200 * perf_ratio logging.debug("Waiting %ds before proceeding..." % st) time.sleep(st) - shm = vm.get_shared_meminfo() + if (new_ksm): + shm = get_ksmstat() + else: + shm = vm.get_shared_meminfo() logging.debug("Shared meminfo for guest %s after " - "iteration %s: %s", vm.name, i, shm) - i += 1 + "iteration %s: %s", vm.name, j, shm) + j += 1 # Keep some reserve rt = ksm_size / 200 * perf_ratio @@ -263,14 +279,17 @@ def run_ksm_overcommit(test, params, env): shm = 0 i = 0 logging.debug("Target shared memory size: %s", ksm_size) - while shm < ksm_size: + while (shm < ksm_size): if i > 64: logging.debug(kvm_test_utils.get_memory_info(lvms)) raise error.TestError("SHM didn't merge the memory until DL") wt = ksm_size / 200 * perf_ratio logging.debug("Waiting %ds before proceed...", wt) time.sleep(wt) - shm = vm.get_shared_meminfo() + if (new_ksm): + shm = get_ksmstat() + else: + shm = vm.get_shared_meminfo() logging.debug("Shared meminfo after attempt %s: %s", i, shm) i += 1 @@ -348,6 +367,18 @@ def run_ksm_overcommit(test, params, env): # Main test code logging.info("Starting phase 0: Initialization") + new_ksm = False + if (os.path.exists("/sys/kernel/mm/ksm/run")): + utils.run("echo 50 > /sys/kernel/mm/ksm/sleep_millisecs") + utils.run("echo 5000 > /sys/kernel/mm/ksm/pages_to_scan") + utils.run("echo 1 > /sys/kernel/mm/ksm/run") + new_ksm = True + else: + try: + utils.run("modprobe ksm") + utils.run("ksmctl start 5000 100") + except error.CmdError, e: + raise error.TestFail("Failed to load KSM: %s" % e) # host_reserve: mem reserve kept for the host system to run host_reserve = int(params.get("ksm_host_reserve", -1)) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index ab8922b..b377eeb 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -315,8 +315,6 @@ variants: catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}' - ksm_overcommit: - pre_command = "[ -e /dev/ksm ] && true || modprobe ksm && ksmctl start 5000 50" - pre_command_critical = yes # Don't preprocess any vms as we need to change its params vms = '' image_snapshot = yes