Commit d2ceb9b7ddedbb2e8e590bc6ce33c854043016f9

Authored by KAMEZAWA Hiroyuki
Committed by Linus Torvalds
1 parent d52aa412d4

memory cgroup enhancements: add memory.stat file

Show accounted information of memory cgroup by memory.stat file

[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: fix printk warning]
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Pavel Emelianov <xemul@openvz.org>
Cc: Paul Menage <menage@google.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Kirill Korotaev <dev@sw.ru>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: David Rientjes <rientjes@google.com>
Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 48 additions and 0 deletions Side-by-side Diff

... ... @@ -29,6 +29,7 @@
29 29 #include <linux/swap.h>
30 30 #include <linux/spinlock.h>
31 31 #include <linux/fs.h>
  32 +#include <linux/seq_file.h>
32 33  
33 34 #include <asm/uaccess.h>
34 35  
... ... @@ -794,6 +795,49 @@
794 795 }
795 796  
796 797  
  798 +static const struct mem_cgroup_stat_desc {
  799 + const char *msg;
  800 + u64 unit;
  801 +} mem_cgroup_stat_desc[] = {
  802 + [MEM_CGROUP_STAT_CACHE] = { "cache", PAGE_SIZE, },
  803 + [MEM_CGROUP_STAT_RSS] = { "rss", PAGE_SIZE, },
  804 +};
  805 +
  806 +static int mem_control_stat_show(struct seq_file *m, void *arg)
  807 +{
  808 + struct cgroup *cont = m->private;
  809 + struct mem_cgroup *mem_cont = mem_cgroup_from_cont(cont);
  810 + struct mem_cgroup_stat *stat = &mem_cont->stat;
  811 + int i;
  812 +
  813 + for (i = 0; i < ARRAY_SIZE(stat->cpustat[0].count); i++) {
  814 + s64 val;
  815 +
  816 + val = mem_cgroup_read_stat(stat, i);
  817 + val *= mem_cgroup_stat_desc[i].unit;
  818 + seq_printf(m, "%s %lld\n", mem_cgroup_stat_desc[i].msg,
  819 + (long long)val);
  820 + }
  821 + return 0;
  822 +}
  823 +
  824 +static const struct file_operations mem_control_stat_file_operations = {
  825 + .read = seq_read,
  826 + .llseek = seq_lseek,
  827 + .release = single_release,
  828 +};
  829 +
  830 +static int mem_control_stat_open(struct inode *unused, struct file *file)
  831 +{
  832 + /* XXX __d_cont */
  833 + struct cgroup *cont = file->f_dentry->d_parent->d_fsdata;
  834 +
  835 + file->f_op = &mem_control_stat_file_operations;
  836 + return single_open(file, mem_control_stat_show, cont);
  837 +}
  838 +
  839 +
  840 +
797 841 static struct cftype mem_cgroup_files[] = {
798 842 {
799 843 .name = "usage_in_bytes",
... ... @@ -820,6 +864,10 @@
820 864 .name = "force_empty",
821 865 .write = mem_force_empty_write,
822 866 .read = mem_force_empty_read,
  867 + },
  868 + {
  869 + .name = "stat",
  870 + .open = mem_control_stat_open,
823 871 },
824 872 };
825 873