[PATCH 2/2 v4] memcg: support hierarchical memory.numa_stats

2013-09-16 Thread Greg Thelen
From: Ying Han 

From: Ying Han 

The memory.numa_stat file was not hierarchical.  Memory charged to the
children was not shown in parent's numa_stat.

This change adds the "hierarchical_" stats to the existing stats.  The
new hierarchical stats include the sum of all children's values in
addition to the value of the memcg.

Tested: Create cgroup a, a/b and run workload under b.  The values of
b are included in the "hierarchical_*" under a.

$ cd /sys/fs/cgroup
$ echo 1 > memory.use_hierarchy
$ mkdir a a/b

Run workload in a/b:
$ (echo $BASHPID >> a/b/cgroup.procs && cat /some/file && bash) &

The hierarchical_ fields in parent (a) show use of workload in a/b:
$ cat a/memory.numa_stat
total=0 N0=0 N1=0 N2=0 N3=0
file=0 N0=0 N1=0 N2=0 N3=0
anon=0 N0=0 N1=0 N2=0 N3=0
unevictable=0 N0=0 N1=0 N2=0 N3=0
hierarchical_total=908 N0=552 N1=317 N2=39 N3=0
hierarchical_file=850 N0=549 N1=301 N2=0 N3=0
hierarchical_anon=58 N0=3 N1=16 N2=39 N3=0
hierarchical_unevictable=0 N0=0 N1=0 N2=0 N3=0

$ cat a/b/memory.numa_stat
total=908 N0=552 N1=317 N2=39 N3=0
file=850 N0=549 N1=301 N2=0 N3=0
anon=58 N0=3 N1=16 N2=39 N3=0
unevictable=0 N0=0 N1=0 N2=0 N3=0
hierarchical_total=908 N0=552 N1=317 N2=39 N3=0
hierarchical_file=850 N0=549 N1=301 N2=0 N3=0
hierarchical_anon=58 N0=3 N1=16 N2=39 N3=0
hierarchical_unevictable=0 N0=0 N1=0 N2=0 N3=0

Signed-off-by: Ying Han 
Signed-off-by: Greg Thelen 
---
Changelog since v3:
- push 'iter' local variable usage closer to its usage
- documentation fixup

 Documentation/cgroups/memory.txt | 10 +++---
 mm/memcontrol.c  | 17 +
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt
index 8af4ad1..e2bc132 100644
--- a/Documentation/cgroups/memory.txt
+++ b/Documentation/cgroups/memory.txt
@@ -573,15 +573,19 @@ an memcg since the pages are allowed to be allocated from 
any physical
 node.  One of the use cases is evaluating application performance by
 combining this information with the application's CPU allocation.
 
-We export "total", "file", "anon" and "unevictable" pages per-node for
-each memcg.  The ouput format of memory.numa_stat is:
+Each memcg's numa_stat file includes "total", "file", "anon" and "unevictable"
+per-node page counts including "hierarchical_" which sums up all
+hierarchical children's values in addition to the memcg's own value.
+
+The ouput format of memory.numa_stat is:
 
 total= N0= N1= ...
 file= N0= N1= ...
 anon= N0= N1= ...
 unevictable= N0= N1= ...
+hierarchical_= N0= N1= ...
 
-And we have total = file + anon + unevictable.
+The "total" count is sum of file + anon + unevictable.
 
 6. Hierarchy support
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5806eea..d02176d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5206,6 +5206,23 @@ static int memcg_numa_stat_show(struct 
cgroup_subsys_state *css,
seq_putc(m, '\n');
}
 
+   for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) {
+   struct mem_cgroup *iter;
+
+   nr = 0;
+   for_each_mem_cgroup_tree(iter, memcg)
+   nr += mem_cgroup_nr_lru_pages(iter, stat->lru_mask);
+   seq_printf(m, "hierarchical_%s=%lu", stat->name, nr);
+   for_each_node_state(nid, N_MEMORY) {
+   nr = 0;
+   for_each_mem_cgroup_tree(iter, memcg)
+   nr += mem_cgroup_node_nr_lru_pages(
+   iter, nid, stat->lru_mask);
+   seq_printf(m, " N%d=%lu", nid, nr);
+   }
+   seq_putc(m, '\n');
+   }
+
return 0;
 }
 #endif /* CONFIG_NUMA */
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2 v4] memcg: support hierarchical memory.numa_stats

2013-09-16 Thread Greg Thelen
From: Ying Han ying...@google.com

From: Ying Han ying...@google.com

The memory.numa_stat file was not hierarchical.  Memory charged to the
children was not shown in parent's numa_stat.

This change adds the hierarchical_ stats to the existing stats.  The
new hierarchical stats include the sum of all children's values in
addition to the value of the memcg.

Tested: Create cgroup a, a/b and run workload under b.  The values of
b are included in the hierarchical_* under a.

$ cd /sys/fs/cgroup
$ echo 1  memory.use_hierarchy
$ mkdir a a/b

Run workload in a/b:
$ (echo $BASHPID  a/b/cgroup.procs  cat /some/file  bash) 

The hierarchical_ fields in parent (a) show use of workload in a/b:
$ cat a/memory.numa_stat
total=0 N0=0 N1=0 N2=0 N3=0
file=0 N0=0 N1=0 N2=0 N3=0
anon=0 N0=0 N1=0 N2=0 N3=0
unevictable=0 N0=0 N1=0 N2=0 N3=0
hierarchical_total=908 N0=552 N1=317 N2=39 N3=0
hierarchical_file=850 N0=549 N1=301 N2=0 N3=0
hierarchical_anon=58 N0=3 N1=16 N2=39 N3=0
hierarchical_unevictable=0 N0=0 N1=0 N2=0 N3=0

$ cat a/b/memory.numa_stat
total=908 N0=552 N1=317 N2=39 N3=0
file=850 N0=549 N1=301 N2=0 N3=0
anon=58 N0=3 N1=16 N2=39 N3=0
unevictable=0 N0=0 N1=0 N2=0 N3=0
hierarchical_total=908 N0=552 N1=317 N2=39 N3=0
hierarchical_file=850 N0=549 N1=301 N2=0 N3=0
hierarchical_anon=58 N0=3 N1=16 N2=39 N3=0
hierarchical_unevictable=0 N0=0 N1=0 N2=0 N3=0

Signed-off-by: Ying Han ying...@google.com
Signed-off-by: Greg Thelen gthe...@google.com
---
Changelog since v3:
- push 'iter' local variable usage closer to its usage
- documentation fixup

 Documentation/cgroups/memory.txt | 10 +++---
 mm/memcontrol.c  | 17 +
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt
index 8af4ad1..e2bc132 100644
--- a/Documentation/cgroups/memory.txt
+++ b/Documentation/cgroups/memory.txt
@@ -573,15 +573,19 @@ an memcg since the pages are allowed to be allocated from 
any physical
 node.  One of the use cases is evaluating application performance by
 combining this information with the application's CPU allocation.
 
-We export total, file, anon and unevictable pages per-node for
-each memcg.  The ouput format of memory.numa_stat is:
+Each memcg's numa_stat file includes total, file, anon and unevictable
+per-node page counts including hierarchical_counter which sums up all
+hierarchical children's values in addition to the memcg's own value.
+
+The ouput format of memory.numa_stat is:
 
 total=total pages N0=node 0 pages N1=node 1 pages ...
 file=total file pages N0=node 0 pages N1=node 1 pages ...
 anon=total anon pages N0=node 0 pages N1=node 1 pages ...
 unevictable=total anon pages N0=node 0 pages N1=node 1 pages ...
+hierarchical_counter=counter pages N0=node 0 pages N1=node 1 pages ...
 
-And we have total = file + anon + unevictable.
+The total count is sum of file + anon + unevictable.
 
 6. Hierarchy support
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5806eea..d02176d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5206,6 +5206,23 @@ static int memcg_numa_stat_show(struct 
cgroup_subsys_state *css,
seq_putc(m, '\n');
}
 
+   for (stat = stats; stat  stats + ARRAY_SIZE(stats); stat++) {
+   struct mem_cgroup *iter;
+
+   nr = 0;
+   for_each_mem_cgroup_tree(iter, memcg)
+   nr += mem_cgroup_nr_lru_pages(iter, stat-lru_mask);
+   seq_printf(m, hierarchical_%s=%lu, stat-name, nr);
+   for_each_node_state(nid, N_MEMORY) {
+   nr = 0;
+   for_each_mem_cgroup_tree(iter, memcg)
+   nr += mem_cgroup_node_nr_lru_pages(
+   iter, nid, stat-lru_mask);
+   seq_printf(m,  N%d=%lu, nid, nr);
+   }
+   seq_putc(m, '\n');
+   }
+
return 0;
 }
 #endif /* CONFIG_NUMA */
-- 
1.8.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/