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.