1. Prepare the cgroups # mount -t tmpfs none /sys/fs/cgroup # mkdir /sys/fs/cgroup/memory # mount -t cgroup none /sys/fs/cgroup/memory -o memory 2. Make the new group and move pid(s) into it # mkdir /sys/fs/cgroup/memory/0 # echo $$ > /sys/fs/cgroup/memory/0/tasks NOTE: in this example, only pid of current bash shell Since now we're in the 0 cgroup, we can alter the memory limit: # echo 4M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes NOTE: We can use an optional suffix (k, K, m, M, g or G) We can check the limit: # cat /sys/fs/cgroup/memory/0/memory.limit_in_bytes 4194304 We can check the usage: # cat /sys/fs/cgroup/memory/0/memory.usage_in_bytes 1216512 3. Swap Extension - memory.memsw.usage_in_bytes. - memory.memsw.limit_in_bytes. memsw means memory+swap. Example: Assume a system with 4G of swap. A task which allocates 6G of memory (by mistake) under 2G memory limitation will use all swap. In this case, setting memsw.limit_in_bytes=3G will prevent bad use of swap. By using the memsw limit, you can avoid system OOM which can be caused by swap shortage. #EOF ha ha :)