Commit 104f39284e830f425085886ef72c49aee6631575
Committed by
Linus Torvalds
1 parent
0dea116876
Exists in
master
and in
7 other branches
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>
Showing 1 changed file with 32 additions and 22 deletions Side-by-side Diff
mm/memcontrol.c
... | ... | @@ -2857,40 +2857,50 @@ |
2857 | 2857 | *val = d.val; |
2858 | 2858 | } |
2859 | 2859 | |
2860 | +static 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 | + | |
2860 | 2885 | static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft) |
2861 | 2886 | { |
2862 | 2887 | struct mem_cgroup *mem = mem_cgroup_from_cont(cont); |
2863 | - u64 idx_val, val; | |
2888 | + u64 val; | |
2864 | 2889 | int type, name; |
2865 | 2890 | |
2866 | 2891 | type = MEMFILE_TYPE(cft->private); |
2867 | 2892 | name = MEMFILE_ATTR(cft->private); |
2868 | 2893 | switch (type) { |
2869 | 2894 | case _MEM: |
2870 | - if (name == RES_USAGE && mem_cgroup_is_root(mem)) { | |
2871 | - mem_cgroup_get_recursive_idx_stat(mem, | |
2872 | - MEM_CGROUP_STAT_CACHE, &idx_val); | |
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 | |
2895 | + if (name == RES_USAGE) | |
2896 | + val = mem_cgroup_usage(mem, false); | |
2897 | + else | |
2879 | 2898 | val = res_counter_read_u64(&mem->res, name); |
2880 | 2899 | break; |
2881 | 2900 | case _MEMSWAP: |
2882 | - if (name == RES_USAGE && mem_cgroup_is_root(mem)) { | |
2883 | - mem_cgroup_get_recursive_idx_stat(mem, | |
2884 | - MEM_CGROUP_STAT_CACHE, &idx_val); | |
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 | |
2901 | + if (name == RES_USAGE) | |
2902 | + val = mem_cgroup_usage(mem, true); | |
2903 | + else | |
2894 | 2904 | val = res_counter_read_u64(&mem->memsw, name); |
2895 | 2905 | break; |
2896 | 2906 | default: |