Bug 1146539 - Setting value to 0 will not turn to be unlimited with virsh command memtune
Summary: Setting value to 0 will not turn to be unlimited with virsh command memtune
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.1
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Pavel Hrdina
QA Contact: Virtualization Bugs
URL:
Whiteboard:
: 1146540 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-09-25 12:57 UTC by Xuesong Zhang
Modified: 2015-11-19 05:53 UTC (History)
5 users (show)

Fixed In Version: libvirt-1.2.16-1.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-11-19 05:53:19 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:2202 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2015-11-19 08:17:58 UTC

Description Xuesong Zhang 2014-09-25 12:57:18 UTC
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:

Comment 1 Pavel Hrdina 2015-03-04 10:56:25 UTC
*** Bug 1146540 has been marked as a duplicate of this bug. ***

Comment 2 Pavel Hrdina 2015-03-04 16:17:48 UTC
Upstream patches proposed:

https://www.redhat.com/archives/libvir-list/2015-March/msg00139.html

Comment 4 Pavel Hrdina 2015-05-04 17:49:45 UTC
Upstream commit:

commit cf521fc8bae5aa8bfb28806ced8ac3a9f58b0627
Author: Pavel Hrdina <phrdina@redhat.com>
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@redhat.com>

v1.2.13-71-gcf521fc

Comment 6 Luyao Huang 2015-07-22 07:08:13 UTC
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

Comment 8 errata-xmlrpc 2015-11-19 05:53:19 UTC
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


Note You need to log in before you can comment on or make changes to this bug.