Similar with root memcg's CACHE/RSS, we don't account its swap stats to improve performance. And for root memcg memcg_stat_show(): nr(MEM_CGROUP_STAT_SWAP) = total_swap_pages - nr_swap_pages - sum_of_all_memcg(MEM_CGROUP_STAT_SWAP); Signed-off-by: Sha Zhengju <handai.szj@xxxxxxxxxx> --- mm/memcontrol.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 24ce5e6d..b73758e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -934,7 +934,9 @@ static void mem_cgroup_swap_statistics(struct mem_cgroup *memcg, bool charge) { int val = (charge) ? 1 : -1; - this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_SWAP], val); + + if (!mem_cgroup_is_root(memcg)) + this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_SWAP], val); } static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg, @@ -5460,10 +5462,13 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft, if (i == MEM_CGROUP_STAT_SWAP && !do_swap_account) continue; - if (mem_cgroup_is_root(memcg) && (i != MEM_CGROUP_STAT_SWAP)) { - val = global_page_state(global_stat[i]) - - mem_cgroup_recursive_stat(memcg, i); - root_stat[i] = val = val < 0 ? 0 : val; + if (mem_cgroup_is_root(memcg)) { + if (i == MEM_CGROUP_STAT_SWAP) + val = total_swap_pages - + atomic_long_read(&nr_swap_pages); + else + val = global_page_state(global_stat[i]); + val = val - mem_cgroup_recursive_stat(memcg, i); } else val = mem_cgroup_read_stat(memcg, i); seq_printf(m, "%s %ld\n", mem_cgroup_stat_names[i], -- 1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>