On Tue, Sep 11, 2012 at 10:54:51AM +0800, Gao feng wrote: > with this patch,container's meminfo will be shown based on > containers' mem cgroup. > > Right now,it's impossible to virtualize all values in meminfo, > I collect some values such as MemTotal,MemFree,Cached,Active, > Inactive,Active(anon),Inactive(anon),Active(file),Inactive(anon), > Active(file),Inactive(file),Unevictable,SwapTotal,SwapFree. > > if I miss something, please let me know. > > Signed-off-by: Gao feng <gaofeng@xxxxxxxxxxxxxx> > +int virLXCCgroupGetMeminfo(unsigned long long *meminfo) > +{ > + int ret; > + virCgroupPtr cgroup; > + > + ret = virCgroupGetAppRoot(&cgroup); > + if (ret < 0) { > + virReportSystemError(-ret, "%s", > + _("Unable to get cgroup for container")); > + return ret; > + } > + > + ret = virLXCCgroupGetMemStat(cgroup, meminfo); > + if (ret < 0) { > + virReportSystemError(-ret, "%s", > + _("Unable to get memory cgroup stat info")); > + goto out; > + } > + > + ret = virLXCCgroupGetMemTotal(cgroup, &meminfo[MEMTOTAL]); > + if (ret < 0) { > + virReportSystemError(-ret, "%s", > + _("Unable to get memory cgroup total")); > + goto out; > + } > + > + ret = virLXCCgroupGetMemUsage(cgroup, &meminfo[MEMUSAGE]); > + if (ret < 0) { > + virReportSystemError(-ret, "%s", > + _("Unable to get memory cgroup stat usage")); > + goto out; > + } > + > + ret = virLXCCgroupGetMemSwapTotal(cgroup, &meminfo[SWAPTOTAL]); > + if (ret < 0) { > + virReportSystemError(-ret, "%s", > + _("Unable to get memory cgroup stat swaptotal")); > + goto out; > + } > + > + ret = virLXCCgroupGetMemSwapUsage(cgroup, &meminfo[SWAPUSAGE]); > + if (ret < 0) { > + virReportSystemError(-ret, "%s", > + _("Unable to get memory cgroup stat swapusage")); > + goto out; > + } When I tested these patches on a 3.4 kernel, these last two calls always fail because the corresponding cgroup file does not exist. I had to remove them to make this work at all. > + > + ret = 0; > +out: > + virCgroupFree(&cgroup); > + > + return ret; > +} Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list