Commit 1dd3a27326d307952f8ad2499478c84dc7311517

Authored by Daisuke Nishimura
Committed by Linus Torvalds
1 parent 0c3e73e84f

memcg: show swap usage in stat file

We now count MEM_CGROUP_STAT_SWAPOUT, so we can show swap usage.  It would
be useful for users to show swap usage in memory.stat file, because they
don't need calculate memsw.usage - res.usage to know swap usage.

Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: Balbir Singh <balbir@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 14 additions and 3 deletions Side-by-side Diff

... ... @@ -2676,6 +2676,7 @@
2676 2676 MCS_MAPPED_FILE,
2677 2677 MCS_PGPGIN,
2678 2678 MCS_PGPGOUT,
  2679 + MCS_SWAP,
2679 2680 MCS_INACTIVE_ANON,
2680 2681 MCS_ACTIVE_ANON,
2681 2682 MCS_INACTIVE_FILE,
... ... @@ -2697,6 +2698,7 @@
2697 2698 {"mapped_file", "total_mapped_file"},
2698 2699 {"pgpgin", "total_pgpgin"},
2699 2700 {"pgpgout", "total_pgpgout"},
  2701 + {"swap", "total_swap"},
2700 2702 {"inactive_anon", "total_inactive_anon"},
2701 2703 {"active_anon", "total_active_anon"},
2702 2704 {"inactive_file", "total_inactive_file"},
... ... @@ -2721,6 +2723,10 @@
2721 2723 s->stat[MCS_PGPGIN] += val;
2722 2724 val = mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_PGPGOUT_COUNT);
2723 2725 s->stat[MCS_PGPGOUT] += val;
  2726 + if (do_swap_account) {
  2727 + val = mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_SWAPOUT);
  2728 + s->stat[MCS_SWAP] += val * PAGE_SIZE;
  2729 + }
2724 2730  
2725 2731 /* per zone stat */
2726 2732 val = mem_cgroup_get_local_zonestat(mem, LRU_INACTIVE_ANON);
2727 2733  
... ... @@ -2752,8 +2758,11 @@
2752 2758 memset(&mystat, 0, sizeof(mystat));
2753 2759 mem_cgroup_get_local_stat(mem_cont, &mystat);
2754 2760  
2755   - for (i = 0; i < NR_MCS_STAT; i++)
  2761 + for (i = 0; i < NR_MCS_STAT; i++) {
  2762 + if (i == MCS_SWAP && !do_swap_account)
  2763 + continue;
2756 2764 cb->fill(cb, memcg_stat_strings[i].local_name, mystat.stat[i]);
  2765 + }
2757 2766  
2758 2767 /* Hierarchical information */
2759 2768 {
2760 2769  
... ... @@ -2766,9 +2775,11 @@
2766 2775  
2767 2776 memset(&mystat, 0, sizeof(mystat));
2768 2777 mem_cgroup_get_total_stat(mem_cont, &mystat);
2769   - for (i = 0; i < NR_MCS_STAT; i++)
  2778 + for (i = 0; i < NR_MCS_STAT; i++) {
  2779 + if (i == MCS_SWAP && !do_swap_account)
  2780 + continue;
2770 2781 cb->fill(cb, memcg_stat_strings[i].total_name, mystat.stat[i]);
2771   -
  2782 + }
2772 2783  
2773 2784 #ifdef CONFIG_DEBUG_VM
2774 2785 cb->fill(cb, "inactive_ratio", calc_inactive_ratio(mem_cont, NULL));