aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2010-03-10 18:22:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-12 18:52:37 -0500
commit104f39284e830f425085886ef72c49aee6631575 (patch)
tree6b5fff422dea5c5513a3af45f055fd939b32b316 /mm/memcontrol.c
parent0dea116876eefc9c7ca9c5d74fe665481e499fa3 (diff)
memcg: extract mem_group_usage() from mem_cgroup_read()
Helper to get memory or mem+swap usage of the cgroup. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Dan Malek <dan@embeddedalley.com> Cc: Vladislav Buzov <vbuzov@embeddedalley.com> Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Alexander Shishkin <virtuoso@slind.org> Cc: Davide Libenzi <davidel@xmailserver.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r--mm/memcontrol.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b00ec74a4c18..5f8f93d83edf 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2857,40 +2857,50 @@ mem_cgroup_get_recursive_idx_stat(struct mem_cgroup *mem,
2857 *val = d.val; 2857 *val = d.val;
2858} 2858}
2859 2859
2860static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap)
2861{
2862 u64 idx_val, val;
2863
2864 if (!mem_cgroup_is_root(mem)) {
2865 if (!swap)
2866 return res_counter_read_u64(&mem->res, RES_USAGE);
2867 else
2868 return res_counter_read_u64(&mem->memsw, RES_USAGE);
2869 }
2870
2871 mem_cgroup_get_recursive_idx_stat(mem, MEM_CGROUP_STAT_CACHE, &idx_val);
2872 val = idx_val;
2873 mem_cgroup_get_recursive_idx_stat(mem, MEM_CGROUP_STAT_RSS, &idx_val);
2874 val += idx_val;
2875
2876 if (swap) {
2877 mem_cgroup_get_recursive_idx_stat(mem,
2878 MEM_CGROUP_STAT_SWAPOUT, &idx_val);
2879 val += idx_val;
2880 }
2881
2882 return val << PAGE_SHIFT;
2883}
2884
2860static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft) 2885static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)
2861{ 2886{
2862 struct mem_cgroup *mem = mem_cgroup_from_cont(cont); 2887 struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
2863 u64 idx_val, val; 2888 u64 val;
2864 int type, name; 2889 int type, name;
2865 2890
2866 type = MEMFILE_TYPE(cft->private); 2891 type = MEMFILE_TYPE(cft->private);
2867 name = MEMFILE_ATTR(cft->private); 2892 name = MEMFILE_ATTR(cft->private);
2868 switch (type) { 2893 switch (type) {
2869 case _MEM: 2894 case _MEM:
2870 if (name == RES_USAGE && mem_cgroup_is_root(mem)) { 2895 if (name == RES_USAGE)
2871 mem_cgroup_get_recursive_idx_stat(mem, 2896 val = mem_cgroup_usage(mem, false);
2872 MEM_CGROUP_STAT_CACHE, &idx_val); 2897 else
2873 val = idx_val;
2874 mem_cgroup_get_recursive_idx_stat(mem,
2875 MEM_CGROUP_STAT_RSS, &idx_val);
2876 val += idx_val;
2877 val <<= PAGE_SHIFT;
2878 } else
2879 val = res_counter_read_u64(&mem->res, name); 2898 val = res_counter_read_u64(&mem->res, name);
2880 break; 2899 break;
2881 case _MEMSWAP: 2900 case _MEMSWAP:
2882 if (name == RES_USAGE && mem_cgroup_is_root(mem)) { 2901 if (name == RES_USAGE)
2883 mem_cgroup_get_recursive_idx_stat(mem, 2902 val = mem_cgroup_usage(mem, true);
2884 MEM_CGROUP_STAT_CACHE, &idx_val); 2903 else
2885 val = idx_val;
2886 mem_cgroup_get_recursive_idx_stat(mem,
2887 MEM_CGROUP_STAT_RSS, &idx_val);
2888 val += idx_val;
2889 mem_cgroup_get_recursive_idx_stat(mem,
2890 MEM_CGROUP_STAT_SWAPOUT, &idx_val);
2891 val += idx_val;
2892 val <<= PAGE_SHIFT;
2893 } else
2894 val = res_counter_read_u64(&mem->memsw, name); 2904 val = res_counter_read_u64(&mem->memsw, name);
2895 break; 2905 break;
2896 default: 2906 default: