From: Ryan Harper <ryanh@us.ibm.com>
To: Lucas Meneghel Rodrigues <lmr@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org,
ldoktor@redhat.com, ryanh@us.ibm.com, mgoldish@redhat.com
Subject: Re: [KVM-AUTOTEST PATCH] KVM test: Add hugepage variant
Date: Wed, 29 Jul 2009 09:41:04 -0500 [thread overview]
Message-ID: <20090729144104.GA21912@us.ibm.com> (raw)
In-Reply-To: <1248838829-7804-1-git-send-email-lmr@redhat.com>
* Lucas Meneghel Rodrigues <lmr@redhat.com> [2009-07-28 22:40]:
> This patch adds a small setup script to set up huge memory
> pages during the kvm tests execution. Also, added hugepage setup to the
> fc8_quick sample.
>
> Signed-off-by: Luká?? Doktor <ldoktor@redhat.com>
> Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
Looks good. one nit below.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
> ---
> client/tests/kvm/kvm_tests.cfg.sample | 8 +++
> client/tests/kvm/kvm_vm.py | 11 +++
> client/tests/kvm/scripts/hugepage.py | 109 +++++++++++++++++++++++++++++++++
> 3 files changed, 128 insertions(+), 0 deletions(-)
> create mode 100644 client/tests/kvm/scripts/hugepage.py
>
> diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
> index 2d75a66..7cd12cb 100644
> --- a/client/tests/kvm/kvm_tests.cfg.sample
> +++ b/client/tests/kvm/kvm_tests.cfg.sample
> @@ -587,6 +587,13 @@ variants:
>
>
> variants:
> + - @kvm_smallpages:
> + - kvm_hugepages:
> + pre_command = "/usr/bin/python scripts/hugepage.py /mnt/kvm_hugepage"
> + extra_params += " -mem-path /mnt/kvm_hugepage"
> +
> +
> +variants:
> - @basic:
> only Fedora Windows
> - @full:
> @@ -598,6 +605,7 @@ variants:
> only Fedora.8.32
> only install setup boot shutdown
> only rtl8139
> + only kvm_hugepages
> - @sample1:
> only qcow2
> only ide
> diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
> index d96b359..eba9b84 100644
> --- a/client/tests/kvm/kvm_vm.py
> +++ b/client/tests/kvm/kvm_vm.py
> @@ -397,6 +397,17 @@ class VM:
> self.destroy()
> return False
>
> + # Get the output so far, to see if we have any problems with
> + # hugepage setup.
> + output = self.process.get_output()
> +
> + if "alloc_mem_area" in output:
> + logging.error("Could not allocate hugepage memory; "
> + "qemu command:\n%s" % qemu_command)
> + logging.error("Output:" + kvm_utils.format_str_for_message(
> + self.process.get_output()))
> + return False
> +
> logging.debug("VM appears to be alive with PID %d",
> self.process.get_pid())
> return True
> diff --git a/client/tests/kvm/scripts/hugepage.py b/client/tests/kvm/scripts/hugepage.py
> new file mode 100644
> index 0000000..dc36da4
> --- /dev/null
> +++ b/client/tests/kvm/scripts/hugepage.py
> @@ -0,0 +1,109 @@
> +#!/usr/bin/python
> +# -*- coding: utf-8 -*-
> +import os, sys, time
> +
> +"""
> +Simple script to allocate enough hugepages for KVM testing purposes.
> +"""
> +
> +class HugePageError(Exception):
> + """
> + Simple wrapper for the builtin Exception class.
> + """
> + pass
> +
> +
> +class HugePage:
> + def __init__(self, hugepage_path=None):
> + """
> + Gets environment variable values and calculates the target number
> + of huge memory pages.
> +
> + @param hugepage_path: Path where to mount hugetlbfs path, if not
> + yet configured.
> + """
> + self.vms = len(os.environ['KVM_TEST_vms'].split())
> + self.mem = int(os.environ['KVM_TEST_mem'])
> + try:
> + self.max_vms = int(os.environ['KVM_TEST_max_vms'])
> + except KeyError:
> + self.max_vms = 0
> +
> + if hugepage_path:
> + self.hugepage_path = hugepage_path
> + else:
> + self.hugepage_path = '/mnt/kvm_hugepage'
> +
> + self.hugepage_size = self.get_hugepage_size()
> + self.target_hugepages = self.get_target_hugepages()
> +
> +
> + def get_hugepage_size(self):
> + """
> + Get the current system setting for huge memory page size.
> + """
> + meminfo = open('/proc/meminfo', 'r').readlines()
> + huge_line_list = [h for h in meminfo if h.startswith("Hugepagesize")]
> + try:
> + return int(huge_line_list[0].split()[1])
> + except ValueError, e:
> + raise HugePageError("Could not get huge page size setting from "
> + "/proc/meminfo: %s" % e)
> +
> +
> + def get_target_hugepages(self):
> + """
> + Calculate the target number of hugepages for testing purposes.
> + """
> + if self.vms < self.max_vms:
> + self.vms = self.max_vms
> + vmsm = (self.vms * self.mem) + (self.vms * 64)
Nit: Maybe a comment about the fudge factor being added in?
> + return int(vmsm * 1024 / self.hugepage_size)
> +
> +
> + def set_hugepages(self):
> + """
> + Sets the hugepage limit to the target hugepage value calculated.
> + """
> + hugepage_cfg = open("/proc/sys/vm/nr_hugepages", "r+")
> + hp = hugepage_cfg.readline()
> + while int(hp) < self.target_hugepages:
> + loop_hp = hp
> + hugepage_cfg.write(str(self.target_hugepages))
> + hugepage_cfg.flush()
> + hugepage_cfg.seek(0)
> + hp = int(hugepage_cfg.readline())
> + if loop_hp == hp:
> + raise HugePageError("Cannot set the kernel hugepage setting "
> + "to the target value of %d hugepages." %
> + self.target_hugepages)
> + hugepage_cfg.close()
> +
> +
> + def mount_hugepage_fs(self):
> + """
> + Verify if there's a hugetlbfs mount set. If there's none, will set up
> + a hugetlbfs mount using the class attribute that defines the mount
> + point.
> + """
> + if not os.path.ismount(self.hugepage_path):
> + if not os.path.isdir(self.hugepage_path):
> + os.makedirs(self.hugepage_path)
> + cmd = "mount -t hugetlbfs none %s" % self.hugepage_path
> + if os.system(cmd):
> + raise HugePageError("Cannot mount hugetlbfs path %s" %
> + self.hugepage_path)
> +
> +
> + def setup(self):
> + self.set_hugepages()
> + self.mount_hugepage_fs()
> +
> +
> +if __name__ == "__main__":
> + if len(sys.argv) < 2:
> + huge_page = HugePage()
> + else:
> + huge_page = HugePage(sys.argv[1])
> +
> + huge_page.setup()
> --
> 1.6.2.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
ryanh@us.ibm.com
next prev parent reply other threads:[~2009-07-29 14:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-29 3:40 [KVM-AUTOTEST PATCH] KVM test: Add hugepage variant Lucas Meneghel Rodrigues
2009-07-29 3:40 ` [KVM AUTOTEST PATCH] [RFC] KVM test: keep record of supported qemu options Lucas Meneghel Rodrigues
2009-07-29 8:11 ` Lukáš Doktor
2009-07-29 12:11 ` [Autotest] " Lucas Meneghel Rodrigues
2009-07-29 8:02 ` [KVM-AUTOTEST PATCH] KVM test: Add hugepage variant Lukáš Doktor
2009-07-29 14:41 ` Ryan Harper [this message]
2009-08-04 13:00 ` Lukáš Doktor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090729144104.GA21912@us.ibm.com \
--to=ryanh@us.ibm.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=ldoktor@redhat.com \
--cc=lmr@redhat.com \
--cc=mgoldish@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.