<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 12/01/13 08:49, Stéphane Graber
      wrote:<br>
    </div>
    <blockquote cite="mid:50F06CDF.2030001@ubuntu.com" type="cite">
      <pre wrap="">On 01/11/2013 01:17 PM, Gary Ballantyne wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">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).
</pre>
      </blockquote>
      <pre wrap="">
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.

</pre>
    </blockquote>
    Thanks Stéphane<br>
    <br>
    I tried to test this, but without any success. This is what I did:<br>
    <br>
    On a new quantal EC2 instance I set the memory limit to 64M and
    created a container (vm0):<br>
    <br>
    # apt-get update<br>
    # apt-get install lxc lvm2<br>
    # umount /mnt<br>
    # pvcreate /dev/xvdb<br>
    # vgcreate lxc /dev/xvdb<br>
    # echo "prepend domain-name-servers 10.0.3.1;" >>
    /etc/dhcp/dhclient.conf<br>
    <b># echo '64M' > /sys/fs/cgroup/memory/lxc/memory.limit_in_bytes</b><br>
    # cat /sys/fs/cgroup/memory/lxc/memory.limit_in_bytes (return
    67108864)<br>
    # lxc-create -t ubuntu -n vm0 -B lvm<br>
    # lxc-start -d -n vm0<br>
    # ssh ubuntu@vm0<br>
    <br>
    On vm0 I installed ipython and numpy<br>
    <br>
    # apt-get update<br>
    # apt-get install ipython python-numpy<br>
    <br>
    In Ipython (on vm0) I created a large random array:<br>
    <br>
    : import numpy as np<br>
    : A=np.random.rand(10000,10000)<br>
    <br>
    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).<br>
    <br>
    Perhaps I am missing a step?<br>
    <br>
  </body>
</html>