Exemple #1
0
def config_feature_memory_backing(test, vmxml, **kwargs):
    """
    Config libvirt VM XML to influence how virtual memory pages are backed
    by host pages.

    :param vmxml: VMXML instance
    :param kwargs: Function keywords
    :return: Corresponding feature flag in qem cmdline
    """
    # Both 'nosharepages' and 'locked' are supported since 1.0.6
    if not libvirt_version.version_compare(1, 0, 6):
        test.cancel("Element is not supported in current" " libvirt version")
    qemu_flags = []
    no_sharepages = "yes" == kwargs.get("nosharepages", "no")
    locked = "yes" == kwargs.get("locked", "no")
    if no_sharepages:
        # On RHEL6, the flag is 'redhat-disable-KSM'
        # On RHEL7 & Fedora, the flag is 'mem-merge=off'
        qemu_flags.append(['mem-merge=off', 'redhat-disable-KSM'])
    if locked:
        qemu_flags.append("mlock=on")
        memtune_xml = vm_xml.VMMemTuneXML()
        memtune_xml.hard_limit = vmxml.max_mem * 4
        vmxml.memtune = memtune_xml
        vmxml.sync()
    try:
        vm_xml.VMXML.set_memoryBacking_tag(vmxml.vm_name,
                                           hpgs=False,
                                           nosp=no_sharepages,
                                           locked=locked)
        logging.debug("xml updated to %s", vmxml.xmltreefile)
    except Exception as detail:
        logging.error("Update VM XML fail: %s", detail)
    return qemu_flags
Exemple #2
0
    def run_test_memorybacking(case):
        """
        Test memory backing cases

        :param case: test case
        """
        if case == 'no_numa':
            # Verify <access mode='shared'/> is ignored
            # if no NUMA nodes are configured
            if libvirt_version.version_compare(7, 0, 0) or\
                    not libvirt_version.version_compare(5, 0, 0):
                test.cancel('This case is not supported by current libvirt.')
            access_mode = params.get('access_mode')

            # Setup memoryBacking
            mem_backing = vm_xml.VMMemBackingXML()
            mem_backing.access_mode = access_mode
            hugepages = vm_xml.VMHugepagesXML()
            mem_backing.hugepages = hugepages
            vmxml.mb = mem_backing
            logging.debug('membacking xml is: %s', mem_backing)

            vmxml.xmltreefile.write()

            # Define xml
            cmd_result = virsh.define(vmxml.xml, debug=True)
            check_result(cmd_result, status_error, error_msg)

        if case == 'mem_lock':
            # Allow use mlock without hard limit
            hard_limit = params.get('hard_limit')
            hard_limit_unit = params.get('hard_limit_unit', 'KiB')

            mem_backing = vm_xml.VMMemBackingXML()
            mem_backing.locked = True
            vmxml.mb = mem_backing

            if hard_limit:
                mem_tune = vm_xml.VMMemTuneXML()
                mem_tune.hard_limit = int(hard_limit)
                mem_tune.hard_limit_unit = hard_limit_unit
                vmxml.memtune = mem_tune

            vmxml.sync()
            vm.start()

            output = process.run('prlimit -p `pidof qemu-kvm`',
                                 shell=True,
                                 verbose=True).stdout_text
            if not re.search(expect_msg, output):
                test.fail('Not found expected content "%s" in output.' %
                          expect_msg)