[lxc-users] How properly to find what consumes memory inside the container.

Ivan Kurnosov zerkms at zerkms.ru
Wed Oct 11 21:51:19 UTC 2017


Fajar,

yep, that is helpful. Thanks.

On 12 October 2017 at 10:42, Fajar A. Nugraha <list at fajar.net> wrote:

> On Tue, Sep 19, 2017 at 11:20 AM, Ivan Kurnosov <zerkms at zerkms.ru> wrote:
>
>>
>> But if I clear the system caches on the host
>>
>> echo 3 > /proc/sys/vm/drop_caches
>>
>>
>> the container memory consumption drops to the expected <100mb.
>>
>> So the question, how to monitor the memory consumption from the container
>> reliably?
>>
>
> As in 'know what the kernel thinks the container is using? You're doing it
> already.
>
> If you use lxcfs (which should be the case on ubuntu), /proc entries
> inside containers are fake, created using data from the relevant cgroups.
>
>
>
>> And why does `free` count caches as used memory inside container?
>>
>>
>>
>
> From https://www.kernel.org/doc/Documentation/cgroup-v2.txt:
> "
> Memory
> ------
>
> The "memory" controller regulates distribution of memory.  Memory is
> stateful and implements both limit and protection models.  Due to the
> intertwining between memory usage and reclaim pressure and the
> stateful nature of memory, the distribution model is relatively
> complex.
>
> While not completely water-tight, all major memory usages by a given
> cgroup are tracked so that the total memory consumption can be
> accounted and controlled to a reasonable extent.  Currently, the
> following types of memory usages are tracked.
>
> - Userland memory - page cache and anonymous memory.
>
> - Kernel data structures such as dentries and inodes.
>
> - TCP socket buffers.
>
> The above list may expand in the future for better coverage.
>
> ...
> Memory Ownership
> ~~~~~~~~~~~~~~~~
>
> A memory area is charged to the cgroup which instantiated it and stays
> charged to the cgroup until the area is released.  Migrating a process
> to a different cgroup doesn't move the memory usages that it
> instantiated while in the previous cgroup to the new cgroup.
>
> A memory area may be used by processes belonging to different cgroups.
> To which cgroup the area will be charged is in-deterministic; however,
> over time, the memory area is likely to end up in a cgroup which has
> enough memory allowance to avoid high reclaim pressure.
>
> If a cgroup sweeps a considerable amount of memory which is expected
> to be accessed repeatedly by other cgroups, it may make sense to use
> POSIX_FADV_DONTNEED to relinquish the ownership of memory areas
> belonging to the affected files to ensure correct memory ownership.
> "
>
>
>
> An interesting question would be "can you exclude page cache from cgroup
> memory accounting". I don't think that's possible though.
>
> --
> Fajar
>
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users
>



-- 
With best regards, Ivan Kurnosov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20171012/b7e3e668/attachment.html>


More information about the lxc-users mailing list