linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memcg: remove unneeded nr_scanned
@ 2022-03-28 11:41 Miaohe Lin
  2022-03-28 12:01 ` Michal Hocko
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Miaohe Lin @ 2022-03-28 11:41 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeelb, akpm
  Cc: cgroups, linux-mm, linux-kernel, linmiaohe

The local variable nr_scanned is unneeded as mem_cgroup_soft_reclaim always
does *total_scanned += nr_scanned. So we can pass total_scanned directly to
the mem_cgroup_soft_reclaim to simplify the code and save some cpu cycles
of adding nr_scanned to total_scanned.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/memcontrol.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b686ec4f42c6..79341365ec90 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3384,7 +3384,6 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
 	int loop = 0;
 	struct mem_cgroup_tree_per_node *mctz;
 	unsigned long excess;
-	unsigned long nr_scanned;
 
 	if (order > 0)
 		return 0;
@@ -3412,11 +3411,9 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
 		if (!mz)
 			break;
 
-		nr_scanned = 0;
 		reclaimed = mem_cgroup_soft_reclaim(mz->memcg, pgdat,
-						    gfp_mask, &nr_scanned);
+						    gfp_mask, total_scanned);
 		nr_reclaimed += reclaimed;
-		*total_scanned += nr_scanned;
 		spin_lock_irq(&mctz->lock);
 		__mem_cgroup_remove_exceeded(mz, mctz);
 
-- 
2.23.0



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

* Re: [PATCH] mm/memcg: remove unneeded nr_scanned
  2022-03-28 11:41 [PATCH] mm/memcg: remove unneeded nr_scanned Miaohe Lin
@ 2022-03-28 12:01 ` Michal Hocko
  2022-03-28 13:15   ` Miaohe Lin
  2022-03-28 14:16 ` David Hildenbrand
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Michal Hocko @ 2022-03-28 12:01 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: hannes, roman.gushchin, shakeelb, akpm, cgroups, linux-mm, linux-kernel

On Mon 28-03-22 19:41:44, Miaohe Lin wrote:
> The local variable nr_scanned is unneeded as mem_cgroup_soft_reclaim always
> does *total_scanned += nr_scanned. So we can pass total_scanned directly to
> the mem_cgroup_soft_reclaim to simplify the code and save some cpu cycles
> of adding nr_scanned to total_scanned.

Maybe the compiler could be clever enough to generate a good code.
mem_cgroup_soft_reclaim doesn't have other caller so it could be
inlined. But I do agree that the change makes sense because it makes the
code more consistent as mem_cgroup_soft_limit_reclaim already uses
total_scanned this way.

> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Acked-by: Michal Hocko <mhocko@suse.com>

Thanks

> ---
>  mm/memcontrol.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index b686ec4f42c6..79341365ec90 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3384,7 +3384,6 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
>  	int loop = 0;
>  	struct mem_cgroup_tree_per_node *mctz;
>  	unsigned long excess;
> -	unsigned long nr_scanned;
>  
>  	if (order > 0)
>  		return 0;
> @@ -3412,11 +3411,9 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
>  		if (!mz)
>  			break;
>  
> -		nr_scanned = 0;
>  		reclaimed = mem_cgroup_soft_reclaim(mz->memcg, pgdat,
> -						    gfp_mask, &nr_scanned);
> +						    gfp_mask, total_scanned);
>  		nr_reclaimed += reclaimed;
> -		*total_scanned += nr_scanned;
>  		spin_lock_irq(&mctz->lock);
>  		__mem_cgroup_remove_exceeded(mz, mctz);
>  
> -- 
> 2.23.0

-- 
Michal Hocko
SUSE Labs


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

* Re: [PATCH] mm/memcg: remove unneeded nr_scanned
  2022-03-28 12:01 ` Michal Hocko
@ 2022-03-28 13:15   ` Miaohe Lin
  0 siblings, 0 replies; 6+ messages in thread
From: Miaohe Lin @ 2022-03-28 13:15 UTC (permalink / raw)
  To: Michal Hocko
  Cc: hannes, roman.gushchin, shakeelb, akpm, cgroups, linux-mm, linux-kernel

On 2022/3/28 20:01, Michal Hocko wrote:
> On Mon 28-03-22 19:41:44, Miaohe Lin wrote:
>> The local variable nr_scanned is unneeded as mem_cgroup_soft_reclaim always
>> does *total_scanned += nr_scanned. So we can pass total_scanned directly to
>> the mem_cgroup_soft_reclaim to simplify the code and save some cpu cycles
>> of adding nr_scanned to total_scanned.
> 
> Maybe the compiler could be clever enough to generate a good code.
> mem_cgroup_soft_reclaim doesn't have other caller so it could be
> inlined. But I do agree that the change makes sense because it makes the
> code more consistent as mem_cgroup_soft_limit_reclaim already uses
> total_scanned this way.

Many thanks for your comment and Acked-by tag. :)

> 
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> 
> Acked-by: Michal Hocko <mhocko@suse.com>
> 
> Thanks
> 
>> ---
>>  mm/memcontrol.c | 5 +----
>>  1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index b686ec4f42c6..79341365ec90 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -3384,7 +3384,6 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
>>  	int loop = 0;
>>  	struct mem_cgroup_tree_per_node *mctz;
>>  	unsigned long excess;
>> -	unsigned long nr_scanned;
>>  
>>  	if (order > 0)
>>  		return 0;
>> @@ -3412,11 +3411,9 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
>>  		if (!mz)
>>  			break;
>>  
>> -		nr_scanned = 0;
>>  		reclaimed = mem_cgroup_soft_reclaim(mz->memcg, pgdat,
>> -						    gfp_mask, &nr_scanned);
>> +						    gfp_mask, total_scanned);
>>  		nr_reclaimed += reclaimed;
>> -		*total_scanned += nr_scanned;
>>  		spin_lock_irq(&mctz->lock);
>>  		__mem_cgroup_remove_exceeded(mz, mctz);
>>  
>> -- 
>> 2.23.0
> 



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

* Re: [PATCH] mm/memcg: remove unneeded nr_scanned
  2022-03-28 11:41 [PATCH] mm/memcg: remove unneeded nr_scanned Miaohe Lin
  2022-03-28 12:01 ` Michal Hocko
@ 2022-03-28 14:16 ` David Hildenbrand
  2022-03-28 18:36 ` Roman Gushchin
  2022-04-01  1:06 ` Wei Yang
  3 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2022-03-28 14:16 UTC (permalink / raw)
  To: Miaohe Lin, hannes, mhocko, roman.gushchin, shakeelb, akpm
  Cc: cgroups, linux-mm, linux-kernel

On 28.03.22 13:41, Miaohe Lin wrote:
> The local variable nr_scanned is unneeded as mem_cgroup_soft_reclaim always
> does *total_scanned += nr_scanned. So we can pass total_scanned directly to
> the mem_cgroup_soft_reclaim to simplify the code and save some cpu cycles
> of adding nr_scanned to total_scanned.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/memcontrol.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index b686ec4f42c6..79341365ec90 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3384,7 +3384,6 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
>  	int loop = 0;
>  	struct mem_cgroup_tree_per_node *mctz;
>  	unsigned long excess;
> -	unsigned long nr_scanned;
>  
>  	if (order > 0)
>  		return 0;
> @@ -3412,11 +3411,9 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
>  		if (!mz)
>  			break;
>  
> -		nr_scanned = 0;
>  		reclaimed = mem_cgroup_soft_reclaim(mz->memcg, pgdat,
> -						    gfp_mask, &nr_scanned);
> +						    gfp_mask, total_scanned);
>  		nr_reclaimed += reclaimed;
> -		*total_scanned += nr_scanned;
>  		spin_lock_irq(&mctz->lock);
>  		__mem_cgroup_remove_exceeded(mz, mctz);
>  

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb



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

* Re: [PATCH] mm/memcg: remove unneeded nr_scanned
  2022-03-28 11:41 [PATCH] mm/memcg: remove unneeded nr_scanned Miaohe Lin
  2022-03-28 12:01 ` Michal Hocko
  2022-03-28 14:16 ` David Hildenbrand
@ 2022-03-28 18:36 ` Roman Gushchin
  2022-04-01  1:06 ` Wei Yang
  3 siblings, 0 replies; 6+ messages in thread
From: Roman Gushchin @ 2022-03-28 18:36 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: hannes, mhocko, shakeelb, akpm, cgroups, linux-mm, linux-kernel

On Mon, Mar 28, 2022 at 07:41:44PM +0800, Miaohe Lin wrote:
> The local variable nr_scanned is unneeded as mem_cgroup_soft_reclaim always
> does *total_scanned += nr_scanned. So we can pass total_scanned directly to
> the mem_cgroup_soft_reclaim to simplify the code and save some cpu cycles
> of adding nr_scanned to total_scanned.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>

Thanks!


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

* Re: [PATCH] mm/memcg: remove unneeded nr_scanned
  2022-03-28 11:41 [PATCH] mm/memcg: remove unneeded nr_scanned Miaohe Lin
                   ` (2 preceding siblings ...)
  2022-03-28 18:36 ` Roman Gushchin
@ 2022-04-01  1:06 ` Wei Yang
  3 siblings, 0 replies; 6+ messages in thread
From: Wei Yang @ 2022-04-01  1:06 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: hannes, mhocko, roman.gushchin, shakeelb, akpm, cgroups,
	linux-mm, linux-kernel

On Mon, Mar 28, 2022 at 07:41:44PM +0800, Miaohe Lin wrote:
>The local variable nr_scanned is unneeded as mem_cgroup_soft_reclaim always
>does *total_scanned += nr_scanned. So we can pass total_scanned directly to
>the mem_cgroup_soft_reclaim to simplify the code and save some cpu cycles
>of adding nr_scanned to total_scanned.
>
>Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>---

Reviewed-by: Wei Yang <richard.weiyang@gmail.com>

Thanks

-- 
Wei Yang
Help you, Help me


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

end of thread, other threads:[~2022-04-01  1:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28 11:41 [PATCH] mm/memcg: remove unneeded nr_scanned Miaohe Lin
2022-03-28 12:01 ` Michal Hocko
2022-03-28 13:15   ` Miaohe Lin
2022-03-28 14:16 ` David Hildenbrand
2022-03-28 18:36 ` Roman Gushchin
2022-04-01  1:06 ` Wei Yang

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).