linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2  0/2] Replace nr_node_ids for loop with for_each_node
@ 2015-09-15  2:08 Raghavendra K T
  2015-09-15  2:08 ` [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru Raghavendra K T
  2015-09-15  2:08 ` [PATCH V2 2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes Raghavendra K T
  0 siblings, 2 replies; 8+ messages in thread
From: Raghavendra K T @ 2015-09-15  2:08 UTC (permalink / raw)
  To: benh, paulus, mpe, anton, akpm
  Cc: nacc, gkurz, grant.likely, nikunj, vdavydov, raghavendra.kt,
	linuxppc-dev, linux-kernel, linux-mm

Many places in the kernel use 'for' loop with nr_node_ids. For the architectures
which supports sparse numa ids, this will result in some unnecessary allocations
for non existing nodes.
(for e.g., numa node numbers such as 0,1,16,17 is common in powerpc.)

So replace the for loop with for_each_node so that allocations happen only for
existing numa nodes.

Please note that, though there are many places where nr_node_ids is used,
current patchset uses for_each_node only for slowpath to avoid find_next_bit
traversal.

Changes in V2:
  - Take memcg_aware check outside for_each loop (Vldimir)
  - Add comment that node 0 should always be present (Vladimir)

Raghavendra K T (2):
  mm: Replace nr_node_ids for loop with for_each_node in list lru
  powerpc:numa Do not allocate bootmem memory for non existing nodes

 arch/powerpc/mm/numa.c |  2 +-
 mm/list_lru.c          | 34 +++++++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 12 deletions(-)

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru
  2015-09-15  2:08 [PATCH V2 0/2] Replace nr_node_ids for loop with for_each_node Raghavendra K T
@ 2015-09-15  2:08 ` Raghavendra K T
  2015-09-15  2:17   ` Raghavendra K T
  2015-09-15  7:59   ` Vladimir Davydov
  2015-09-15  2:08 ` [PATCH V2 2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes Raghavendra K T
  1 sibling, 2 replies; 8+ messages in thread
From: Raghavendra K T @ 2015-09-15  2:08 UTC (permalink / raw)
  To: benh, paulus, mpe, anton, akpm
  Cc: nacc, gkurz, grant.likely, nikunj, vdavydov, raghavendra.kt,
	linuxppc-dev, linux-kernel, linux-mm

The functions used in the patch are in slowpath, which gets called
whenever alloc_super is called during mounts.

Though this should not make difference for the architectures with
sequential numa node ids, for the powerpc which can potentially have
sparse node ids (for e.g., 4 node system having numa ids, 0,1,16,17
is common), this patch saves some unnecessary allocations for
non existing numa nodes.

Even without that saving, perhaps patch makes code more readable.

[ Take memcg_aware check outside for_each loop: Vldimir]
Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
---
 mm/list_lru.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

 Changes in V2:
  - Take memcg_aware check outside for_each loop (Vldimir)
  - Add comment that node 0 should always be present (Vladimir)  
  
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 909eca2..60cd6dd 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -42,6 +42,10 @@ static void list_lru_unregister(struct list_lru *lru)
 #ifdef CONFIG_MEMCG_KMEM
 static inline bool list_lru_memcg_aware(struct list_lru *lru)
 {
+	/*
+	 * This needs node 0 to be always present, even
+	 * in the systems supporting sparse numa ids.
+	 */
 	return !!lru->node[0].memcg_lrus;
 }
 
@@ -377,16 +381,20 @@ static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware)
 {
 	int i;
 
-	for (i = 0; i < nr_node_ids; i++) {
-		if (!memcg_aware)
-			lru->node[i].memcg_lrus = NULL;
-		else if (memcg_init_list_lru_node(&lru->node[i]))
+	if (!memcg_aware)
+		return 0;
+
+	for_each_node(i) {
+		if (memcg_init_list_lru_node(&lru->node[i]))
 			goto fail;
 	}
 	return 0;
 fail:
-	for (i = i - 1; i >= 0; i--)
+	for (i = i - 1; i >= 0; i--) {
+		if (!lru->node[i].memcg_lrus)
+			continue;
 		memcg_destroy_list_lru_node(&lru->node[i]);
+	}
 	return -ENOMEM;
 }
 
@@ -397,7 +405,7 @@ static void memcg_destroy_list_lru(struct list_lru *lru)
 	if (!list_lru_memcg_aware(lru))
 		return;
 
-	for (i = 0; i < nr_node_ids; i++)
+	for_each_node(i)
 		memcg_destroy_list_lru_node(&lru->node[i]);
 }
 
@@ -409,16 +417,20 @@ static int memcg_update_list_lru(struct list_lru *lru,
 	if (!list_lru_memcg_aware(lru))
 		return 0;
 
-	for (i = 0; i < nr_node_ids; i++) {
+	for_each_node(i) {
 		if (memcg_update_list_lru_node(&lru->node[i],
 					       old_size, new_size))
 			goto fail;
 	}
 	return 0;
 fail:
-	for (i = i - 1; i >= 0; i--)
+	for (i = i - 1; i >= 0; i--) {
+		if (!lru->node[i].memcg_lrus)
+			continue;
+
 		memcg_cancel_update_list_lru_node(&lru->node[i],
 						  old_size, new_size);
+	}
 	return -ENOMEM;
 }
 
@@ -430,7 +442,7 @@ static void memcg_cancel_update_list_lru(struct list_lru *lru,
 	if (!list_lru_memcg_aware(lru))
 		return;
 
-	for (i = 0; i < nr_node_ids; i++)
+	for_each_node(i)
 		memcg_cancel_update_list_lru_node(&lru->node[i],
 						  old_size, new_size);
 }
@@ -485,7 +497,7 @@ static void memcg_drain_list_lru(struct list_lru *lru,
 	if (!list_lru_memcg_aware(lru))
 		return;
 
-	for (i = 0; i < nr_node_ids; i++)
+	for_each_node(i)
 		memcg_drain_list_lru_node(&lru->node[i], src_idx, dst_idx);
 }
 
@@ -522,7 +534,7 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware,
 	if (!lru->node)
 		goto out;
 
-	for (i = 0; i < nr_node_ids; i++) {
+	for_each_node(i) {
 		spin_lock_init(&lru->node[i].lock);
 		if (key)
 			lockdep_set_class(&lru->node[i].lock, key);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V2 2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes
  2015-09-15  2:08 [PATCH V2 0/2] Replace nr_node_ids for loop with for_each_node Raghavendra K T
  2015-09-15  2:08 ` [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru Raghavendra K T
@ 2015-09-15  2:08 ` Raghavendra K T
  2015-09-22  5:29   ` Michael Ellerman
  1 sibling, 1 reply; 8+ messages in thread
From: Raghavendra K T @ 2015-09-15  2:08 UTC (permalink / raw)
  To: benh, paulus, mpe, anton, akpm
  Cc: nacc, gkurz, grant.likely, nikunj, vdavydov, raghavendra.kt,
	linuxppc-dev, linux-kernel, linux-mm

Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
---
 arch/powerpc/mm/numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 8b9502a..8d8a541 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -80,7 +80,7 @@ static void __init setup_node_to_cpumask_map(void)
 		setup_nr_node_ids();
 
 	/* allocate the map */
-	for (node = 0; node < nr_node_ids; node++)
+	for_each_node(node)
 		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
 
 	/* cpumask_of_node() will now work */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru
  2015-09-15  2:08 ` [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru Raghavendra K T
@ 2015-09-15  2:17   ` Raghavendra K T
  2015-09-15  7:59   ` Vladimir Davydov
  1 sibling, 0 replies; 8+ messages in thread
From: Raghavendra K T @ 2015-09-15  2:17 UTC (permalink / raw)
  To: Raghavendra K T
  Cc: benh, paulus, mpe, anton, akpm, nacc, gkurz, grant.likely,
	nikunj, vdavydov, linuxppc-dev, linux-kernel, linux-mm

On 09/15/2015 07:38 AM, Raghavendra K T wrote:
> The functions used in the patch are in slowpath, which gets called
> whenever alloc_super is called during mounts.
>
> Though this should not make difference for the architectures with
> sequential numa node ids, for the powerpc which can potentially have
> sparse node ids (for e.g., 4 node system having numa ids, 0,1,16,17
> is common), this patch saves some unnecessary allocations for
> non existing numa nodes.
>
> Even without that saving, perhaps patch makes code more readable.
>
> [ Take memcg_aware check outside for_each loop: Vladimir]
> Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
> ---

Sorry that I had misspelled Vladimir above.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2  1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru
  2015-09-15  2:08 ` [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru Raghavendra K T
  2015-09-15  2:17   ` Raghavendra K T
@ 2015-09-15  7:59   ` Vladimir Davydov
  1 sibling, 0 replies; 8+ messages in thread
From: Vladimir Davydov @ 2015-09-15  7:59 UTC (permalink / raw)
  To: Raghavendra K T
  Cc: benh, paulus, mpe, anton, akpm, nacc, gkurz, grant.likely,
	nikunj, linuxppc-dev, linux-kernel, linux-mm

On Tue, Sep 15, 2015 at 07:38:36AM +0530, Raghavendra K T wrote:
> The functions used in the patch are in slowpath, which gets called
> whenever alloc_super is called during mounts.
> 
> Though this should not make difference for the architectures with
> sequential numa node ids, for the powerpc which can potentially have
> sparse node ids (for e.g., 4 node system having numa ids, 0,1,16,17
> is common), this patch saves some unnecessary allocations for
> non existing numa nodes.
> 
> Even without that saving, perhaps patch makes code more readable.
> 
> [ Take memcg_aware check outside for_each loop: Vldimir]
> Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>

Reviewed-by: Vladimir Davydov <vdavydov@parallels.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2  2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes
  2015-09-15  2:08 ` [PATCH V2 2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes Raghavendra K T
@ 2015-09-22  5:29   ` Michael Ellerman
  2015-09-22 10:48     ` Raghavendra K T
  2015-09-22 19:36     ` Raghavendra K T
  0 siblings, 2 replies; 8+ messages in thread
From: Michael Ellerman @ 2015-09-22  5:29 UTC (permalink / raw)
  To: Raghavendra K T
  Cc: benh, paulus, anton, akpm, nacc, gkurz, grant.likely, nikunj,
	vdavydov, linuxppc-dev, linux-kernel, linux-mm

On Tue, 2015-09-15 at 07:38 +0530, Raghavendra K T wrote:
>
> ... nothing

Sure this patch looks obvious, but please give me a changelog that proves
you've thought about it thoroughly.

For example is it OK to use for_each_node() at this point in boot? Is there any
historical reason why we did it with a hard coded loop? If so what has changed.
What systems have you tested on? etc. etc.

cheers

> Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
> ---
>  arch/powerpc/mm/numa.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
> index 8b9502a..8d8a541 100644
> --- a/arch/powerpc/mm/numa.c
> +++ b/arch/powerpc/mm/numa.c
> @@ -80,7 +80,7 @@ static void __init setup_node_to_cpumask_map(void)
>  		setup_nr_node_ids();
>  
>  	/* allocate the map */
> -	for (node = 0; node < nr_node_ids; node++)
> +	for_each_node(node)
>  		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
>  
>  	/* cpumask_of_node() will now work */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2  2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes
  2015-09-22  5:29   ` Michael Ellerman
@ 2015-09-22 10:48     ` Raghavendra K T
  2015-09-22 19:36     ` Raghavendra K T
  1 sibling, 0 replies; 8+ messages in thread
From: Raghavendra K T @ 2015-09-22 10:48 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: benh, paulus, anton, akpm, nacc, gkurz, grant.likely, nikunj,
	vdavydov, linuxppc-dev, linux-kernel, linux-mm

On 09/22/2015 10:59 AM, Michael Ellerman wrote:
> On Tue, 2015-09-15 at 07:38 +0530, Raghavendra K T wrote:
>>
>> ... nothing
>
> Sure this patch looks obvious, but please give me a changelog that proves
> you've thought about it thoroughly.
>
> For example is it OK to use for_each_node() at this point in boot? Is there any
> historical reason why we did it with a hard coded loop? If so what has changed.
> What systems have you tested on? etc. etc.
>
> cheers

Changelog:

With the setup_nr_nodes(), we have already initialized
node_possible_map. So it is safe to use for_each_node here.

There are many places in the kernel that use hardcoded 'for' loop with
nr_node_ids, because all other architectures have numa nodes populated
serially. That should be reason we had maintained same for powerpc.

But since on power we have sparse numa node ids possible, we
unnecessarily allocate memory for non existent numa nodes.

For e.g., on a system with 0,1,16,17 as numa nodes nr_node_ids=18
and we allocate memory for nodes 2-14.

The patch is boot tested on a 4 node tuleta [ confirming with printks ].
that it works as expected.

>
>> Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
>> ---
>>   arch/powerpc/mm/numa.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
>> index 8b9502a..8d8a541 100644
>> --- a/arch/powerpc/mm/numa.c
>> +++ b/arch/powerpc/mm/numa.c
>> @@ -80,7 +80,7 @@ static void __init setup_node_to_cpumask_map(void)
>>   		setup_nr_node_ids();
>>
>>   	/* allocate the map */
>> -	for (node = 0; node < nr_node_ids; node++)
>> +	for_each_node(node)
>>   		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
>>
>>   	/* cpumask_of_node() will now work */
>
>
>
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2  2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes
  2015-09-22  5:29   ` Michael Ellerman
  2015-09-22 10:48     ` Raghavendra K T
@ 2015-09-22 19:36     ` Raghavendra K T
  1 sibling, 0 replies; 8+ messages in thread
From: Raghavendra K T @ 2015-09-22 19:36 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Raghavendra K T, benh, paulus, anton, akpm, nacc, gkurz,
	grant.likely, nikunj, vdavydov, linuxppc-dev, linux-kernel,
	linux-mm

* Michael Ellerman <mpe@ellerman.id.au> [2015-09-22 15:29:03]:

> On Tue, 2015-09-15 at 07:38 +0530, Raghavendra K T wrote:
> >
> > ... nothing
> 
> Sure this patch looks obvious, but please give me a changelog that proves
> you've thought about it thoroughly.
> 
> For example is it OK to use for_each_node() at this point in boot? Is there any
> historical reason why we did it with a hard coded loop? If so what has changed.
> What systems have you tested on? etc. etc.
> 
> cheers

Hi Michael,
resending the patches with the changelog.

Please note that the patch is in -mm tree already.

---8<---
>From 86ead2520662c362d7b9ebd452ce1c33e156016f Mon Sep 17 00:00:00 2001
From: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
Date: Sun, 6 Sep 2015 12:54:40 +0530
Subject: [PATCH V2  2/2] powerpc:numa Do not allocate bootmem memory for non
 existing nodes

With the setup_nr_nodes(), we have already initialized
node_possible_map. So it is safe to use for_each_node here.

There are many places in the kernel that use hardcoded 'for' loop with
nr_node_ids, because all other architectures have numa nodes populated
serially. That should be reason we had maintained the same for powerpc.

But, since sparse numa node ids possible on powerpc, we
unnecessarily allocate memory for non existent numa nodes.

For e.g., on a system with 0,1,16,17 as numa nodes nr_node_ids=18
and we allocate memory for nodes 2-14. This patch we allocate
memory for only existing numa nodes.

The patch is boot tested on a 4 node tuleta [ confirming with printks ].
that it works as expected.

Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
---
 arch/powerpc/mm/numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 8b9502a..8d8a541 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -80,7 +80,7 @@ static void __init setup_node_to_cpumask_map(void)
 		setup_nr_node_ids();
 
 	/* allocate the map */
-	for (node = 0; node < nr_node_ids; node++)
+	for_each_node(node)
 		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
 
 	/* cpumask_of_node() will now work */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-09-22 19:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-15  2:08 [PATCH V2 0/2] Replace nr_node_ids for loop with for_each_node Raghavendra K T
2015-09-15  2:08 ` [PATCH V2 1/2] mm: Replace nr_node_ids for loop with for_each_node in list lru Raghavendra K T
2015-09-15  2:17   ` Raghavendra K T
2015-09-15  7:59   ` Vladimir Davydov
2015-09-15  2:08 ` [PATCH V2 2/2] powerpc:numa Do not allocate bootmem memory for non existing nodes Raghavendra K T
2015-09-22  5:29   ` Michael Ellerman
2015-09-22 10:48     ` Raghavendra K T
2015-09-22 19:36     ` Raghavendra K T

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).