Skip to contentSkip to conversation

About cgroup memory limits

DISCUSSION Andre Nathan 3 participants 4 messages May 10, 2012 – May 23, 2012 1 message not in the archive cgroup

lore
Share & tools
lore
#0 lore raw

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?

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

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.

Thank you in advance,
Andre

[1] http://www.kernel.org/doc/Documentation/cgroups/memory.txt

#1 lore raw
Quoted 8 lines · Andre Nathan

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?

mapped_file is the subset of cache that is mapped into virtual memory.

cache (= inactive_file + active_file) + rss (= inactive_anon + active_anon) is what the limit applies to.

Quoted 8 lines

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

statms accounts based on virtual memory, not physical memory like memcg does. If you have the same page mapped into two tasks, both their "share" counters will show a page, while the memcg will only account the single physical page in mapped_file.

Quoted 13 lines

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
Quoted 4 lines

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.

Excluding the memory shared between tasks in the same group from the "shared" counter gets you to "mapped_file" etc.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Hi Johannes,

Thank you very much for your reply, it does help us to understand the
numbers we have at hand.

Could you clarify your following statement further:

Quoted 10 lines
Quoted 5 lines

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

statms accounts based on virtual memory, not physical memory like memcg does. If you have the same page mapped into two tasks, both their "share" counters will show a page, while the memcg will only account the single physical page in mapped_file.

You mean when those two tasks are in the same cgroup, don't you? Is
there a case in which a page is shared by two tasks that are in different cgroups but that page is accounted only for one of the two cgroups? If so, how's this case triggered?

Signature · 2 lines
[ ]'s
Michel Machado
#4 lore raw
Quoted 18 lines · Michel Machado

Hi Johannes,

Thank you very much for your reply, it does help us to understand the
numbers we have at hand.

Could you clarify your following statement further:

Quoted 10 lines
Quoted 5 lines

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

statms accounts based on virtual memory, not physical memory like memcg does. If you have the same page mapped into two tasks, both their "share" counters will show a page, while the memcg will only account the single physical page in mapped_file.

Quoted 4 lines

You mean when those two tasks are in the same cgroup, don't you? Is
there a case in which a page is shared by two tasks that are in different cgroups but that page is accounted only for one of the two cgroups? If so, how's this case triggered?

It doesn't matter whether it's the same cgroup or separate cgroups.

When two tasks are in separate memory cgroups, the shared page will be accounted to the group of the task that is responsible for bringing it into memory, the one touching it for the first time.