RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1070695 - dominfo get wrong info after set memory to an lxc guest
Summary: dominfo get wrong info after set memory to an lxc guest
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: John Ferlan
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-02-27 11:20 UTC by Shanzhi Yu
Modified: 2015-11-19 05:44 UTC (History)
7 users (show)

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


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 Shanzhi Yu 2014-02-27 11:20:45 UTC
Description of problem:

dominfo get wrong info after set memory to an lxc guest

Version-Release number of selected component (if applicable):
libvirt-1.1.1-25.el7.x86_64

How reproducible:
100%

Steps to Reproduce:

1.define an lxc guest

# virsh  -c lxc:/// list
 Id    Name                           State
----------------------------------------------------
 3134  vm1                            running

2.check memory info of the lxc guest

# virsh  -c lxc:/// dominfo vm1
Id:             3134
Name:           vm1
UUID:           386f5b25-43ee-9d62-4ce2-58c3809e47c1
OS Type:        exe
State:          running
CPU(s):         1
CPU time:       0.1s
Max memory:     500000 KiB
Used memory:    708 KiB
Persistent:     yes
Autostart:      disable
Managed save:   unknown
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 (enforcing)

3.set lxc guest memory
# virsh  -c lxc:/// setmem vm1 100000

4.login guest and check the memory by "cat /proc/memory"
the "MemTotal" change to 100000KB

5.re-check the lxc guest memory info by dominfo

# virsh  -c lxc:/// dominfo vm1
Id:             3134
Name:           vm1
UUID:           386f5b25-43ee-9d62-4ce2-58c3809e47c1
OS Type:        exe
State:          running
CPU(s):         1
CPU time:       0.1s
Max memory:     500000 KiB
Used memory:    708 KiB    ......here doesn't change
Persistent:     yes
Autostart:      disable
Managed save:   unknown
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 (enforcing)


Actual results:


Expected results:


Additional info:

Comment 2 Jiri Denemark 2014-02-27 11:31:34 UTC
It's "Max memory" that should have been changed, "Used memory" gives the amount or memory really consumed by the domain.

Comment 3 Shanzhi Yu 2014-02-27 12:09:18 UTC
(In reply to Jiri Denemark from comment #2)
> It's "Max memory" that should have been changed, "Used memory" gives the
> amount or memory really consumed by the domain.
Hi Jiri,
Thanks for your quick response.

setmaxmem will change the Max memory. And for qemu-kvm guest,the setmem works fine(it really changes Used memory)

Comment 4 Jiri Denemark 2014-02-27 12:14:25 UTC
Hmm, right, so it's likely not be a bug at all then. LXC is a bit different than KVM, there's no hypervisor process that would allocate the memory from the host and use it for guest processes. In LXC, guest processes allocate memory directly from the host via host kernel, they are just limited so that memory used by all guest processes does not exceed the limit.

Comment 5 John Ferlan 2014-08-06 18:30:51 UTC
The 'setmem' will set the 'memory.limit_in_bytes' or "the maximum amount of user memory (including file cache)".  

The 'dominfo' fetches the 'memory.usage_in_bytes' or "the total current memory usage by processes in the cgroup".

So they clearly are not the same thing. 

 Although I suppose if the query were


sh-4.2# cat  /proc/meminfo | grep -i mem
MemTotal:         500000 kB
MemFree:          498744 kB
MemAvailable:    4621284 kB
Shmem:            361028 kB

From the host do the setmem command

sh-4.2# cat  /proc/meminfo | grep -i mem
MemTotal:         100000 kB
MemFree:           98744 kB
MemAvailable:    4618716 kB
Shmem:            361012 kB

So when you 'setmem' on the container (or a vm in general) it balloons the guest memory (up or down)... This equates to the <currentMemory> XML value. It will not allow you to set beyond the "maximum memory" assigned to the VM (e.g., the <memory> value from the XML set while the VM is down). 

What it seems is desired perhaps is a way to see the "max max" (eg what setmaxmem would allow), the current max/limit/size one could get to (or currentMemory), and the currently used value, but I'm not sure/clear if that's the case.

Right now it's hypervisor dependent whether you see the maxmax or you see the currrent value in the "Max memory" output from 'dominfo'.  For qemu it's also dependent on whether the balloon is enabled or not. For lxc you see the maxmax, although I suppose it could show the current max instead.

So while it seems the belief was the "Used" field in dominfo was wrong, perhaps the "Max memory" field is wrong...

So is there a preference?  See all 3 values or change lxc to return current max from the setmem (or whatever the container was started with)?

Comment 6 John Ferlan 2014-08-06 19:57:39 UTC
FWIW: memtune will show the 100K value:

# virsh -c lxc:/// memtune vm1
hard_limit     : 100000
soft_limit     : unlimited
swap_hard_limit: unlimited

A bit more investigation has found that other hypervisors set/return maxmax for "Max memory" and it varies for "Used memory" between what's currently set/used for the guest, to the currentMemory value, to the maximum value.

Given Max memory is maxmax, I don't see changing that for lxc to be a good thing. And given Used memory is actually what is in use, so it shouldn't be changed either.  That leaves displaying current which can be seen with memtune, so is there a need to repeat it and/or would it create confusion?

The more I think about the solution to this issue is better documentation of 'setmem' and 'dominfo' to describe/set expectations on the result.  Whether that's in the 'virsh' docs or the driver specific docs is still to be decided.

Comment 7 Jiri Denemark 2014-08-07 11:45:47 UTC
Yeah, I agree that there's nothing to be really fixed for this bug other than improving the documentation.

Comment 9 John Ferlan 2015-02-26 23:40:31 UTC
Posted patch upstream:

http://www.redhat.com/archives/libvir-list/2015-February/msg01195.html

also removing the needsinfo

Comment 10 John Ferlan 2015-03-03 03:57:07 UTC
Fixes pushed upstream

Commit id:

69db32f93d7a22e7be04c2e9dc41a357f9811404

$ git describe 69db32f93d7a22e7be04c2e9dc41a357f9811404
v1.2.13-29-g69db32f
$

Comment 13 vivian zhang 2015-07-15 09:57:18 UTC
Verify this bug with build libvirt-1.2.17-2.el7.x86_64


check man virsh

  setmem domain size [[--config] [--live] | [--current]]
           .....

           For LXC, the value being set is the cgroups value for limit_in_bytes or the maximum amount of user memory
           (including file cache). When viewing memory inside the container, this is the /proc/meminfo "MemTotal" value.
           When viewing the value from the host, use the virsh memtune command. In order to view the current memory in
           use and the maximum value allowed to set memory, use the virsh dominfo command.


...

       memtune domain [--hard-limit size] [--soft-limit size] [--swap-hard-limit size] [--min-guarantee size] [[--config]
       [--live] | [--current]]
           ...

           For LXC, the displayed hard_limit value is the current memory setting from the XML or the results from a virsh
           setmem command.

           --hard-limit
               The maximum memory the guest can use.

           --soft-limit
               The memory limit to enforce during memory contention.

           --swap-hard-limit
               The maximum memory plus swap the guest can use.  This has to be more than hard-limit value provided.

           --min-guarantee
               The guaranteed minimum memory allocation for the guest.

           Specifying -1 as a value for these limits is interpreted as unlimited.


move to verified

Comment 15 errata-xmlrpc 2015-11-19 05:44:46 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.