Skip to contentSkip to conversation

mm: memcontrol: Add the missing numa stat of anon and file for cgroup v2

PATCH In review Muchun Song 3 participants 7 messages Sep 10, 2020 – Sep 11, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: memcontrol: Add the missing numa stat of anon and file for cgroup v2

In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within 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. But the cgroup v2 does not. So this patch adds the missing information.

---
 mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
mm/memcontrol.c +44 -2
index 75cd1a1e66c8..c779673f29b2 100644
@@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
 	return false;
 }
 
+#ifdef CONFIG_NUMA
+static unsigned long memcg_node_page_state(struct mem_cgroup *memcg,
+					   unsigned int nid,
+					   enum node_stat_item idx)
+{
+	long x;
+	struct mem_cgroup_per_node *pn;
+	struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+
+	VM_BUG_ON(nid >= nr_node_ids);
+
+	pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
+	x = atomic_long_read(&pn->lruvec_stat[idx]);
+#ifdef CONFIG_SMP
+	if (x < 0)
+		x = 0;
+#endif
+	return x;
+}
+#endif
+
 static char *memory_stat_format(struct mem_cgroup *memcg)
 {
 	struct seq_buf s;
 	int i;
+#ifdef CONFIG_NUMA
+	int nid;
+#endif
 
 	seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
 	if (!s.buffer)
@@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
 	 * Current memory state:
 	 */
 
-	seq_buf_printf(&s, "anon %llu\n",
+	seq_buf_printf(&s, "anon %llu",
 		       (u64)memcg_page_state(memcg, NR_ANON_MAPPED) *
 		       PAGE_SIZE);
-	seq_buf_printf(&s, "file %llu\n",
+#ifdef CONFIG_NUMA
+	for_each_node_state(nid, N_MEMORY)
+		seq_buf_printf(&s, " N%d=%llu", nid,
+			       (u64)memcg_node_page_state(memcg, nid,
+							  NR_ANON_MAPPED) *
+			       PAGE_SIZE);
+#endif
+	seq_buf_putc(&s, '\n');
+
+	seq_buf_printf(&s, "file %llu",
 		       (u64)memcg_page_state(memcg, NR_FILE_PAGES) *
 		       PAGE_SIZE);
+#ifdef CONFIG_NUMA
+	for_each_node_state(nid, N_MEMORY)
+		seq_buf_printf(&s, " N%d=%llu", nid,
+			       (u64)memcg_node_page_state(memcg, nid,
+							  NR_FILE_PAGES) *
+			       PAGE_SIZE);
+#endif
+	seq_buf_putc(&s, '\n');
+
 	seq_buf_printf(&s, "kernel_stack %llu\n",
 		       (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) *
 		       1024);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Muchun Song

In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within 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. But the cgroup v2 does not. So this patch adds the missing information.

---

I am actually working on exposing this info on v2 as well.

Quoted 43 lines
 mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
mm/memcontrol.c +24 -0
index 75cd1a1e66c8..c779673f29b2 100644
@@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
        return false;
 }
 
+#ifdef CONFIG_NUMA
+static unsigned long memcg_node_page_state(struct mem_cgroup *memcg,
+                                          unsigned int nid,
+                                          enum node_stat_item idx)
+{
+       long x;
+       struct mem_cgroup_per_node *pn;
+       struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+
+       VM_BUG_ON(nid >= nr_node_ids);
+
+       pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
+       x = atomic_long_read(&pn->lruvec_stat[idx]);
+#ifdef CONFIG_SMP
+       if (x < 0)
+               x = 0;
+#endif
+       return x;
+}
+#endif
+
 static char *memory_stat_format(struct mem_cgroup *memcg)
 {
        struct seq_buf s;
        int i;
+#ifdef CONFIG_NUMA
+       int nid;
+#endif
 
        seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
        if (!s.buffer)

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1538

Quoted 3 lines
mm/memcontrol.c +0 -0
@@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
         * Current memory state:
         */
 

Let's not break the parsers of memory.stat. I would prefer a separate interface like v1 i.e. memory.numa_stat.

Quoted 16 lines
mm/memcontrol.c +11 -2
-       seq_buf_printf(&s, "anon %llu\n",
+       seq_buf_printf(&s, "anon %llu",
                       (u64)memcg_page_state(memcg, NR_ANON_MAPPED) *
                       PAGE_SIZE);
-       seq_buf_printf(&s, "file %llu\n",
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_ANON_MAPPED) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+
+       seq_buf_printf(&s, "file %llu",
                       (u64)memcg_page_state(memcg, NR_FILE_PAGES) *

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1562

Quoted 10 lines
mm/memcontrol.c +9 -0
                       PAGE_SIZE);
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_FILE_PAGES) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+

The v1's numa_stat exposes the LRUs, why NR_ANON_MAPPED and NR_FILE_PAGES?

Also I think exposing slab_[un]reclaimable per node would be beneficial as well.

Quoted 6 lines
mm/memcontrol.c +0 -1
        seq_buf_printf(&s, "kernel_stack %llu\n",
                       (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) *
                       1024);
--

2.20.1

#2 lore raw
Quoted 55 lines · Shakeel Butt
Quoted 10 lines · Muchun Song

In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within 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. But the cgroup v2 does not. So this patch adds the missing information.

---

I am actually working on exposing this info on v2 as well.

Quoted 40 lines
 mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
mm/memcontrol.c +24 -0
index 75cd1a1e66c8..c779673f29b2 100644
@@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
        return false;
 }
 
+#ifdef CONFIG_NUMA
+static unsigned long memcg_node_page_state(struct mem_cgroup *memcg,
+                                          unsigned int nid,
+                                          enum node_stat_item idx)
+{
+       long x;
+       struct mem_cgroup_per_node *pn;
+       struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+
+       VM_BUG_ON(nid >= nr_node_ids);
+
+       pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
+       x = atomic_long_read(&pn->lruvec_stat[idx]);
+#ifdef CONFIG_SMP
+       if (x < 0)
+               x = 0;
+#endif
+       return x;
+}
+#endif
+
 static char *memory_stat_format(struct mem_cgroup *memcg)
 {
        struct seq_buf s;
        int i;
+#ifdef CONFIG_NUMA
+       int nid;
+#endif
 
Quoted 9 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1538

Quoted 6 lines
mm/memcontrol.c +0 -0
        seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
        if (!s.buffer)
@@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
         * Current memory state:
         */
 

Let's not break the parsers of memory.stat. I would prefer a separate interface like v1 i.e. memory.numa_stat.

It is also a good idea to expose a new interface like memory.numa_stat.

Quoted 21 lines
Quoted 21 lines
mm/memcontrol.c +14 -2
-       seq_buf_printf(&s, "anon %llu\n",
+       seq_buf_printf(&s, "anon %llu",
                       (u64)memcg_page_state(memcg, NR_ANON_MAPPED) *
                       PAGE_SIZE);
-       seq_buf_printf(&s, "file %llu\n",
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_ANON_MAPPED) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+
+       seq_buf_printf(&s, "file %llu",
                       (u64)memcg_page_state(memcg, NR_FILE_PAGES) *
                       PAGE_SIZE);
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
Quoted 8 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1562

Quoted 6 lines
mm/memcontrol.c +6 -0
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_FILE_PAGES) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+

The v1's numa_stat exposes the LRUs, why NR_ANON_MAPPED and NR_FILE_PAGES?

If we want to expose the anon per node, we need to add inactive anon and active anon together. Why not use NR_ANON_MAPPED directly?

Quoted 2 lines

Also I think exposing slab_[un]reclaimable per node would be beneficial as well.

Yeah, I agree with you. Maybe kernel_stack and percpu also should be exposed.

Quoted 7 lines
Quoted 7 lines
mm/memcontrol.c +0 -1
        seq_buf_printf(&s, "kernel_stack %llu\n",
                       (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) *
                       1024);
--

2.20.1

Signature · 2 lines
Yours,
Muchun
#3 lore raw
Quoted 99 lines · Muchun Song
Quoted 55 lines · Shakeel Butt
Quoted 10 lines · Muchun Song

In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within 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. But the cgroup v2 does not. So this patch adds the missing information.

---

I am actually working on exposing this info on v2 as well.

Quoted 40 lines
 mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
mm/memcontrol.c +24 -0
index 75cd1a1e66c8..c779673f29b2 100644
@@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
        return false;
 }
 
+#ifdef CONFIG_NUMA
+static unsigned long memcg_node_page_state(struct mem_cgroup *memcg,
+                                          unsigned int nid,
+                                          enum node_stat_item idx)
+{
+       long x;
+       struct mem_cgroup_per_node *pn;
+       struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+
+       VM_BUG_ON(nid >= nr_node_ids);
+
+       pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
+       x = atomic_long_read(&pn->lruvec_stat[idx]);
+#ifdef CONFIG_SMP
+       if (x < 0)
+               x = 0;
+#endif
+       return x;
+}
+#endif
+
 static char *memory_stat_format(struct mem_cgroup *memcg)
 {
        struct seq_buf s;
        int i;
+#ifdef CONFIG_NUMA
+       int nid;
+#endif
 
Quoted 9 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1538

Quoted 6 lines
mm/memcontrol.c +0 -0
        seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
        if (!s.buffer)
@@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
         * Current memory state:
         */
 

Let's not break the parsers of memory.stat. I would prefer a separate interface like v1 i.e. memory.numa_stat.

It is also a good idea to expose a new interface like memory.numa_stat.

Quoted 21 lines
Quoted 21 lines
mm/memcontrol.c +14 -2
-       seq_buf_printf(&s, "anon %llu\n",
+       seq_buf_printf(&s, "anon %llu",
                       (u64)memcg_page_state(memcg, NR_ANON_MAPPED) *
                       PAGE_SIZE);
-       seq_buf_printf(&s, "file %llu\n",
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_ANON_MAPPED) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+
+       seq_buf_printf(&s, "file %llu",
                       (u64)memcg_page_state(memcg, NR_FILE_PAGES) *
                       PAGE_SIZE);
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
Quoted 8 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1562

Quoted 6 lines
mm/memcontrol.c +6 -0
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_FILE_PAGES) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+

The v1's numa_stat exposes the LRUs, why NR_ANON_MAPPED and NR_FILE_PAGES?

Quoted 3 lines

If we want to expose the anon per node, we need to add inactive anon and active anon together. Why not use NR_ANON_MAPPED directly?

Active anon plus inactive anon is not equal to NR_ANON_MAPPED. The shmem related memory is on anon LRUs but not accounted in NR_ANON_MAPPED.

Similarly file LRU can contain MADV_FREE pages which are not accounted in NR_FILE_PAGES.

Quoted 19 lines
Quoted 2 lines

Also I think exposing slab_[un]reclaimable per node would be beneficial as well.

Yeah, I agree with you. Maybe kernel_stack and percpu also should be exposed.

Quoted 7 lines
Quoted 7 lines
mm/memcontrol.c +0 -1
        seq_buf_printf(&s, "kernel_stack %llu\n",
                       (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) *
                       1024);
--

2.20.1

--
Yours,
Muchun

#4 lore raw
Quoted 105 lines · Shakeel Butt
Quoted 99 lines · Muchun Song
Quoted 55 lines · Shakeel Butt
Quoted 10 lines · Muchun Song

In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within 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. But the cgroup v2 does not. So this patch adds the missing information.

---

I am actually working on exposing this info on v2 as well.

Quoted 40 lines
 mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
mm/memcontrol.c +24 -0
index 75cd1a1e66c8..c779673f29b2 100644
@@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
        return false;
 }
 
+#ifdef CONFIG_NUMA
+static unsigned long memcg_node_page_state(struct mem_cgroup *memcg,
+                                          unsigned int nid,
+                                          enum node_stat_item idx)
+{
+       long x;
+       struct mem_cgroup_per_node *pn;
+       struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+
+       VM_BUG_ON(nid >= nr_node_ids);
+
+       pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
+       x = atomic_long_read(&pn->lruvec_stat[idx]);
+#ifdef CONFIG_SMP
+       if (x < 0)
+               x = 0;
+#endif
+       return x;
+}
+#endif
+
 static char *memory_stat_format(struct mem_cgroup *memcg)
 {
        struct seq_buf s;
        int i;
+#ifdef CONFIG_NUMA
+       int nid;
+#endif
 
Quoted 9 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1538

Quoted 6 lines
mm/memcontrol.c +0 -0
        seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
        if (!s.buffer)
@@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
         * Current memory state:
         */
 

Let's not break the parsers of memory.stat. I would prefer a separate interface like v1 i.e. memory.numa_stat.

It is also a good idea to expose a new interface like memory.numa_stat.

Quoted 21 lines
Quoted 21 lines
mm/memcontrol.c +14 -2
-       seq_buf_printf(&s, "anon %llu\n",
+       seq_buf_printf(&s, "anon %llu",
                       (u64)memcg_page_state(memcg, NR_ANON_MAPPED) *
                       PAGE_SIZE);
-       seq_buf_printf(&s, "file %llu\n",
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_ANON_MAPPED) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+
+       seq_buf_printf(&s, "file %llu",
                       (u64)memcg_page_state(memcg, NR_FILE_PAGES) *
                       PAGE_SIZE);
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
Quoted 8 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1562

Quoted 6 lines
mm/memcontrol.c +6 -0
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_FILE_PAGES) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+

The v1's numa_stat exposes the LRUs, why NR_ANON_MAPPED and NR_FILE_PAGES?

Quoted 3 lines

If we want to expose the anon per node, we need to add inactive anon and active anon together. Why not use NR_ANON_MAPPED directly?

Quoted 6 lines

Active anon plus inactive anon is not equal to NR_ANON_MAPPED. The shmem related memory is on anon LRUs but not accounted in NR_ANON_MAPPED.

Similarly file LRU can contain MADV_FREE pages which are not accounted in NR_FILE_PAGES.

I got it, thanks. Because the "state" interface exposes the anon and file information. So I think that we also should expose the anon and file for "numa_stat" per node instead of the lru statistics. Maybe it is better that we expose both of all the information.

Quoted 20 lines
Quoted 20 lines
Quoted 3 lines

Also I think exposing slab_[un]reclaimable per node would be beneficial as well.

Yeah, I agree with you. Maybe kernel_stack and percpu also should be exposed.

Quoted 7 lines
Quoted 7 lines
mm/memcontrol.c +0 -1
        seq_buf_printf(&s, "kernel_stack %llu\n",
                       (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) *
                       1024);
--

2.20.1

--
Yours,
Muchun

Signature · 2 lines
Yours,
Muchun
#5 lore raw
Quoted 1 line · Muchun Song

[snip]

Quoted 6 lines

I got it, thanks. Because the "state" interface exposes the anon and file information. So I think that we also should expose the anon and file for "numa_stat" per node instead of the lru statistics. Maybe it is better that we expose both of all the information.

Sure, go ahead and please do update the doc file as well in the next version.

#6 lore raw
In reply to Muchun Song
Quoted 98 lines · Muchun Song
Quoted 55 lines · Shakeel Butt
Quoted 10 lines · Muchun Song

In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within 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. But the cgroup v2 does not. So this patch adds the missing information.

---

I am actually working on exposing this info on v2 as well.

Quoted 40 lines
 mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
mm/memcontrol.c +24 -0
index 75cd1a1e66c8..c779673f29b2 100644
@@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
        return false;
 }
 
+#ifdef CONFIG_NUMA
+static unsigned long memcg_node_page_state(struct mem_cgroup *memcg,
+                                          unsigned int nid,
+                                          enum node_stat_item idx)
+{
+       long x;
+       struct mem_cgroup_per_node *pn;
+       struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+
+       VM_BUG_ON(nid >= nr_node_ids);
+
+       pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
+       x = atomic_long_read(&pn->lruvec_stat[idx]);
+#ifdef CONFIG_SMP
+       if (x < 0)
+               x = 0;
+#endif
+       return x;
+}
+#endif
+
 static char *memory_stat_format(struct mem_cgroup *memcg)
 {
        struct seq_buf s;
        int i;
+#ifdef CONFIG_NUMA
+       int nid;
+#endif
 
Quoted 9 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1538

Quoted 6 lines
mm/memcontrol.c +0 -0
        seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
        if (!s.buffer)
@@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
         * Current memory state:
         */
 

Let's not break the parsers of memory.stat. I would prefer a separate interface like v1 i.e. memory.numa_stat.

It is also a good idea to expose a new interface like memory.numa_stat.

Quoted 21 lines
Quoted 21 lines
mm/memcontrol.c +14 -2
-       seq_buf_printf(&s, "anon %llu\n",
+       seq_buf_printf(&s, "anon %llu",
                       (u64)memcg_page_state(memcg, NR_ANON_MAPPED) *
                       PAGE_SIZE);
-       seq_buf_printf(&s, "file %llu\n",
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_ANON_MAPPED) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+
+       seq_buf_printf(&s, "file %llu",
                       (u64)memcg_page_state(memcg, NR_FILE_PAGES) *
                       PAGE_SIZE);
+#ifdef CONFIG_NUMA
+       for_each_node_state(nid, N_MEMORY)
+               seq_buf_printf(&s, " N%d=%llu", nid,
Quoted 8 lines

mm/memcontrol.c static char *memory_stat_format(struct mem_cgroup *memcg) · line 1562

Quoted 6 lines
mm/memcontrol.c +6 -0
+                              (u64)memcg_node_page_state(memcg, nid,
+                                                         NR_FILE_PAGES) *
+                              PAGE_SIZE);
+#endif
+       seq_buf_putc(&s, '\n');
+

The v1's numa_stat exposes the LRUs, why NR_ANON_MAPPED and NR_FILE_PAGES?

Quoted 8 lines

If we want to expose the anon per node, we need to add inactive anon and active anon together. Why not use NR_ANON_MAPPED directly?

Quoted 2 lines

Also I think exposing slab_[un]reclaimable per node would be beneficial as well.

Yeah, I agree with you. Maybe kernel_stack and percpu also should be exposed.

Percpu allocations are usually spread over multiple pages and numa nodes, so there are no per-node pepcpu counters.

Thanks!

Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
mm/memcontrol.c +0 -1
        seq_buf_printf(&s, "kernel_stack %llu\n",
                       (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) *
                       1024);
--

2.20.1

Signature · 2 lines
Yours,
Muchun