Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu
@ 2020-01-26 13:20 Wei Yang
  2020-01-26 22:44 ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Wei Yang @ 2020-01-26 13:20 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Wei Yang

When onlining a cpu, kswapd_cpu_online() is called to adjust kswapd cpu
affinity.

Current routine does like this:

  * Iterate all the numa node
  * Adjust cpu affinity when node has an online cpu

Actually we could improve this by:

  * Just adjust the numa node to which current online cpu belongs

Because we know which numa node the cpu belongs to and this cpu would
not affect other node.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 mm/vmscan.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 572fb17c6273..19c92d35045c 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4049,18 +4049,19 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
    restore their cpu bindings. */
 static int kswapd_cpu_online(unsigned int cpu)
 {
-	int nid;
+	int nid = cpu_to_node(cpu);
+	pg_data_t *pgdat;
+	const struct cpumask *mask;
 
-	for_each_node_state(nid, N_MEMORY) {
-		pg_data_t *pgdat = NODE_DATA(nid);
-		const struct cpumask *mask;
+	if (!node_state(nid, N_MEMORY))
+		return 0;
 
-		mask = cpumask_of_node(pgdat->node_id);
+	pgdat = NODE_DATA(nid);
+	mask = cpumask_of_node(nid);
+
+	/* One of our CPUs online: restore mask */
+	set_cpus_allowed_ptr(pgdat->kswapd, mask);
 
-		if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
-			/* One of our CPUs online: restore mask */
-			set_cpus_allowed_ptr(pgdat->kswapd, mask);
-	}
 	return 0;
 }
 
-- 
2.17.1



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

* Re: [PATCH] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu
  2020-01-26 13:20 [PATCH] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu Wei Yang
@ 2020-01-26 22:44 ` David Rientjes
  2020-01-28  0:39   ` Wei Yang
  0 siblings, 1 reply; 4+ messages in thread
From: David Rientjes @ 2020-01-26 22:44 UTC (permalink / raw)
  To: Wei Yang; +Cc: akpm, linux-mm, linux-kernel

On Sun, 26 Jan 2020, Wei Yang wrote:

> When onlining a cpu, kswapd_cpu_online() is called to adjust kswapd cpu
> affinity.
> 
> Current routine does like this:
> 
>   * Iterate all the numa node
>   * Adjust cpu affinity when node has an online cpu
> 
> Actually we could improve this by:
> 
>   * Just adjust the numa node to which current online cpu belongs
> 
> Because we know which numa node the cpu belongs to and this cpu would
> not affect other node.
> 

Is there ever a situation where the cpu to be onlined would have appeared 
in the cpumask of another node and so a different kswapd's cpumask would 
now include an off-node cpu?

> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---
>  mm/vmscan.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 572fb17c6273..19c92d35045c 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -4049,18 +4049,19 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
>     restore their cpu bindings. */
>  static int kswapd_cpu_online(unsigned int cpu)
>  {
> -	int nid;
> +	int nid = cpu_to_node(cpu);
> +	pg_data_t *pgdat;
> +	const struct cpumask *mask;
>  
> -	for_each_node_state(nid, N_MEMORY) {
> -		pg_data_t *pgdat = NODE_DATA(nid);
> -		const struct cpumask *mask;
> +	if (!node_state(nid, N_MEMORY))
> +		return 0;
>  
> -		mask = cpumask_of_node(pgdat->node_id);
> +	pgdat = NODE_DATA(nid);
> +	mask = cpumask_of_node(nid);
> +
> +	/* One of our CPUs online: restore mask */
> +	set_cpus_allowed_ptr(pgdat->kswapd, mask);
>  
> -		if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
> -			/* One of our CPUs online: restore mask */
> -			set_cpus_allowed_ptr(pgdat->kswapd, mask);
> -	}
>  	return 0;
>  }
>  
> -- 
> 2.17.1
> 
> 
> 


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

* Re: [PATCH] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu
  2020-01-26 22:44 ` David Rientjes
@ 2020-01-28  0:39   ` Wei Yang
  2020-02-14  5:32     ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Wei Yang @ 2020-01-28  0:39 UTC (permalink / raw)
  To: David Rientjes; +Cc: Wei Yang, akpm, linux-mm, linux-kernel

On Sun, Jan 26, 2020 at 02:44:31PM -0800, David Rientjes wrote:
>On Sun, 26 Jan 2020, Wei Yang wrote:
>
>> When onlining a cpu, kswapd_cpu_online() is called to adjust kswapd cpu
>> affinity.
>> 
>> Current routine does like this:
>> 
>>   * Iterate all the numa node
>>   * Adjust cpu affinity when node has an online cpu
>> 
>> Actually we could improve this by:
>> 
>>   * Just adjust the numa node to which current online cpu belongs
>> 
>> Because we know which numa node the cpu belongs to and this cpu would
>> not affect other node.
>> 
>
>Is there ever a situation where the cpu to be onlined would have appeared 
>in the cpumask of another node and so a different kswapd's cpumask would 
>now include an off-node cpu?

No, I don't think so.

Per my understanding, kswapd_cpu_online() will be invoked when a cpu is
onlined. And the particular cpu belongs to a particular numa node. So it is
not necessary to iterate on every nodes.

And current code use cpumask_and_any() to do the check. If my understanding is
correct, the check would return true if this node has any online cpu. This is
likely to be true.

This is why I want to make the logic clear.

>
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> ---
>>  mm/vmscan.c | 19 ++++++++++---------
>>  1 file changed, 10 insertions(+), 9 deletions(-)
>> 
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 572fb17c6273..19c92d35045c 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -4049,18 +4049,19 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
>>     restore their cpu bindings. */
>>  static int kswapd_cpu_online(unsigned int cpu)
>>  {
>> -	int nid;
>> +	int nid = cpu_to_node(cpu);
>> +	pg_data_t *pgdat;
>> +	const struct cpumask *mask;
>>  
>> -	for_each_node_state(nid, N_MEMORY) {
>> -		pg_data_t *pgdat = NODE_DATA(nid);
>> -		const struct cpumask *mask;
>> +	if (!node_state(nid, N_MEMORY))
>> +		return 0;
>>  
>> -		mask = cpumask_of_node(pgdat->node_id);
>> +	pgdat = NODE_DATA(nid);
>> +	mask = cpumask_of_node(nid);
>> +
>> +	/* One of our CPUs online: restore mask */
>> +	set_cpus_allowed_ptr(pgdat->kswapd, mask);
>>  
>> -		if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
>> -			/* One of our CPUs online: restore mask */
>> -			set_cpus_allowed_ptr(pgdat->kswapd, mask);
>> -	}
>>  	return 0;
>>  }
>>  
>> -- 
>> 2.17.1
>> 
>> 
>> 

-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu
  2020-01-28  0:39   ` Wei Yang
@ 2020-02-14  5:32     ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2020-02-14  5:32 UTC (permalink / raw)
  To: Wei Yang; +Cc: David Rientjes, linux-mm, linux-kernel

On Tue, 28 Jan 2020 08:39:42 +0800 Wei Yang <richardw.yang@linux.intel.com> wrote:

> >Is there ever a situation where the cpu to be onlined would have appeared 
> >in the cpumask of another node and so a different kswapd's cpumask would 
> >now include an off-node cpu?
> 
> No, I don't think so.
> 
> Per my understanding, kswapd_cpu_online() will be invoked when a cpu is
> onlined. And the particular cpu belongs to a particular numa node. So it is
> not necessary to iterate on every nodes.
> 
> And current code use cpumask_and_any() to do the check. If my understanding is
> correct, the check would return true if this node has any online cpu. This is
> likely to be true.
> 
> This is why I want to make the logic clear.

Please resend with a changelog which explains the above?


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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-26 13:20 [PATCH] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu Wei Yang
2020-01-26 22:44 ` David Rientjes
2020-01-28  0:39   ` Wei Yang
2020-02-14  5:32     ` Andrew Morton

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git