Beispiel #1
0
def cmd_runner_monitor(vm, monitor_cmd, test_cmd, guest_path, timeout=300):
    """
    For record the env information such as cpu utilization, meminfo while
    run guest test in guest.
    @vm: Guest Object
    @monitor_cmd: monitor command running in backgroud
    @test_cmd: test suit run command
    @guest_path: path in guest to store the test result and monitor data
    @timeout: longest time for monitor running
    Return: tag the suffix of the results
    """
    def thread_kill(cmd, p_file):
        fd = shelve.open(p_file)
        o = commands.getoutput("pstree -p %s" % fd["pid"])
        tmp = re.split("\s+", cmd)[0]
        pid = re.findall("%s.(\d+)" % tmp, o)[0]
        s, o = commands.getstatusoutput("kill -9 %s" % pid)
        fd.close()
        return (s, o)

    def monitor_thread(m_cmd, p_file, r_file):
        fd = shelve.open(p_file)
        fd["pid"] = os.getpid()
        fd.close()
        os.system("%s &> %s" % (m_cmd, r_file))

    def test_thread(session, m_cmd, t_cmd, p_file, flag, timeout):
        flag.put(True)
        s, o = session.cmd_status_output(t_cmd, timeout)
        if s != 0:
            raise error.TestFail("Test failed or timeout: %s" % o)
        if not flag.empty():
            flag.get()
            thread_kill(m_cmd, p_file)

    kill_thread_flag = Queue(1)
    session = utils_test.wait_for_login(vm, 0, 300, 0, 2)
    tag = vm.instance
    pid_file = "/tmp/monitor_pid_%s" % tag
    result_file = "/tmp/host_monitor_result_%s" % tag

    monitor = threading.Thread(target=monitor_thread, args=(monitor_cmd,
                                                            pid_file, result_file))
    test_runner = threading.Thread(target=test_thread, args=(session,
                                   monitor_cmd, test_cmd, pid_file,
                                   kill_thread_flag, timeout))
    monitor.start()
    test_runner.start()
    monitor.join(int(timeout))
    if not kill_thread_flag.empty():
        kill_thread_flag.get()
        thread_kill(monitor_cmd, pid_file)
        thread_kill("sh", pid_file)

    guest_result_file = "/tmp/guest_result_%s" % tag
    guest_monitor_result_file = "/tmp/guest_monitor_result_%s" % tag
    vm.copy_files_from(guest_path, guest_result_file)
    vm.copy_files_from("%s_monitor" % guest_path, guest_monitor_result_file)
    return tag
Beispiel #2
0
def run_set_link(test, params, env):
    """
    KVM guest link test:
    1) Boot up guest with one nic
    2) Ping guest from host
    3) Disable guest link and ping guest from host
    4) Re-enable guest link and ping guest from host
    5) Do file transfer test

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    timeout = float(params.get("login_timeout", 360))
    session = utils_test.wait_for_login(vm, 0, timeout, 0, 2)

    def set_link_test(linkid):
        """
        Issue set_link commands and test its function

        @param linkid: id of netdev or devices to be tested
        """
        ip = vm.get_address(0)

        vm.set_link(linkid, up=False)
        _, o = utils_test.ping(ip, count=10, timeout=20)
        if utils_test.get_loss_ratio(o) != 100:
            raise error.TestFail("Still can ping the %s after down %s" %
                                 (ip, linkid))

        vm.set_link(linkid, up=True)
        _, o = utils_test.ping(ip, count=10, timeout=20)
        # we use 100% here as the notification of link status changed may be
        # delayed in guest driver
        if utils_test.get_loss_ratio(o) == 100:
            raise error.TestFail("Packet loss during ping %s after up %s" %
                                 (ip, linkid))

    netdev_id = vm.netdev_id[0]
    device_id = vm.get_peer(netdev_id)
    logging.info("Issue set_link commands for netdevs")
    set_link_test(netdev_id)
    logging.info("Issue set_link commands for network devics")
    set_link_test(device_id)

    utils_test.run_file_transfer(test, params, env)
    session.close()
Beispiel #3
0
def run_trans_hugepage(test, params, env):
    """
    KVM kernel hugepages user side test:
    1) Smoke test
    2) Stress test

    @param test: QEMU test object.
    @param params: Dictionary with test parameters.
    @param env: Dictionary with the test environment.
    """
    def get_mem_status(params, role):
        if role == "host":
            info = utils.system_output("cat /proc/meminfo")
        else:
            info = session.cmd("cat /proc/meminfo")
        for h in re.split("\n+", info):
            if h.startswith("%s" % params):
                output = re.split('\s+', h)[1]
        return output


    dd_timeout = float(params.get("dd_timeout", 900))
    mem = params['mem']
    failures = []

    debugfs_flag = 1
    debugfs_path = os.path.join(test.tmpdir, 'debugfs')
    mem_path = os.path.join("/tmp", 'thp_space')

    login_timeout = float(params.get("login_timeout", "3600"))

    error.context("smoke test setup")
    if not os.path.ismount(debugfs_path):
        if not os.path.isdir(debugfs_path):
            os.makedirs(debugfs_path)
        utils.run("mount -t debugfs none %s" % debugfs_path)

    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    try:
        logging.info("Smoke test start")
        error.context("smoke test")

        nr_ah_before = int(get_mem_status('AnonHugePages', 'host'))
        if nr_ah_before <= 0:
            e_msg = 'smoke: Host is not using THP'
            logging.error(e_msg)
            failures.append(e_msg)

        # Protect system from oom killer
        if int(get_mem_status('MemFree', 'guest')) / 1024 < mem :
            mem = int(get_mem_status('MemFree', 'guest')) / 1024

        session.cmd("mkdir -p %s" % mem_path)

        session.cmd("mount -t tmpfs -o size=%sM none %s" % (str(mem), mem_path))

        count = mem / 4
        session.cmd("dd if=/dev/zero of=%s/1 bs=4000000 count=%s" %
                    (mem_path, count), timeout=dd_timeout)

        nr_ah_after = int(get_mem_status('AnonHugePages', 'host'))

        if nr_ah_after <= nr_ah_before:
            e_msg = ('smoke: Host did not use new THP during dd')
            logging.error(e_msg)
            failures.append(e_msg)

        if debugfs_flag == 1:
            if int(open('%s/kvm/largepages' % debugfs_path, 'r').read()) <= 0:
                e_msg = 'smoke: KVM is not using THP'
                logging.error(e_msg)
                failures.append(e_msg)

        logging.info("Smoke test finished")

        # Use parallel dd as stress for memory
        count = count / 3
        logging.info("Stress test start")
        error.context("stress test")
        cmd = "rm -rf %s/*; for i in `seq %s`; do dd " % (mem_path, count)
        cmd += "if=/dev/zero of=%s/$i bs=4000000 count=1& done;wait" % mem_path
        output = session.cmd_output(cmd, timeout=dd_timeout)

        if len(re.findall("No space", output)) > count * 0.05:
            e_msg = "stress: Too many dd instances failed in guest"
            logging.error(e_msg)
            failures.append(e_msg)

        try:
            output = session.cmd('pidof dd')
        except Exception:
            output = None

        if output is not None:
            for i in re.split('\n+', output):
                session.cmd('kill -9 %s' % i)

        session.cmd("umount %s" % mem_path)

        logging.info("Stress test finished")

    finally:
        error.context("all tests cleanup")
        if os.path.ismount(debugfs_path):
            utils.run("umount %s" % debugfs_path)
        if os.path.isdir(debugfs_path):
            os.removedirs(debugfs_path)
        session.close()

    error.context("")
    if failures:
        raise error.TestFail("THP base test reported %s failures:\n%s" %
                             (len(failures), "\n".join(failures)))
Beispiel #4
0
def run_trans_hugepage(test, params, env):
    """
    KVM kernel hugepages user side test:
    1) Smoke test
    2) Stress test

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    def get_mem_status(params, role):
        if role == "host":
            info = utils.system_output("cat /proc/meminfo")
        else:
            info = session.cmd("cat /proc/meminfo")
        for h in re.split("\n+", info):
            if h.startswith("%s" % params):
                output = re.split('\s+', h)[1]
        return output

    dd_timeout = float(params.get("dd_timeout", 900))
    mem = params['mem']
    failures = []

    debugfs_flag = 1
    debugfs_path = os.path.join(test.tmpdir, 'debugfs')
    mem_path = os.path.join("/tmp", 'thp_space')

    login_timeout = float(params.get("login_timeout", "3600"))

    error.context("smoke test setup")
    if not os.path.ismount(debugfs_path):
        if not os.path.isdir(debugfs_path):
            os.makedirs(debugfs_path)
        utils.run("mount -t debugfs none %s" % debugfs_path)

    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    funcatexit.register(env, params.get("type"), cleanup, debugfs_path,
                        session)

    logging.info("Smoke test start")
    error.context("smoke test")

    nr_ah_before = int(get_mem_status('AnonHugePages', 'host'))
    if nr_ah_before <= 0:
        e_msg = 'smoke: Host is not using THP'
        logging.error(e_msg)
        failures.append(e_msg)

    # Protect system from oom killer
    if int(get_mem_status('MemFree', 'guest')) / 1024 < mem:
        mem = int(get_mem_status('MemFree', 'guest')) / 1024

    session.cmd("mkdir -p %s" % mem_path)

    session.cmd("mount -t tmpfs -o size=%sM none %s" % (str(mem), mem_path))

    count = mem / 4
    session.cmd("dd if=/dev/zero of=%s/1 bs=4000000 count=%s" %
                (mem_path, count),
                timeout=dd_timeout)

    nr_ah_after = int(get_mem_status('AnonHugePages', 'host'))

    if nr_ah_after <= nr_ah_before:
        e_msg = ('smoke: Host did not use new THP during dd')
        logging.error(e_msg)
        failures.append(e_msg)

    if debugfs_flag == 1:
        if int(open('%s/kvm/largepages' % debugfs_path, 'r').read()) <= 0:
            e_msg = 'smoke: KVM is not using THP'
            logging.error(e_msg)
            failures.append(e_msg)

    logging.info("Smoke test finished")

    # Use parallel dd as stress for memory
    count = count / 3
    logging.info("Stress test start")
    error.context("stress test")
    cmd = "rm -rf %s/*; for i in `seq %s`; do dd " % (mem_path, count)
    cmd += "if=/dev/zero of=%s/$i bs=4000000 count=1& done;wait" % mem_path
    output = session.cmd_output(cmd, timeout=dd_timeout)

    if len(re.findall("No space", output)) > count * 0.05:
        e_msg = "stress: Too many dd instances failed in guest"
        logging.error(e_msg)
        failures.append(e_msg)

    try:
        output = session.cmd('pidof dd')
    except Exception:
        output = None

    if output is not None:
        for i in re.split('\n+', output):
            session.cmd('kill -9 %s' % i)

    session.cmd("umount %s" % mem_path)

    logging.info("Stress test finished")

    error.context("")
    if failures:
        raise error.TestFail("THP base test reported %s failures:\n%s" %
                             (len(failures), "\n".join(failures)))
Beispiel #5
0
def run_nic_hotplug(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one nic
    2) Add a host network device through monitor cmd and check if it's added
    3) Add nic device through monitor cmd and check if it's added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev
    8) Re-enable primary link of guest

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The KVM autotest default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    @param test:   QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env:    Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    login_timeout = int(params.get("login_timeout", 360))
    pci_model = params.get("pci_model", "rtl8139")
    run_dhclient = params.get("run_dhclient", "no")

    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    guest_is_not_windows = "Win" not in params.get("guest_name", "")

    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    udev_rules_path = "/etc/udev/rules.d/70-persistent-net.rules"
    udev_rules_bkp_path = "/tmp/70-persistent-net.rules"

    def guest_path_isfile(path):
        try:
            session.cmd("test -f %s" % path)
        except aexpect.ShellError:
            return False
        return True

    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_path):
            session.cmd("mv -f %s %s" % (udev_rules_path, udev_rules_bkp_path))

        # Modprobe the module if specified in config file
        module = params.get("modprobe_module")
        if module:
            session.get_command_output("modprobe %s" % module)

    # hot-add the nic
    nic_name = 'hotadded'
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype)

    # Only run dhclient if explicitly set and guest is not running Windows.
    # Most modern Linux guests run NetworkManager, and thus do not need this.
    if run_dhclient == "yes" and guest_is_not_windows:
        session_serial = vm.wait_for_serial_login(timeout=login_timeout)
        ifname = utils_test.get_linux_ifname(session, nic_info['mac'])
        session_serial.cmd("dhclient %s &" % ifname)

    logging.info("Shutting down the primary link(s)")
    for nic in vm.virtnet:
        if not (nic.nic_name == nic_name):
            vm.set_link(nic.device_id, up=False)

    try:
        logging.info("Waiting for new nic's ip address acquisition...")
        try:
            ip = vm.wait_for_get_address(nic_name)
        except virt_vm.VMIPAddressMissingError:
            raise error.TestFail("Could not get or verify ip address of nic")
        logging.info("Got the ip address of new nic: %s", ip)

        logging.info("Ping test the new nic ...")
        s, o = utils_test.ping(ip, 100)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test")

        logging.info("Detaching the previously attached nic from vm")
        vm.hotunplug_nic(nic_name)

    finally:
        logging.info("Re-enabling the primary link(s)")
        for nic in vm.virtnet:
            if not (nic.nic_name == nic_name):
                vm.set_link(nic.device_id, up=True)

    # Attempt to put back udev network naming rules, even if the command to
    # disable the rules failed. We may be undoing what was done in a previous
    # (failed) test that never reached this point.
    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_bkp_path):
            session.cmd("mv -f %s %s" % (udev_rules_bkp_path, udev_rules_path))
Beispiel #6
0
def run_nic_hotplug(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one nic
    2) Add a host network device through monitor cmd and check if it's added
    3) Add nic device through monitor cmd and check if it's added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev
    8) Re-enable primary link of guest

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The KVM autotest default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    @param test:   KVM test object.
    @param params: Dictionary with the test parameters.
    @param env:    Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    login_timeout = int(params.get("login_timeout", 360))
    pci_model = params.get("pci_model", "rtl8139")
    run_dhclient = params.get("run_dhclient", "no")

    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    guest_is_not_windows = "Win" not in params.get("guest_name", "")

    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    udev_rules_path = "/etc/udev/rules.d/70-persistent-net.rules"
    udev_rules_bkp_path = "/tmp/70-persistent-net.rules"

    def guest_path_isfile(path):
        try:
            session.cmd("test -f %s" % path)
        except aexpect.ShellError:
            return False
        return True

    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_path):
            session.cmd("mv -f %s %s" % (udev_rules_path, udev_rules_bkp_path))

        # Modprobe the module if specified in config file
        module = params.get("modprobe_module")
        if module:
            session.get_command_output("modprobe %s" % module)

    # hot-add the nic
    nic_name = 'hotadded'
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype)

    # Only run dhclient if explicitly set and guest is not running Windows.
    # Most modern Linux guests run NetworkManager, and thus do not need this.
    if run_dhclient == "yes" and guest_is_not_windows:
        session_serial = vm.wait_for_serial_login(timeout=login_timeout)
        ifname = utils_test.get_linux_ifname(session, nic_info['mac'])
        session_serial.cmd("dhclient %s &" % ifname)

    logging.info("Shutting down the primary link(s)")
    for nic in vm.virtnet:
        if nic.nic_name == nic_name:
            continue
        else:
            vm.monitor.cmd("set_link %s off" % nic.device_id)

    try:
        logging.info("Waiting for new nic's ip address acquisition...")
        try:
            ip = vm.wait_for_get_address(nic_name)
        except virt_vm.VMIPAddressMissingError:
            raise error.TestFail("Could not get or verify ip address of nic")
        logging.info("Got the ip address of new nic: %s", ip)

        logging.info("Ping test the new nic ...")
        s, o = utils_test.ping(ip, 100)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test")

        logging.info("Detaching the previously attached nic from vm")
        vm.hotunplug_nic(nic_name)

    finally:
        logging.info("Re-enabling the primary link(s)")
        for nic in vm.virtnet:
            if nic.nic_name == nic_name:
                continue
            else:
                vm.monitor.cmd("set_link %s on" % nic.device_id)

    # Attempt to put back udev network naming rules, even if the command to
    # disable the rules failed. We may be undoing what was done in a previous
    # (failed) test that never reached this point.
    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_bkp_path):
            session.cmd("mv -f %s %s" % (udev_rules_bkp_path, udev_rules_path))
Beispiel #7
0
def run_nic_hotplug(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one nic
    2) Add a host network device through monitor cmd and check if it's added
    3) Add nic device through monitor cmd and check if it's added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev
    8) Ping guest's new ip address after guest pause/resume
    9) Re-enable primary link of guest

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The KVM autotest default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params["main_vm"])
    login_timeout = int(params.get("login_timeout", 360))
    pci_model = params.get("pci_model", "rtl8139")
    run_dhclient = params.get("run_dhclient", "no")

    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    guest_is_not_windows = "Win" not in params.get("guest_name", "")

    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    if guest_is_not_windows:
        # Modprobe the module if specified in config file
        module = params.get("modprobe_module")
        if module:
            session.get_command_output("modprobe %s" % module)

    # hot-add the nic
    error.context("Add network devices through monitor cmd", logging.info)
    nic_name = 'hotadded'
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype,
                              queues=params.get('queues'),
                              vectors=params.get('vectors'))

    # Only run dhclient if explicitly set and guest is not running Windows.
    # Most modern Linux guests run NetworkManager, and thus do not need this.
    if run_dhclient == "yes" and guest_is_not_windows:
        session_serial = vm.wait_for_serial_login(timeout=login_timeout)
        ifname = utils_net.get_linux_ifname(session, nic_info['mac'])
        session_serial.cmd("dhclient %s &" % ifname)

    error.context("Disable the primary link(s) of guest", logging.info)
    for nic in vm.virtnet:
        if not (nic.nic_name == nic_name):
            vm.set_link(nic.device_id, up=False)

    try:
        error.context("Check if new interface gets ip address", logging.info)
        try:
            ip = vm.wait_for_get_address(nic_name)
        except virt_vm.VMIPAddressMissingError:
            raise error.TestFail("Could not get or verify ip address of nic")
        logging.info("Got the ip address of new nic: %s", ip)

        error.context("Ping guest's new ip from host", logging.info)
        s, o = utils_test.ping(ip, 10, timeout=15)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test")
        error.context("Ping guest's new ip after pasue/resume", logging.info)
        vm.monitor.cmd("stop")
        vm.monitor.cmd("cont")
        s, o = utils_test.ping(ip, 10, timeout=15)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test after stop/cont")

        logging.info("Detaching the previously attached nic from vm")
        error.context("Detaching the previously attached nic from vm",
                      logging.info)
        vm.hotunplug_nic(nic_name)

    finally:
        error.context("Re-enabling the primary link(s)", logging.info)
        for nic in vm.virtnet:
            if not (nic.nic_name == nic_name):
                vm.set_link(nic.device_id, up=True)
        finally:
            utils.run("umount %s" % mem_path)


    test_config = test_setup.TransparentHugePageConfig(test, params)
    logging.info("Defrag test start")
    login_timeout = float(params.get("login_timeout", 360))
    mem_path = os.path.join("/tmp", "thp_space")

    try:
        error.context("deactivating khugepaged defrag functionality")
        change_feature_status("off", "khugepaged/defrag", test_config)
        change_feature_status("off", "defrag", test_config)

        vm = utils_test.get_living_vm(env, params.get("main_vm"))
        session = utils_test.wait_for_login(vm, timeout=login_timeout)

        fragment_host_memory(mem_path)

        total = get_mem_stat('MemTotal')
        hugepagesize = get_mem_stat('Hugepagesize')
        nr_full = int(0.8 * (total / hugepagesize))

        nr_hp_before = set_libhugetlbfs(nr_full)

        error.context("activating khugepaged defrag functionality")
        change_feature_status("on", "khugepaged/defrag", test_config)
        change_feature_status("on", "defrag", test_config)

        sleep_time = 10
        logging.debug("Sleeping %s s to settle things out" % sleep_time)
            utils.run(cmd)
        finally:
            utils.run("umount %s" % mem_path)

    test_config = test_setup.TransparentHugePageConfig(test, params)
    logging.info("Defrag test start")
    login_timeout = float(params.get("login_timeout", 360))
    mem_path = os.path.join("/tmp", "thp_space")

    try:
        error.context("deactivating khugepaged defrag functionality")
        change_feature_status("off", "khugepaged/defrag", test_config)
        change_feature_status("off", "defrag", test_config)

        vm = utils_test.get_living_vm(env, params.get("main_vm"))
        session = utils_test.wait_for_login(vm, timeout=login_timeout)

        fragment_host_memory(mem_path)

        total = get_mem_stat('MemTotal')
        hugepagesize = get_mem_stat('Hugepagesize')
        nr_full = int(0.8 * (total / hugepagesize))

        nr_hp_before = set_libhugetlbfs(nr_full)

        error.context("activating khugepaged defrag functionality")
        change_feature_status("on", "khugepaged/defrag", test_config)
        change_feature_status("on", "defrag", test_config)

        sleep_time = 10
        logging.debug("Sleeping %s s to settle things out" % sleep_time)