Re: About cgroup memory limits

From: Zhu Yanhai
Date: Fri May 25 2012 - 00:16:49 EST


2012/5/10 KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>:
> (2012/05/10 3:37), Andre Nathan wrote:
>
>> Hello
>>
>> I'm doing some tests with LXC and how it interacts with the memory
>> cgroup limits, more specifically the memory.limit_in_bytes control file.
>>
>> Am I correct in my understanding of the memory cgroup documentation[1]
>> that the limit set in memory.limit_in_bytes is applied to the sum of the
>> fields 'cache', 'rss' and 'mapped_file' in the memory.stat file?
>>
>
> cache includes mapped_file. Then,

Excuse me, but it does read:

switch (ctype) {
case MEM_CGROUP_CHARGE_TYPE_CACHE:
case MEM_CGROUP_CHARGE_TYPE_SHMEM:
SetPageCgroupCache(pc);
SetPageCgroupUsed(pc);
break;
case MEM_CGROUP_CHARGE_TYPE_MAPPED:
ClearPageCgroupCache(pc);
SetPageCgroupUsed(pc);
break;
default:
break;
}
mem_cgroup_charge_statistics(mem, pc, page_size);

And then, in mem_cgroup_charge_statistics() we have :

if (PageCgroupCache(pc))
__mem_cgroup_stat_add_safe(cpustat,
MEM_CGROUP_STAT_CACHE, numpages);
else
__mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_RSS,
numpages);

So it seems that rss includes mapped_file, not cache?

>
> rss + cache < limit.
>
> cache - mapped_file == unmapped file caches.
>
>
>> I am also trying to understand the values reported in memory.stat when
>> compared to the statistics in /proc/$PID/statm.
>>
>> Below is the sum of each field in /proc/$PID/statm for every process
>> running inside a test container, converted to bytes:
>>
>>    Âsize Âresident   share   text Âlib    data Âdt
>> Â 897208320 Â28741632 Â20500480 Â1171456 Â Â0 Â170676224 Â 0
>>
>
> from statm source code.
>
> size   Â= total virtual memory size
> Â Â Â Â Â Â# total amount of mmaps().
>
> shared  Â= mapped_file
> Â Â Â Â Â Â# resident mapped file caches
>
> text   Â= end_code - start_code
> Â Â Â Â Â Â# end_code and start_code is determined when the program is loaded.
> Â Â Â Â Â Â# this is virtual memory size.
>
> data   Â= total virtual memory size Â- MAP_SHARED virtual memory size.
>
> regisdent = anonymous pages + mapped_file.
>
>
>> Compare this with the usage reports from memory.stat (fields total_*,
>> hierarchical_* and pg* omitted):
>>
>> cache           16834560
>> rss            8192000
>> mapped_file        3743744
>> swap           Â0
>> inactive_anon       0
>> active_anon        8192000
>> inactive_file       13996032
>> active_file        2838528
>> unevictable        0
>>
>> Is there a way to reconcile these numbers somehow? I understand that the
>> fields from the two files represent different things. What I'm trying to
>> do is to combine, for example, the fields from memory.stat to
>> approximately reach what is displayed by statm.
>>
>
>
> From above, rss + mapped_file == resident.
>
> Thanks,
> -Kame
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/