Score:0

Cgroups Memory Limits - Script gets killed well before limit is reached

cn flag

I am trying out a simple example to understand how to limit the memory consumption of processes.

I have created a test memory group, set the limits for both memory.limit_in_bytes and memory.memsw.limit_in_bytes to 5 MB.

I have a really simple program that allocates memory in increments of 1 MB (by reading from a random device).

I would have expected my script to reach somewhere close to 5 MB before it gets killed, but it gets killed right after it reads 1 MB.

When I raise the cgroup limits to 8 MB, it gets killed after consuming 3 MB.

I have tried with different limits, and have noticed it consistently gets killed before reaching half of the allocated limit.

Can someone please let me know if I am missing anything else?

Would greatly appreciate some guidance.

user10489 avatar
in flag
Note that you don't have to read from a device to allocate memory. It is sufficient to use malloc and touch a byte in each page.
Score:0
in flag

cgroups memory limits also cover executable code for the program, including the executable itself and any shared libraries it needs. You can use tools like ps and top (or one of the top variants) to watch actual memory use before you set limits with cgroups, and possibly before you allow your test program to start allocating memory.

cn flag
Thank you. I suspected the libraries the program uses, and as you suggested, that seems to be the case. I also used pmap to verify the actual memory consumed, and that validates your answer here.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.