Bug 1024272 - Changing --hard-limit with memtune report invalid error when --swap-hard-limit is unlimited.
Changing --hard-limit with memtune report invalid error when --swap-hard-limi...
Status: CLOSED CURRENTRELEASE
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.0
x86_64 Linux
medium Severity medium
: rc
: 7.0
Assigned To: Martin Kletzander
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-29 05:45 EDT by Hao Liu
Modified: 2014-06-17 20:58 EDT (History)
7 users (show)

See Also:
Fixed In Version: libvirt-1.1.1-15.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-06-13 08:05:29 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Hao Liu 2013-10-29 05:45:24 EDT
Description of problem:
Changing --hard-limit with memtune report invalid error when --swap-hard-limit is unlimited.

Version-Release number of selected component (if applicable):
Red Hat Enterprise Linux Server release 7.0 Beta
libvirt-1.1.1-10.el7.x86_64

How reproducible:
always

Command:
1. Prepare a running vm with unlimited memory.
# virsh start <vm-name>

2. Check memtune status.
# virsh memtune <vm-name> --live
hard_limit     : unlimited
soft_limit     : unlimited
swap_hard_limit: unlimited

3. Try to change --hard-limit with memtune.
# virsh memtune <vm-name> --hard-limit 100000000 --live

Result:
error: Unable to change memory parameters
error: invalid argument: memory hard_limit tunable value must be lower than swap_hard_limit

Expected result:
Change hard limit successfully.

Additional info:
This only happens for new started VM. 
After change limits manually to 'unlimited' with:

# virsh memtune <vm-name> --hard-limit -1 --swap-hard-limit -1 --live

, memtune works fine with step 3.
Comment 1 Hao Liu 2013-10-29 06:01:59 EDT
In the following part of qemuDomainSetMemoryParameters() in src/qemu/qemu_driver.c ,
when the VM is fresh started, vm->def->mem.swap_hard_limit is 0, then the
comparison is true.
when --swap-hard-limit is manually set to -1, then vm->def->mem.swap_hard_limit
is the maximum ulong, then this comparison is false.

    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;

        if (set_swap_hard_limit)
            swap_limit = swap_hard_limit;

        if (set_hard_limit)
            mem_limit = hard_limit;

        if (virCompareLimitUlong(mem_limit, swap_limit) > 0) {
            virReportError(VIR_ERR_INVALID_ARG, "%s",
                           _("memory hard_limit tunable value must be lower "
                             "than swap_hard_limit"));
            goto cleanup;
        }
    }

So this might be caused by ambiguous representation of unlimited memory.
Comment 3 Jincheng Miao 2013-11-18 21:28:37 EST
Need to adopt this patch from upstream:

commit 19e7c04dce34afeb9a762471e09777de7d219db8
Author: Bing Bu Cao <mars@linux.vnet.ibm.com>
Date:   Fri Oct 11 14:50:33 2013 +0800

    util: fix two virCompareLimitUlong bugs
    
    The helper function virCompareLimitUlong compares limit values,
    where value of 0 is equal to unlimited. If the latter parameter is 0,
    it should return -1 instead of 1, hence the user can only set hard_limit whe
    swap_hard_limit currently is unlimited.
    
    Worse, all callers pass 2 64-bit values, but on 32-bit platforms,
    the second argument was silently truncated to 32 bits, which
    could lead to incorrect computations.
Comment 4 Martin Kletzander 2013-11-19 04:05:07 EST
Thanks for the info, but unfortunately that's not enough since upstream is currently a bit broken as well.
Comment 5 Martin Kletzander 2013-12-10 03:02:57 EST
Rest of the upstream code is waiting for review (don't mind the misleading subject):

https://www.redhat.com/archives/libvir-list/2013-December/msg00434.html
and
https://www.redhat.com/archives/libvir-list/2013-December/msg00501.html
Comment 8 Hao Liu 2013-12-16 00:21:37 EST
This fix is VERIFIED.

Verification Steps:
Same as https://bugzilla.redhat.com/show_bug.cgi?id=1024272#c0
In step 3:
for libvirt-1.1.1-14.el7:
# virsh memtune <vm-name> --live --hard-limit 100000000
error: Unable to change memory parameters
error: invalid argument: memory hard_limit tunable value must be lower than swap_hard_limit

for libvirt-1.1.1-15.el7:
# virsh memtune <vm-name> --live --hard-limit 100000000

# virsh memtune <vm-name> --live 
hard_limit     : 100000000
soft_limit     : unlimited
swap_hard_limit: unlimited

So this bug is fixed and VERIFIED.
Comment 9 Ludek Smid 2014-06-13 08:05:29 EDT
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.

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