Bug 767921

Summary: Results are different when testing memtune for twice with the same parameters
Product: Red Hat Enterprise Linux 6 Reporter: Min Zhan <mzhan>
Component: libvirtAssignee: Martin Kletzander <mkletzan>
Status: CLOSED DUPLICATE QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.3CC: acathrow, bili, dallan, dyuan, mzhan, rwu, yupzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 826880 (view as bug list) Environment:
Last Closed: 2012-07-23 13:42:56 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 826880    

Description Min Zhan 2011-12-15 09:08:37 UTC
Description of problem:
For the first time, memtune command fails; try with the second time, memtune succeed with the same parameters. I think maybe it is needed to check the user layer's parameters first.

Version-Release number of selected component (if applicable):
kernel-2.6.32-220.el6.x86_64
qemu-kvm-0.12.1.2-2.209.el6.x86_64
libvirt-0.9.8-1.el6.x86_64

How reproducible:
Always

Steps to Reproduce:
1. # virsh list --all
 Id Name                 State
----------------------------------
  8 vm1                  running

# virsh memtune vm1
hard_limit     : 103000000004 kB
soft_limit     : 103000000004 kB
swap_hard_limit: 103000000004 kB

2. Increase hard-limit value (only need pay attention on the first 4 numbers)

# virsh memtune vm1 --hard-limit 103100000001 --soft-limit 103000000001 --swap-hard-limit 103000000001 
error: Unable to change memory parameters
error: unable to set memory hard_limit tunable: Invalid argument

# virsh memtune vm1
hard_limit     : 103000000004 kB
soft_limit     : 103000000004 kB
swap_hard_limit: 103000000004 kB


3. Increase other 2 parameters to keep the same as hard-limit, and do twice

# virsh memtune vm1 --hard-limit 103100000001 --soft-limit 103100000001 --swap-hard-limit 103100000001
error: Unable to change memory parameters
error: unable to set memory hard_limit tunable: Invalid argument

# echo $?
1

# virsh memtune vm1
hard_limit     : 103000000004 kB
soft_limit     : 103100000004 kB
swap_hard_limit: 103100000004 kB

-> here soft-limit and swap-hard-limit change, but hard-limit not changes, and throw an error

# virsh memtune vm1 --hard-limit 103100000001 --soft-limit 103100000001 --swap-hard-limit 103100000001

# echo $?
0
# virsh memtune vm1
hard_limit     : 103100000004 kB
soft_limit     : 103100000004 kB
swap_hard_limit: 103100000004 kB
-> here all 3 values are changed, return correct
  
Actual results:
See step 3.

Expected results:
The results should be the same in step 3.

Additional info:

Comment 3 EricLee 2012-03-26 09:47:18 UTC
Has same result as the description in the versions:
qemu-kvm-0.12.1.2-2.248.el6.x86_64
libvirt-0.9.10-6.el6.x86_64
kernel-2.6.32-251.el6.x86_64

Comment 4 Martin Kletzander 2012-05-31 07:46:16 UTC
I was able to reproduce the bug on latest libvirt and qemu with 3.4.0 kernel. According to the logs, however, libvirt is doing everything correctly. Researching a little bit more, I came to a point where I am able to reproduce this bug *without* libvirt, causing the same error messages to appear from kernel. There is a workaround for this problem, but it doesn't seem right, because I've found out no information about it.

Let me explain. This is how to reproduce the bug without libvirt (numbers are taken from libvirt log after reproducing this according to the comment #1, so multiplied by 1024):

1) Start by creating a group for the actual process:
# mkdir /sys/fs/cgroup/memory/test
# echo $$ >/sys/fs/cgroup/memory/test/tasks 

2) Set the first round of parameters:
# echo 105472000001024 > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
# echo 105472000001024 > /sys/fs/cgroup/memory/test/memory.soft_limit_in_bytes 
# echo 105472000001024 > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes 

3) Set the second round of parameters:
# echo 105574400001024 > /sys/fs/cgroup/memory/test/memory.soft_limit_in_bytes 
# echo 105574400001024 > /sys/fs/cgroup/memory/test/memory.limit_in_bytes 
-su: echo: write error: Invalid argument
# echo 105574400001024 > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes 

4) Try the second round again:
# echo 105574400001024 > /sys/fs/cgroup/memory/test/memory.soft_limit_in_bytes 
# echo 105574400001024 > /sys/fs/cgroup/memory/test/memory.limit_in_bytes 
# echo 105574400001024 > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes 

Note that the second command from point 3) will fail until the memsw limit is greater or equal to the number we want to set. The workaround would then be, to set the memsw first and continue with the others. The problem is that this is  mentioned nowhere in the documentation and thus it looks like a bug.

Having memsw lower than the hard limit on memory is, of course, nonsense. But if this is a valid restriction, it should be mentioned in the documentation. If this is a bug, then it should be fixed (not having these restrictions would ease the setting from scripts and programs, because now there needs to be bunch of checks before the setting).

I'll clone this bug for kernel, to make this resolved asap.

Comment 6 Martin Kletzander 2012-07-02 10:16:23 UTC
*** Bug 829241 has been marked as a duplicate of this bug. ***

Comment 7 Dave Allan 2012-07-23 13:42:56 UTC

*** This bug has been marked as a duplicate of bug 839537 ***