setup

Add to /etc/fstab.

cgroup                  /sys/fs/cgroup  cgroup  defaults        0       2

Then sudo mount -a.

Change directory to /sys/fs/cgroup/. Use mkdir to create a new group, and initalize it like those.

echo 0-3 >> cpuset.cpus
echo 0 > cpuset.mems

Without those two step, next operator will failure.

echo 0 > memory.swappiness
echo 52428800 > memory.limit_in_bytes

Set memory limit 50M, and forbidden swap.

python test code

import os, sys, time, random, string
def main():
    l = []
    random.seed()
    raw_input()
    for i in xrange(1000000):
        for j in xrange(1000):
            t = list(string.letters)
            random.shuffle(t)
            s = ''.join(t)
            l.append(s)
        time.sleep(0.01)

if __name__ == '__main__': main()

Finally, it triggered OOM.