[Lxc-users] total RAM limit

Gary Ballantyne gary.ballantyne at haulashore.com
Thu Jan 31 06:41:31 UTC 2013


On 12/01/13 08:49, Stéphane Graber wrote:
> On 01/11/2013 01:17 PM, Gary Ballantyne wrote:
>> Hello All
>>
>> I understand that I can limit the RAM of a single container via
>> lxc.cgroup.memory.limit_in_bytes. But, is there a way to limit the total
>> RAM available to all containers (without limiting each individually)?
>>
>> E.g., say we have 4G available. Rather than specifying a maximum number
>> of containers (16 with 250M say), I'd like to allocate 4G to all
>> containers, without a hard upper limit on the number of containers (16
>> in this case), and let the performance degrade gradually as more
>> containers are added. (I'm anticipating being able to use many more
>> containers this way, since our container's RAM usage is likely to be
>> bursty).
> You can, but not through lxc configuration.
>
> LXC uses the "lxc" directory in the cgroup hierarchy, so that your
> container is typically at:
> lxc/<container name>/
>
> Manually changing the keys in the lxc directory will set a shared quota
> for everything under it.
>
> As a concrete example, on my laptop, the memory cgroup is mounted at:
> /sys/fs/cgroup/memory/
>
> And individual container cgroups are at:
> /sys/fs/cgroup/memory/lxc/<container name>
>
> So setting /sys/fs/cgroup/memory/lxc/memory.limit_in_bytes would do what
> you want.
>
Thanks Stéphane

I tried to test this, but without any success. This is what I did:

On a new quantal EC2 instance I set the memory limit to 64M and created 
a container (vm0):

# apt-get update
# apt-get install lxc lvm2
# umount /mnt
# pvcreate /dev/xvdb
# vgcreate lxc /dev/xvdb
# echo "prepend domain-name-servers 10.0.3.1;" >> /etc/dhcp/dhclient.conf
*# echo '64M' > /sys/fs/cgroup/memory/lxc/memory.limit_in_bytes*
# cat /sys/fs/cgroup/memory/lxc/memory.limit_in_bytes (return 67108864)
# lxc-create -t ubuntu -n vm0 -B lvm
# lxc-start -d -n vm0
# ssh ubuntu at vm0

On vm0 I installed ipython and numpy

# apt-get update
# apt-get install ipython python-numpy

In Ipython (on vm0) I created a large random array:

: import numpy as np
: A=np.random.rand(10000,10000)

In 'top', on the host (or on the container), I was hoping to see the 
memory to be limited per the cgroup, and for the container to start 
using swap --- but ipython cheerfully used most/all of the host's RAM 
(depending on how large the numpy array was).

Perhaps I am missing a step?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20130131/a51b2158/attachment.html>


More information about the lxc-users mailing list