[lxc-users] Is it possible to change memory limits without restarting container?

Fajar A. Nugraha list at fajar.net
Fri May 9 11:42:03 UTC 2014


On Fri, May 9, 2014 at 6:11 PM, CDR <venefax at gmail.com> wrote:
> I just tested and in fact, the memory restriction does not work.
> a) set a 5G limit for the container
> b) started the container
> c) gave 16 G memory to mysql
> D) restarted mysql
> it works fine and it also shows the memory on "show variable like '%buffer%'

Did you know that mysql doesn't actually use ALL of the allocated
memory on startup?

A simple test:
- start a container (in my case, precise)
- (from the host): check it's current memory usage, then set memory
limit to something a little higher

# lxc-cgroup -n precise memory.usage_in_bytes
92422144

# lxc-cgroup -n precise memory.limit_in_bytes 100000000
# lxc-cgroup -n precise memory.limit_in_bytes
100003840

some rounding take place. 100003840 bytes = 97660 kB

- start a memory-hog program in the container. In my case I use php to
read a big file to memory

# truncate -s 1G /tmp/1G
# php -r 'file("/tmp/1G");'
Killed

- examine what happened from the hosts's syslog

May  9 18:35:26 trusty kernel: [37187.222425] php invoked oom-killer:
gfp_mask=0xd0, order=0, oom_score_adj=0
...
May  9 18:35:26 trusty kernel: [37187.222483] Task in /lxc/precise
killed as a result of limit of /lxc/precise
May  9 18:35:26 trusty kernel: [37187.222484] memory: usage 97660kB,
limit 97660kB, failcnt 15540
May  9 18:35:26 trusty kernel: [37187.222485] memory+swap: usage 0kB,
limit 18014398509481983kB, failcnt 0
May  9 18:35:26 trusty kernel: [37187.222486] kmem: usage 0kB, limit
18014398509481983kB, failcnt 0
May  9 18:35:26 trusty kernel: [37187.222487] Memory cgroup stats for
/lxc/precise: cache:116KB rss:97544KB rss_huge:0KB mapped_file:52KB
writeback:0KB inactive_anon:24KB active_anon:97544KB inactive_file:0KB
active_file:0KB unevictable:0KB
...
May  9 18:35:26 trusty kernel: [37187.222569] Memory cgroup out of
memory: Kill process 15446 (php) score 937 or sacrifice child
May  9 18:35:26 trusty kernel: [37187.222571] Killed process 15446
(php) total-vm:1108108kB, anon-rss:94008kB, file-rss:16kB

You get the idea.

-- 

Fajar


More information about the lxc-users mailing list