Hide Forgot
Description Setting value to 0 will not turn to be unlimited with virsh command memtune. Version: libvirt-1.2.8-3.el7.x86_64 qemu-kvm-rhev-2.1.0-4.el7.x86_64 kernel-3.10.0-168.el7.x86_64 How reproducible: 100% Steps to Reproduce: 1. prepare one guest like following: # virsh memtune rhel7 hard_limit : 456 soft_limit : 123 swap_hard_limit: 789 2. set all the 3 parameter value to "0", all the 3 value are not changed, they are kept as before. # virsh memtune rhel7 --hard-limit 0 --swap-hard-limit 0 --soft-limit 0 hard_limit : 456 soft_limit : 123 swap_hard_limit: 789 3. set all the 3 parameter value to "-1", all the 3 value should be changed to unlimited. # virsh memtune rhel7 --hard-limit -1 --swap-hard-limit -1 --soft-limit -1 # virsh memtune rhel7 hard_limit : unlimited soft_limit : unlimited swap_hard_limit: unlimited 4. test this scenario with api, the value will be changed to unlimited with "0". # python Python 2.7.5 (default, Feb 11 2014, 07:46:25) [GCC 4.8.2 20140120 (Red Hat 4.8.2-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import libvirt >>> con = libvirt.open('') >>> dom = con.lookupByName('rhel7') >>> dom.memoryParameters(libvirt.VIR_DOMAIN_AFFECT_CONFIG) {'swap_hard_limit': 456L, 'hard_limit': 123L, 'soft_limit': 789L} >>> dom.setMemoryParameters({'swap_hard_limit': 0, 'hard_limit': 0, 'soft_limit': 0}, libvirt.VIR_DOMAIN_AFFECT_CONFIG) 0 >>> dom.memoryParameters(libvirt.VIR_DOMAIN_AFFECT_CONFIG) {'swap_hard_limit': 9007199254740991L, 'hard_limit': 9007199254740991L, 'soft_limit': 9007199254740991L} 5. checking in the code, "0" denotes unlimited also. VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_limit) VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) <jmiao> #undef VIR_GET_LIMIT_PARAMETER /* Swap hard limit must be greater than hard limit. * Note that limit of 0 denotes unlimited */ if (set_swap_hard_limit || set_hard_limit) { unsigned long long mem_limit = vm->def->mem.hard_limit; unsigned long long swap_limit = vm->def->mem.swap_hard_limit; Actual results: As step2 Expected results: In step2, the value should be changed to unlimited if setting them to "0" by virsh command. Additional info:
*** Bug 1146540 has been marked as a duplicate of this bug. ***
Upstream patches proposed: https://www.redhat.com/archives/libvir-list/2015-March/msg00139.html
Upstream commit: commit cf521fc8bae5aa8bfb28806ced8ac3a9f58b0627 Author: Pavel Hrdina <phrdina> Date: Mon Mar 2 20:04:12 2015 +0100 memtune: change the way how we store unlimited value There was a mess in the way how we store unlimited value for memory limits and how we handled values provided by user. Internally there were two possible ways how to store unlimited value: as 0 value or as VIR_DOMAIN_MEMORY_PARAM_UNLIMITED. Because we chose to store memory limits as unsigned long long, we cannot use -1 to represent unlimited. It's much easier for us to say that everything greater than VIR_DOMAIN_MEMORY_PARAM_UNLIMITED means unlimited and leave 0 as valid value despite that it makes no sense to set limit to 0. Remove unnecessary function virCompareLimitUlong. The update of test is to prevent the 0 to be miss-used as unlimited in future. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1146539 Signed-off-by: Pavel Hrdina <phrdina> v1.2.13-71-gcf521fc
Verify this bug in libvirt-1.2.17-2.el7.x86_64: 1. test with running guest: # uname -r 3.10.0-295.el7.x86_64 # virsh memtune test4 hard_limit : unlimited soft_limit : unlimited swap_hard_limit: unlimited 2. set a valid value: # virsh memtune test4 --hard-limit 10000 # cgget -g memory /machine.slice/machine-qemu\\x2dtest4.scope |grep limit_in_bytes memory.kmem.tcp.limit_in_bytes: 9223372036854775807 memory.memsw.limit_in_bytes: 9223372036854775807 memory.kmem.limit_in_bytes: 9223372036854775807 memory.soft_limit_in_bytes: 9223372036854775807 memory.limit_in_bytes: 10240000 3. set to -1 : # cgget -g memory /machine.slice/machine-qemu\\x2dtest4.scope |grep limit_in_bytes memory.kmem.tcp.limit_in_bytes: 9223372036854775807 memory.memsw.limit_in_bytes: 9223372036854775807 memory.kmem.limit_in_bytes: 9223372036854775807 memory.soft_limit_in_bytes: 9223372036854775807 memory.limit_in_bytes: 9223372036854775807 4. there are some kernel issue when set hard limit to 0: # virsh memtune test4 --hard-limit 0 error: Unable to change memory parameters error: unable to set memory hard_limit tunable: Operation not permitted # virsh memtune test4 --hard-limit 0 error: Unable to change memory parameters error: unable to set memory hard_limit tunable: Operation not permitted # virsh memtune test4 --hard-limit 0 error: Unable to change memory parameters error: unable to set memory hard_limit tunable: Operation not permitted # virsh memtune test4 --hard-limit 0 # virsh domstate test4 --reason shut off (crashed) 5. test with inactive guest: # virsh memtune test4 0 0 0 # virsh memtune test4 hard_limit : 0 soft_limit : 0 swap_hard_limit: 0 # virsh dumpxml test4 <memtune> <hard_limit unit='KiB'>0</hard_limit> <soft_limit unit='KiB'>0</soft_limit> <swap_hard_limit unit='KiB'>0</swap_hard_limit> </memtune> # virsh memtune test4 -1 -1 -1 # virsh memtune test4 hard_limit : unlimited soft_limit : unlimited swap_hard_limit: unlimited # virsh memtune test4 9007199254740991 9007199254740991 9007199254740991 # virsh memtune test4 hard_limit : unlimited soft_limit : unlimited swap_hard_limit: unlimited
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://rhn.redhat.com/errata/RHBA-2015-2202.html