Skip to contentSkip to conversation

mm/memcg: use NUMA_NO_NODE to indicate allocation from unspecified node

PATCH In review Wei Yang 7 participants 30 messages Jan 11, 2022 – Feb 1, 2022

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/4 mm/memcg: use NUMA_NO_NODE to indicate allocation from unspecified node

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
index 2ed5f2a0879d..11715f7323c0 100644
@@ -5054,7 +5054,7 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	 *       function.
 	 */
 	if (!node_state(node, N_NORMAL_MEMORY))
-		tmp = -1;
+		tmp = NUMA_NO_NODE;
 	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
 	if (!pn)
 		return 1;
Signature · 1 line
2.33.1
author
#1 lore raw

PATCH 2/4 mm/memcg: mem_cgroup_per_node is already set to 0 on allocation

kzalloc_node() would set data to 0, so it's not necessary to set it again.

---
 mm/memcontrol.c | 2 --
 1 file changed, 2 deletions(-)
mm/memcontrol.c +0 -2
index 11715f7323c0..a504616f904a 100644
@@ -5067,8 +5067,6 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	}
 
 	lruvec_init(&pn->lruvec);
-	pn->usage_in_excess = 0;
-	pn->on_tree = false;
 	pn->memcg = memcg;
 
 	memcg->nodeinfo[node] = pn;
Signature · 1 line
2.33.1
Acked-by on v1 2/4
#3 lore raw

Re: [PATCH 2/4] mm/memcg: mem_cgroup_per_node is already set to 0 on allocation

In reply to Wei Yang
Quoted 4 lines · Wei Yang

kzalloc_node() would set data to 0, so it's not necessary to set it again.

Quoted 19 lines
---
 mm/memcontrol.c | 2 --
 1 file changed, 2 deletions(-)
mm/memcontrol.c +0 -2
index 11715f7323c0..a504616f904a 100644
@@ -5067,8 +5067,6 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	}
 
 	lruvec_init(&pn->lruvec);
-	pn->usage_in_excess = 0;
-	pn->on_tree = false;
 	pn->memcg = memcg;
 
 	memcg->nodeinfo[node] = pn;
Signature · 1 line
2.33.1
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] mm/memcg: mem_cgroup_per_node is already set to 0 on allocation

In reply to Wei Yang
Quoted 4 lines · Wei Yang

kzalloc_node() would set data to 0, so it's not necessary to set it again.

Quoted 21 lines
---
 mm/memcontrol.c | 2 --
 1 file changed, 2 deletions(-)
mm/memcontrol.c +0 -2
index 11715f7323c0..a504616f904a 100644
@@ -5067,8 +5067,6 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	}
 
 	lruvec_init(&pn->lruvec);
-	pn->usage_in_excess = 0;
-	pn->on_tree = false;
 	pn->memcg = memcg;
 
 	memcg->nodeinfo[node] = pn;
Signature · 1 line
2.33.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#7 lore raw

PATCH 3/4 mm/memcg: retrieve parent memcg from css.parent

In reply to Wei Yang

The parent we get from page_counter is correct, while this is two different hierarchy.

Let's retrieve the parent memcg from css.parent just like parent_cs(), blkcg_parent(), etc.

---
 include/linux/memcontrol.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
include/linux/memcontrol.h +1 -3
index 0c5c403f4be6..12bf443f7b14 100644
@@ -886,9 +886,7 @@ static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec)
  */
 static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
 {
-	if (!memcg->memory.parent)
-		return NULL;
-	return mem_cgroup_from_counter(memcg->memory.parent, memory);
+	return mem_cgroup_from_css(memcg->css.parent);
 }
 
 static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg,
Signature · 1 line
2.33.1
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] mm/memcg: retrieve parent memcg from css.parent

Quoted 8 lines · Wei Yang

The parent we get from page_counter is correct, while this is two different hierarchy.

Let's retrieve the parent memcg from css.parent just like parent_cs(), blkcg_parent(), etc.

Thanks.

Acked-by on v1 3/4
#9 lore raw

Re: [PATCH 3/4] mm/memcg: retrieve parent memcg from css.parent

In reply to Wei Yang
Quoted 7 lines · Wei Yang

The parent we get from page_counter is correct, while this is two different hierarchy.

Let's retrieve the parent memcg from css.parent just like parent_cs(), blkcg_parent(), etc.

Quoted 21 lines
---
 include/linux/memcontrol.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
include/linux/memcontrol.h +1 -3
index 0c5c403f4be6..12bf443f7b14 100644
@@ -886,9 +886,7 @@ static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec)
  */
 static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
 {
-	if (!memcg->memory.parent)
-		return NULL;
-	return mem_cgroup_from_counter(memcg->memory.parent, memory);
+	return mem_cgroup_from_css(memcg->css.parent);
 }
 
 static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg,
Signature · 1 line
2.33.1
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] mm/memcg: retrieve parent memcg from css.parent

In reply to Wei Yang
Quoted 5 lines · Wei Yang

The parent we get from page_counter is correct, while this is two different hierarchy.

Let's retrieve the parent memcg from css.parent just like parent_cs(), blkcg_parent(), etc.

Does it bring any benefits except consistency?

Quoted 2 lines

Thanks!

author
#11 lore raw

Re: [PATCH 3/4] mm/memcg: retrieve parent memcg from css.parent

Quoted 9 lines · Roman Gushchin
Quoted 5 lines · Wei Yang

The parent we get from page_counter is correct, while this is two different hierarchy.

Let's retrieve the parent memcg from css.parent just like parent_cs(), blkcg_parent(), etc.

Does it bring any benefits except consistency?

I am afraid no.

Quoted 6 lines
Quoted 2 lines

Thanks!

Signature · 2 lines
Wei Yang
Help you, Help me
author
#13 lore raw

PATCH 4/4 mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation

In reply to Wei Yang

mem_cgroup_threshold_ary->current_threshold points to the last entry who's threshold is less or equal to usage.

Instead of iterating entries to get the correct index, we can leverage primary->current_threshold to get it. If the threshold added is less or equal to usage, current_threshold should increase by one. Otherwise, it doesn't change.

---
 mm/memcontrol.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
mm/memcontrol.c +17 -14
index a504616f904a..ce7060907df2 100644
@@ -4161,7 +4161,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	struct mem_cgroup_threshold_ary *new;
 	unsigned long threshold;
 	unsigned long usage;
-	int i, size, ret;
+	int size, ret;
 
 	ret = page_counter_memparse(args, "-1", &threshold);
 	if (ret)
@@ -4193,9 +4193,13 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	new->size = size;
 
 	/* Copy thresholds (if any) to new array */
-	if (thresholds->primary)
+	if (thresholds->primary) {
 		memcpy(new->entries, thresholds->primary->entries,
 		       flex_array_size(new, entries, size - 1));
+		new->current_threshold = thresholds->primary->current_threshold;
+	} else {
+		new->current_threshold = -1;
+	}
 
 	/* Add new threshold */
 	new->entries[size - 1].eventfd = eventfd;
@@ -4205,18 +4209,17 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	sort(new->entries, size, sizeof(*new->entries),
 			compare_thresholds, NULL);
 
-	/* Find current threshold */
-	new->current_threshold = -1;
-	for (i = 0; i < size; i++) {
-		if (new->entries[i].threshold <= usage) {
-			/*
-			 * new->current_threshold will not be used until
-			 * rcu_assign_pointer(), so it's safe to increment
-			 * it here.
-			 */
-			++new->current_threshold;
-		} else
-			break;
+	/*
+	 * If the threshold added here is less or equal to usage, this means
+	 * current_threshold need to increase by one.
+	 */
+	if (threshold <= usage) {
+		/*
+		 * new->current_threshold will not be used until
+		 * rcu_assign_pointer(), so it's safe to increment
+		 * it here.
+		 */
+		new->current_threshold++;
 	}
 
 	/* Free old spare buffer and save old primary buffer as spare */
Signature · 1 line
2.33.1
#14 lore raw

Re: [PATCH 4/4] mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation

Quoted 7 lines · Wei Yang

mem_cgroup_threshold_ary->current_threshold points to the last entry who's threshold is less or equal to usage.

Instead of iterating entries to get the correct index, we can leverage primary->current_threshold to get it. If the threshold added is less or equal to usage, current_threshold should increase by one. Otherwise, it doesn't change.

Why do we want/need this change?

Quoted 65 lines
---
 mm/memcontrol.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
mm/memcontrol.c +17 -14
index a504616f904a..ce7060907df2 100644
@@ -4161,7 +4161,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	struct mem_cgroup_threshold_ary *new;
 	unsigned long threshold;
 	unsigned long usage;
-	int i, size, ret;
+	int size, ret;
 
 	ret = page_counter_memparse(args, "-1", &threshold);
 	if (ret)
@@ -4193,9 +4193,13 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	new->size = size;
 
 	/* Copy thresholds (if any) to new array */
-	if (thresholds->primary)
+	if (thresholds->primary) {
 		memcpy(new->entries, thresholds->primary->entries,
 		       flex_array_size(new, entries, size - 1));
+		new->current_threshold = thresholds->primary->current_threshold;
+	} else {
+		new->current_threshold = -1;
+	}
 
 	/* Add new threshold */
 	new->entries[size - 1].eventfd = eventfd;
@@ -4205,18 +4209,17 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	sort(new->entries, size, sizeof(*new->entries),
 			compare_thresholds, NULL);
 
-	/* Find current threshold */
-	new->current_threshold = -1;
-	for (i = 0; i < size; i++) {
-		if (new->entries[i].threshold <= usage) {
-			/*
-			 * new->current_threshold will not be used until
-			 * rcu_assign_pointer(), so it's safe to increment
-			 * it here.
-			 */
-			++new->current_threshold;
-		} else
-			break;
+	/*
+	 * If the threshold added here is less or equal to usage, this means
+	 * current_threshold need to increase by one.
+	 */
+	if (threshold <= usage) {
+		/*
+		 * new->current_threshold will not be used until
+		 * rcu_assign_pointer(), so it's safe to increment
+		 * it here.
+		 */
+		new->current_threshold++;
 	}
 
 	/* Free old spare buffer and save old primary buffer as spare */
Signature · 1 line
2.33.1
Signature · 2 lines
Michal Hocko
SUSE Labs
#15 lore raw

Re: [PATCH 4/4] mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation

In reply to Wei Yang
Quoted 7 lines · Wei Yang

mem_cgroup_threshold_ary->current_threshold points to the last entry who's threshold is less or equal to usage.

Instead of iterating entries to get the correct index, we can leverage primary->current_threshold to get it. If the threshold added is less or equal to usage, current_threshold should increase by one. Otherwise, it doesn't change.

How big is usually an array of thresholds? If it's not huge, likely any savings won't be really noticeable (it's not a hot path and there is an rc_synchronize() below).

So I agree with Michal that a better justification is really needed.

Thanks!

author
#16 lore raw

Re: [PATCH 4/4] mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation

Quoted 4 lines · Roman Gushchin
Quoted 3 lines · Wei Yang

mem_cgroup_threshold_ary->current_threshold points to the last entry who's threshold is less or equal to usage.

Quoted 8 lines
Quoted 4 lines

Instead of iterating entries to get the correct index, we can leverage primary->current_threshold to get it. If the threshold added is less or equal to usage, current_threshold should increase by one. Otherwise, it doesn't change.

How big is usually an array of thresholds? If it's not huge, likely any savings won't be really noticeable (it's not a hot path and there is an rc_synchronize() below).

Usually the size is small I think.

Quoted 2 lines

So I agree with Michal that a better justification is really needed.

Yep.

Quoted 2 lines

Thanks!

Signature · 2 lines
Wei Yang
Help you, Help me
#18 lore raw
In reply to Wei Yang
Quoted 3 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

I am not really sure this is worth it. After the merge window I plan to
post http://lkml.kernel.org/r/20211214100732.26335-1-mhocko-DgEjT+Ai2yi4UlQgPVntAg@public.gmane.org
With that in place we can drop the check and a node rewrite so the net
result will be a less and more straightforward code. If you agree I can
add this with your s-o-b into my series:

mm/memcontrol.c +2 -12
index 781605e92015..ed19a21ee14e 100644
@@ -5044,18 +5044,8 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
 static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 {
 	struct mem_cgroup_per_node *pn;
-	int tmp = node;
-	/*
-	 * This routine is called against possible nodes.
-	 * But it's BUG to call kmalloc() against offline node.
-	 *
-	 * TODO: this routine can waste much memory for nodes which will
-	 *       never be onlined. It's better to use memory hotplug callback
-	 *       function.
-	 */
-	if (!node_state(node, N_NORMAL_MEMORY))
-		tmp = -1;
-	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
+
+	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
 	if (!pn)
 		return 1;
 
Signature · 2 lines
Michal Hocko
SUSE Labs
#20 lore raw
Quoted 10 lines · Wei Yang
Quoted 7 lines · Michal Hocko
Quoted 3 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

I am not really sure this is worth it. After the merge window I plan to
post http://lkml.kernel.org/r/20211214100732.26335-1-mhocko-DgEjT+Ai2yi4UlQgPVntAg@public.gmane.org

Give me some time to understand it :-)

Just for the record, here is what I have put on top of that series:
---
From b7195eba02fe6308a6927450f4630057c05e808e Mon Sep 17 00:00:00 2001
From: Wei Yang <[email protected]>
Date: Tue, 11 Jan 2022 09:45:25 +0100
Subject: [PATCH] memcg: do not tweak node in alloc_mem_cgroup_per_node_info

alloc_mem_cgroup_per_node_info is allocated for each possible node and this used to be a problem because not !node_online nodes didn't have appropriate data structure allocated. This has changed by "mm: handle uninitialized numa nodes gracefully" so we can drop the special casing here.

---
 mm/memcontrol.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
mm/memcontrol.c +2 -12
index 781605e92015..ed19a21ee14e 100644
@@ -5044,18 +5044,8 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
 static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 {
 	struct mem_cgroup_per_node *pn;
-	int tmp = node;
-	/*
-	 * This routine is called against possible nodes.
-	 * But it's BUG to call kmalloc() against offline node.
-	 *
-	 * TODO: this routine can waste much memory for nodes which will
-	 *       never be onlined. It's better to use memory hotplug callback
-	 *       function.
-	 */
-	if (!node_state(node, N_NORMAL_MEMORY))
-		tmp = -1;
-	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
+
+	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
 	if (!pn)
 		return 1;
 
Signature · 6 lines
2.30.2


-- 
Michal Hocko
SUSE Labs
author
#21 lore raw
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Wei Yang
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I am not really sure this is worth it. After the merge window I plan to
post http://lkml.kernel.org/r/20211214100732.26335-1-mhocko-DgEjT+Ai2yi4UlQgPVntAg@public.gmane.org

Give me some time to understand it :-)

Just for the record, here is what I have put on top of that series:

Ok, I got what you try to resolve. I am ok with the following change except one point.

Quoted 25 lines

---

Quoted 1 line

From b7195eba02fe6308a6927450f4630057c05e808e Mon Sep 17 00:00:00 2001

From: Wei Yang <[email protected]>
Date: Tue, 11 Jan 2022 09:45:25 +0100
Subject: [PATCH] memcg: do not tweak node in alloc_mem_cgroup_per_node_info

alloc_mem_cgroup_per_node_info is allocated for each possible node and this used to be a problem because not !node_online nodes didn't have appropriate data structure allocated. This has changed by "mm: handle uninitialized numa nodes gracefully" so we can drop the special casing here.

---
mm/memcontrol.c | 14 ++------------

1 file changed, 2 insertions(+), 12 deletions(-)
mm/memcontrol.c +0 -0
index 781605e92015..ed19a21ee14e 100644
@@ -5044,18 +5044,8 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
 static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 {

mm/memcontrol.c struct mem_cgroup *mem_cgroup_from_id(unsigned short id) · line 5055

Quoted 10 lines
mm/memcontrol.c +0 -9
 	struct mem_cgroup_per_node *pn;
-	int tmp = node;
-	/*
-	 * This routine is called against possible nodes.
-	 * But it's BUG to call kmalloc() against offline node.
-	 *
-	 * TODO: this routine can waste much memory for nodes which will
-	 *       never be onlined. It's better to use memory hotplug callback
-	 *       function.
-	 */

Do you think this TODO is not related to this change?

Quoted 15 lines
mm/memcontrol.c +2 -3
-	if (!node_state(node, N_NORMAL_MEMORY))
-		tmp = -1;
-	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
+
+	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
 	if (!pn)
 		return 1;
 
Signature · 6 lines
2.30.2


-- 
Michal Hocko
SUSE Labs
Signature · 2 lines
Wei Yang
Help you, Help me
#22 lore raw
Quoted 47 lines · Wei Yang
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Wei Yang
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I am not really sure this is worth it. After the merge window I plan to
post http://lkml.kernel.org/r/20211214100732.26335-1-mhocko-DgEjT+Ai2yi4UlQgPVntAg@public.gmane.org

Give me some time to understand it :-)

Just for the record, here is what I have put on top of that series:

Ok, I got what you try to resolve. I am ok with the following change except one point.

Quoted 29 lines

---

Quoted 1 line

From b7195eba02fe6308a6927450f4630057c05e808e Mon Sep 17 00:00:00 2001

From: Wei Yang <[email protected]>
Date: Tue, 11 Jan 2022 09:45:25 +0100
Subject: [PATCH] memcg: do not tweak node in alloc_mem_cgroup_per_node_info

alloc_mem_cgroup_per_node_info is allocated for each possible node and this used to be a problem because not !node_online nodes didn't have appropriate data structure allocated. This has changed by "mm: handle uninitialized numa nodes gracefully" so we can drop the special casing here.

---
mm/memcontrol.c | 14 ++------------

1 file changed, 2 insertions(+), 12 deletions(-)
mm/memcontrol.c +0 -3
index 781605e92015..ed19a21ee14e 100644
@@ -5044,18 +5044,8 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
 static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 {
 	struct mem_cgroup_per_node *pn;
-	int tmp = node;
-	/*
-	 * This routine is called against possible nodes.
Quoted 8 lines

mm/memcontrol.c struct mem_cgroup *mem_cgroup_from_id(unsigned short id) · line 5055

Quoted 6 lines
mm/memcontrol.c +0 -6
-	 * But it's BUG to call kmalloc() against offline node.
-	 *
-	 * TODO: this routine can waste much memory for nodes which will
-	 *       never be onlined. It's better to use memory hotplug callback
-	 *       function.
-	 */

Do you think this TODO is not related to this change?

It is not really related but I am not sure how useful it is. Essentially any allocation that is per-possible node is in the same situation and if we really need to deal with large and sparse possible nodes masks.

If you want me to keep the TODO I will do it though.

Signature · 2 lines
Michal Hocko
SUSE Labs
author
#23 lore raw
Quoted 57 lines · Michal Hocko
Quoted 47 lines · Wei Yang
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Wei Yang
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I am not really sure this is worth it. After the merge window I plan to
post http://lkml.kernel.org/r/20211214100732.26335-1-mhocko-DgEjT+Ai2yi4UlQgPVntAg@public.gmane.org

Give me some time to understand it :-)

Just for the record, here is what I have put on top of that series:

Ok, I got what you try to resolve. I am ok with the following change except one point.

Quoted 29 lines

---

Quoted 1 line

From b7195eba02fe6308a6927450f4630057c05e808e Mon Sep 17 00:00:00 2001

From: Wei Yang <[email protected]>
Date: Tue, 11 Jan 2022 09:45:25 +0100
Subject: [PATCH] memcg: do not tweak node in alloc_mem_cgroup_per_node_info

alloc_mem_cgroup_per_node_info is allocated for each possible node and this used to be a problem because not !node_online nodes didn't have appropriate data structure allocated. This has changed by "mm: handle uninitialized numa nodes gracefully" so we can drop the special casing here.

---
mm/memcontrol.c | 14 ++------------

1 file changed, 2 insertions(+), 12 deletions(-)
mm/memcontrol.c +0 -3
index 781605e92015..ed19a21ee14e 100644
@@ -5044,18 +5044,8 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
 static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 {
 	struct mem_cgroup_per_node *pn;
-	int tmp = node;
-	/*
-	 * This routine is called against possible nodes.
Quoted 8 lines

mm/memcontrol.c struct mem_cgroup *mem_cgroup_from_id(unsigned short id) · line 5055

Quoted 6 lines
mm/memcontrol.c +0 -6
-	 * But it's BUG to call kmalloc() against offline node.
-	 *
-	 * TODO: this routine can waste much memory for nodes which will
-	 *       never be onlined. It's better to use memory hotplug callback
-	 *       function.
-	 */

Do you think this TODO is not related to this change?

Quoted 4 lines

It is not really related but I am not sure how useful it is. Essentially any allocation that is per-possible node is in the same situation and if we really need to deal with large and sparse possible nodes masks.

Sounds reasonable :-)

Quoted 5 lines

If you want me to keep the TODO I will do it though.

Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Wei Yang
Help you, Help me
Reviewed-by
#24 lore raw
In reply to Michal Hocko
Quoted 20 lines · Michal Hocko
Quoted 10 lines · Wei Yang
Quoted 7 lines · Michal Hocko
Quoted 3 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

I am not really sure this is worth it. After the merge window I plan to
post http://lkml.kernel.org/r/20211214100732.26335-1-mhocko-DgEjT+Ai2yi4UlQgPVntAg@public.gmane.org

Give me some time to understand it :-)

Just for the record, here is what I have put on top of that series:
---
From b7195eba02fe6308a6927450f4630057c05e808e Mon Sep 17 00:00:00 2001
From: Wei Yang <[email protected]>
Date: Tue, 11 Jan 2022 09:45:25 +0100
Subject: [PATCH] memcg: do not tweak node in alloc_mem_cgroup_per_node_info

Quoted 8 lines

alloc_mem_cgroup_per_node_info is allocated for each possible node and this used to be a problem because not !node_online nodes didn't have appropriate data structure allocated. This has changed by "mm: handle uninitialized numa nodes gracefully" so we can drop the special casing here.

Reviewed-by on v1 1/4
#26 lore raw
In reply to Wei Yang
Quoted 3 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

Quoted 21 lines
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
index 2ed5f2a0879d..11715f7323c0 100644
@@ -5054,7 +5054,7 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	 *       function.
 	 */
 	if (!node_state(node, N_NORMAL_MEMORY))
-		tmp = -1;
+		tmp = NUMA_NO_NODE;
 	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
 	if (!pn)
 		return 1;
Signature · 1 line
2.33.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#27 lore raw
In reply to Wei Yang

Hi, Andrew

Would you pick up this patch set, or prefer me to send a v2?

Quoted 22 lines · Wei Yang

Instead of use "-1", let's use NUMA_NO_NODE for consistency.

---
mm/memcontrol.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
index 2ed5f2a0879d..11715f7323c0 100644
@@ -5054,7 +5054,7 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	 *       function.
 	 */
 	if (!node_state(node, N_NORMAL_MEMORY))
-		tmp = -1;
+		tmp = NUMA_NO_NODE;
 	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
 	if (!pn)
 		return 1;
Signature · 1 line
2.33.1
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#28 lore raw
Quoted 4 lines · On Mon, 31 Jan 2022 01:47:42 +0000 Wei Yang…

Hi, Andrew

Would you pick up this patch set, or prefer me to send a v2?

It's unclear to me what's happening with [4/4]. At least a new changelog with more justification is expected?

So yes, please resend?

author
#29 lore raw
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Mon, 31 Jan 2022 01:47:42 +0000 Wei Yang…

Hi, Andrew

Would you pick up this patch set, or prefer me to send a v2?

It's unclear to me what's happening with [4/4]. At least a new changelog with more justification is expected?

As Michal and Roman suggested, this is not a hot-path. I would drop this one.

Quoted 1 line

So yes, please resend?

Sure.

Signature · 2 lines
Wei Yang
Help you, Help me