I’ve been playing around with LXC over the past few weeks and one of the things I tried out was limiting the memory that the container is allowed to use. I didn’t plan on explaining all the ins-and-outs of LXC here, but a short description is that LXC provides a virtualizedish environment that is more than a chroot gives you, but less than a full-blown virtual machine. If you want more details, please check out stgraber’s blog post about LXC in 12.04.
The first thing you need to do in order to limit memory usage for LXC is make sure your kernel is properly configured, you need the following flag enabled:CONFIG_CGROUP_MEM_RES_CTLR=y
If you plan on also limiting swap space usage, you’ll also need:CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
These flags are enabled for me in my 12.10 kernel (3.5.0-22) and so presumably you’ll have them in 12.04.
Setting the Cap
First, I’m going to create my container. Following the instructions from stgraber’s blog post, and calling the container “memlimit”:
Read the entire post on Matt Fischer’s blog.