Bug 950478

Summary: if the value of 'swap-hard-limit' smaller than the existing vaule of 'hard-limit', memtune can not set them together
Product: Red Hat Enterprise Linux 7 Reporter: EricLee <bili>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: acathrow, cwei, dallan, dyuan, gsun, lcui, mzhan
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.0.5-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-13 09:44:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description EricLee 2013-04-10 09:57:48 UTC
Description of problem:
if the value of 'swap-hard-limit' smaller than the existing vaule of 'hard-limit', memtune can not set them together

Version-Release number of selected component (if applicable):
kernel-3.9.0-0.rc6.50.el7.x86_64
libvirt-1.0.4-1.el7.x86_64
qemu-kvm-1.4.0-2.el7.x86_64

Reproduce steps:
1. prepare a healthy guest with os and start guest;

2. # virsh memtune --domain r7 
hard_limit     : 1824256
soft_limit     : unlimited
swap_hard_limit: unlimited

3. # virsh memtune r7 --hard-limit 1024000 --soft-limit 1024000 --swap-hard-limit 1024000
error: Unable to change memory parameters
error: unable to set memory swap_hard_limit tunable: Invalid argument

4. # virsh memtune r7 --hard-limit 1024000 --soft-limit 1024000

set successfully.

5. # virsh memtune --domain r7
hard_limit     : 1024000
soft_limit     : 1024000
swap_hard_limit: unlimited

6. # virsh memtune r7 --hard-limit 1024000 --soft-limit 1024000 --swap-hard-limit 1024000

this time will work.

7. # virsh memtune --domain r7
hard_limit     : 1024000
soft_limit     : 1024000
swap_hard_limit: 1024000

8. # virsh memtune r7 --hard-limit 1024008 --soft-limit 102400 --swap-hard-limit 1024008

works well.

9. # virsh memtune --domain r7
hard_limit     : 1024008
soft_limit     : 102400
swap_hard_limit: 1024008

But
10. # virsh memtune r7 --hard-limit 1024000 --swap-hard-limit 1024004
error: Unable to change memory parameters
error: unable to set memory swap_hard_limit tunable: Invalid argument

will not work.

Actual results:
As steps.

Expected results:
should firstly compare the value of 'swap-hard-limit' with the setting value of 'hard-limit', if the former is not bigger, then compare with the existing value of 'hard-limit'.

Additional info:
There is a cgroup problem and have mentioned in:
https://bugzilla.redhat.com/show_bug.cgi?id=839537#c16

We can try:

# virsh list
 Id    Name                           State
----------------------------------------------------
 2     libvirt_test_api               running

write a big limit value in cgroup:
# echo 1073741824000 >/sys/fs/cgroup/memory/libvirt/qemu/libvirt_test_api/memory.limit_in_bytes;echo 1073741824000 >/sys/fs/cgroup/memory/libvirt/qemu/libvirt_test_api/memory.soft_limit_in_bytes;echo 1073741824000 >/sys/fs/cgroup/memory/libvirt/qemu/libvirt_test_api/memory.memsw.limit_in_bytes

# virsh memtune libvirt_test_api
hard_limit     : 1048576000
soft_limit     : 1048576000
swap_hard_limit: 1048576000

then write a smaller value in:
# echo 6542848 >/sys/fs/cgroup/memory/libvirt/qemu/libvirt_test_api/memory.limit_in_bytes;echo 6542848 >/sys/fs/cgroup/memory/libvirt/qemu/libvirt_test_api/memory.soft_limit_in_bytes;echo 6542848 >/sys/fs/cgroup/memory/libvirt/qemu/libvirt_test_api/memory.memsw.limit_in_bytes
-bash: echo: write error: Device or resource busy

# virsh memtune libvirt_test_api
hard_limit     : 6392
soft_limit     : 6392
swap_hard_limit: 1048576000

But the bug has been closed.

Comment 2 Peter Krempa 2013-04-23 05:18:19 UTC
Fixed upstream in v1.0.4-235-gfa006c4 by:

commit fa006c4fdd8c8580bca3db1436e3201350e973f4
Author: Peter Krempa <pkrempa>
Date:   Wed Apr 17 17:50:56 2013 +0200

    qemu: Fix setting of memory tunables
    
    Refactoring done in 19c6ad9ac7e7eb2fd3c8262bff5f087b508ad07f didn't
    correctly take into account the order cgroup limit modification needs to
    be done in. This resulted into errors when decreasing the limits.
    
    The operations need to take place in this order:
    
    decrease hard limit
    change swap hard limit
    
    or
    
    change swap hard limit
    increase hard limit
    
    This patch also fixes the check if the hard_limit is less than
    swap_hard_limit to print better error messages. For this purpose I
    introduced a helper function virCompareLimitUlong to compare limit
    values where value of 0 is equal to unlimited. Additionally the check is
    now applied also when the user does not provide all of the tunables
    through the API and in that case the currently set values are used.
    
    This patch resolves:
    https://bugzilla.redhat.com/show_bug.cgi?id=950478

Comment 3 EricLee 2013-05-06 09:38:58 UTC
Verifying this bug:

Can reproduce this bug on libvirt-1.0.4-1.1.el7.x86_64; And can not reproduce it on libvirt-1.0.5-1.el7:
# virsh start r63
Domain r63 started

# virsh memtune --domain r63
hard_limit     : 1824256
soft_limit     : unlimited
swap_hard_limit: unlimited

1. decrease hard limit and change swap hard limit:
# virsh memtune r63 --hard-limit 1024000 --soft-limit 1024000 --swap-hard-limit 1024000

# virsh memtune --domain r63
hard_limit     : 1024000
soft_limit     : 1024000
swap_hard_limit: 1024000

working well.

2.change swap hard limit and increase hard limit:
# virsh memtune r63 --hard-limit 1024004 --soft-limit 1024000 --swap-hard-limit 1024008

# virsh memtune --domain r63
hard_limit     : 1024004
soft_limit     : 1024000
swap_hard_limit: 1024008

# virsh memtune r63 --hard-limit 1024000 --swap-hard-limit 1024004

# virsh memtune --domain r63
hard_limit     : 1024000
soft_limit     : 1024000
swap_hard_limit: 1024004

also working fine.

3.when hard_limit is less than swap_hard_limit:
# virsh memtune r63 --hard-limit 1024008 --swap-hard-limit 1024004
error: Unable to change memory parameters
error: invalid argument: memory hard_limit tunable value must be lower than swap_hard_limit

So setting VERIFIED.

Comment 4 Ludek Smid 2014-06-13 09:44:31 UTC
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.