[lxc-devel] the solution of top and free in the lxc

魏子然 duck_uuu at 163.com
Mon May 27 04:13:09 UTC 2013


Hello, we encounter a problem in the use of lxc, that the command of  free and top does 
not show container\'s cpu and memory but the host server\'s;we know that it is a problem 
of proc directory which is mounted outside the container with remount option.we also 
know that we can solve this problem with fuse.

now we put forward another solution which is also based on fuse,but with more 
difference,our solution is modify lxc-start.c:
before do_clone() we use fuse to generate a userspaces proc filesystem,call mount() to 
mount /lxc/as6.3/proc directory;
after perform mount_rootfs_dir ($rootfs, $target) ,then call mount() to mount 
/lxc/as6.3/proc/{stat, meminfo, sysrq-trigger} to target/{stat, meminfo, sysrq-trigger} with --
bind option.

When a virtual machine to read /proc/meminfo, it will read the meminfo of from 
userspaces filesystem, we can  get the correct value is returned to the virtual machine 
from /cgroup/memory.if read /proc/stat, we can get value form /cgroup/cpuacct.

All mount implemented in lxc_start.c using c language, userspace files can be 
configured in the configuration file and dynamic loading.

The function of open and read and write of meminfo,stat,sysrq-trigger must be 
implemented by us.


this is a example,in configuration file:
lxc.cgroup.memory.limit_in_bytes = 268435456
lxc.cgroup.memory.memsw.limit_in_bytes = 536870912

[shell]#free -m 
             total       used       free     shared    buffers     cached
Mem:           256         13        242          0          0          0
-/+ buffers/cache:         13        242
Swap:          512         13        498
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130527/117b1a38/attachment.html>


More information about the lxc-devel mailing list