[lxc-devel] Kernel Samepage Merging

Rob Landley rlandley at parallels.com
Sat Feb 12 03:45:40 UTC 2011


On 02/07/2011 01:19 PM, richard -rw- weinberger wrote:
> Hi,
> 
> Can KSM (http://lwn.net/Articles/306704/) help LXC?
> I guess there are a lot of identical pages when logs of containers are running.
> 

Some of it we get for free by building on top of chroot instead of kvm.

If your binaries live on the same mount point, then they should share
executable pages just like normal binaries, despite being in different
containers.  (Multiple namespaces aside, if you mmap() the same inode
out of the same superblock, you should get the same page cache.  You may
have a read only or copy on write mapping to it, but that's nothing new.
 That's why shared libraries are -fPIC in the first place.)

And similarly, disk cache is also just page cache, based on the
underlying files sharing an inode, so exposing the same mount points
(either read only or with union mounts on top) in different containers
gives you automatic memory sharing the same way it does for the rest of
the kernel.

But if you copy your root filesystem a lot without hard linking together
the underlying inodes, then the underlying disk storage is redundant and
thus mmap() of that storage will also be redundant.  So doing that not
only wastes disk space, but physical memory as well.

Rob




More information about the lxc-devel mailing list