[Lxc-users] lxc.cgroup.memory.limit_in_bytes has no effect
Daniel Lezcano
daniel.lezcano at free.fr
Tue May 17 07:10:03 UTC 2011
On 05/17/2011 08:34 AM, Ulli Horlacher wrote:
> Memory limitation does not work for me:
>
> root at vms2:/lxc# uname -a
> Linux vms2 2.6.32-31-server #61-Ubuntu SMP Fri Apr 8 19:44:42 UTC 2011 x86_64 GNU/Linux
>
> root at vms2:/lxc# grep CONFIG_CGROUP_MEM_RES_CTLR
> /boot/config-2.6.32-31-server
> CONFIG_CGROUP_MEM_RES_CTLR=y
> CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
>
> root at vms2:/lxc# grep limit_in_bytes /lxc/flupp.cfg
> lxc.cgroup.memory.limit_in_bytes = 536870912
>
> root at vms2:/lxc# lxc-version
> lxc version: 0.7.4.1
>
> root at vms2:/lxc# lxc-start -d -n flupp -f /lxc/flupp.cfg
> root at vms2:/lxc# lxc-console -n flupp
>
> Type<Ctrl+a q> to exit the console
>
> root at flupp:~# ls -l /tmp/1GB.tmp
> -rw-r--r-- 1 root root 1073741824 2011-05-17 06:06 /tmp/1GB.tmp
>
> root at flupp:~# clp
> Command Line Perl with readline support, @ARGV and Specials. Type "?" for help.
> (perl):: undef $/; open F,'/tmp/1GB.tmp' or die; $_=<F>; print length
>
> 1073741824
>
>
> Why can a container process allocate more than 1 GB of memory if there is
> 512 MB limit?
I don't know exactly what does your perl program but I suggest you try
with a simple C program:
#include <stdio.h>
#include <sys/mman.h>
#include <sys/poll.h>
int main(int argc, char *argv[])
{
char *addr;
addr = mmap(NULL, 512 * 1024 * 1024, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_POPULATE | MAP_ANONYMOUS, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
return -1;
}
poll(0, 0, -1);
return 0;
}
When a process reaches the memory limit size then the container will
begin to swap. This is not really what we want as it can impact the
performances of the other container with continuous disk io. So the
solution would be to set prevent the container to swap or play with the
swapiness (not tried myself).
In order to disable the swap, you have to set the
memory.memsw.limit_in_bytes = memory.limit_in_bytes.
More information about the lxc-users
mailing list