LXC

Ubuntu LXC memory & swap limit

Ubuntu LXC memory & swap limit

Add to the LXC config

# Memory limits
lxc.cgroup.memory.limit_in_bytes = 2G
lxc.cgroup.memory.memsw.limit_in_bytes = 4G

If you get the following error, when you like to set swap memory limit:

lxc-start: cgmanager.c: cgm_setup_limits: 1238 call to cgmanager_set_value_sync failed: invalid request
lxc-start: cgmanager.c: cgm_setup_limits: 1241 Error setting cgroup memory:lxc/testlxc limit type memory.memsw.limit_in_bytes
lxc-start: start.c: lxc_spawn: 911 failed to setup the cgroup limits for 'testlxc'
lxc-start: start.c: __lxc_start: 1080 failed to spawn 'testlxc'
lxc-start: lxc_start.c: main: 342 The container failed to start.
lxc-start: lxc_start.c: main: 346 Additional information can be obtained by setting the --logfile and --logpriority options.

Add swapaccount=1 to linux boot parameter

sudo -e /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="swapaccount=1"

Now update grub

sudo update-grub

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.