Tuesday, July 22, 2014

Limit CPU, memory, other resources available to an LXC instance

I saw this article on controlling container resources. That's very helpful, I'll be using that where previously I'd used VirtualBox (much too fat) for fine control on RAM and CPU allocated to a VM.

Show CPUs currently available to an instance:
  lxc-cgroup -n ol6ctr1 cpuset.cpus 0-7

Limit CPU time and block I/O

lxc-cgroup -n ol6ctr2 cpu.shares 256
lxc-cgroup -n ol6ctr2 blkio.weight 500

Limit RAM

lxc-cgroup -n ol6ctr2 memory.soft_limit_in_bytes 268435456
lxc-cgroup -n ol6ctr2 memory.limit_in_bytes 536870912

The settings can be made permanent by setting them in the lxc instance's config file, e.g.,

lxc.cgroup.cpuset.cpus=0,1
lxc.cgroup.memory.soft_limit_in_bytes=268435456
lxc.cgroup.memory.limit_in_bytes=536870912

The oracle article has a typo for the memory.limit_in_bytes example, it was missing the last digit (2). Fixed here.



No comments: