cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool
@ 2024-05-07 11:08 Xiu Jianfeng
  2024-05-07 13:10 ` Michal Hocko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Xiu Jianfeng @ 2024-05-07 11:08 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, akpm
  Cc: cgroups, linux-mm, linux-kernel

Currently alloc_mem_cgroup_per_node_info() returns 1 if failed,
make it return bool, false for failure and true for success.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 mm/memcontrol.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d11536ef59ef..69d70feb8e68 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5653,13 +5653,13 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino)
 }
 #endif
 
-static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
+static bool alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 {
 	struct mem_cgroup_per_node *pn;
 
 	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
 	if (!pn)
-		return 1;
+		return false;
 
 	pn->lruvec_stats = kzalloc_node(sizeof(struct lruvec_stats), GFP_KERNEL,
 					node);
@@ -5675,11 +5675,11 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 	pn->memcg = memcg;
 
 	memcg->nodeinfo[node] = pn;
-	return 0;
+	return true;
 fail:
 	kfree(pn->lruvec_stats);
 	kfree(pn);
-	return 1;
+	return false;
 }
 
 static void free_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
@@ -5751,7 +5751,7 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
 	}
 
 	for_each_node(node)
-		if (alloc_mem_cgroup_per_node_info(memcg, node))
+		if (!alloc_mem_cgroup_per_node_info(memcg, node))
 			goto fail;
 
 	if (memcg_wb_domain_init(memcg, GFP_KERNEL))
-- 
2.34.1


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

* Re: [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool
  2024-05-07 11:08 [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool Xiu Jianfeng
@ 2024-05-07 13:10 ` Michal Hocko
  2024-05-07 13:31   ` xiujianfeng
  2024-05-07 16:09 ` Roman Gushchin
  2024-05-09 14:05 ` Johannes Weiner
  2 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2024-05-07 13:10 UTC (permalink / raw)
  To: Xiu Jianfeng
  Cc: hannes, roman.gushchin, shakeel.butt, muchun.song, akpm, cgroups,
	linux-mm, linux-kernel

On Tue 07-05-24 11:08:32, Xiu Jianfeng wrote:
> Currently alloc_mem_cgroup_per_node_info() returns 1 if failed,
> make it return bool, false for failure and true for success.

This describes what the patch does rather than why it is doing that.
The former is clear from the diff while the motivation for this change
is unclear. I would propose something like:

alloc_mem_cgroup_per_node_info() returns int that doesn't map to any
errno error code. The only existing caller doesn't really need an error
code so change the the function to return bool (true on success) because
this is slightly less confusing and more consistent with the other code.

> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>

With changelog clarified feel free to add
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/memcontrol.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index d11536ef59ef..69d70feb8e68 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5653,13 +5653,13 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino)
>  }
>  #endif
>  
> -static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
> +static bool alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
>  {
>  	struct mem_cgroup_per_node *pn;
>  
>  	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
>  	if (!pn)
> -		return 1;
> +		return false;
>  
>  	pn->lruvec_stats = kzalloc_node(sizeof(struct lruvec_stats), GFP_KERNEL,
>  					node);
> @@ -5675,11 +5675,11 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
>  	pn->memcg = memcg;
>  
>  	memcg->nodeinfo[node] = pn;
> -	return 0;
> +	return true;
>  fail:
>  	kfree(pn->lruvec_stats);
>  	kfree(pn);
> -	return 1;
> +	return false;
>  }
>  
>  static void free_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
> @@ -5751,7 +5751,7 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
>  	}
>  
>  	for_each_node(node)
> -		if (alloc_mem_cgroup_per_node_info(memcg, node))
> +		if (!alloc_mem_cgroup_per_node_info(memcg, node))
>  			goto fail;
>  
>  	if (memcg_wb_domain_init(memcg, GFP_KERNEL))
> -- 
> 2.34.1
> 

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool
  2024-05-07 13:10 ` Michal Hocko
@ 2024-05-07 13:31   ` xiujianfeng
  0 siblings, 0 replies; 5+ messages in thread
From: xiujianfeng @ 2024-05-07 13:31 UTC (permalink / raw)
  To: Michal Hocko
  Cc: hannes, roman.gushchin, shakeel.butt, muchun.song, akpm, cgroups,
	linux-mm, linux-kernel



On 2024/5/7 21:10, Michal Hocko wrote:
> On Tue 07-05-24 11:08:32, Xiu Jianfeng wrote:
>> Currently alloc_mem_cgroup_per_node_info() returns 1 if failed,
>> make it return bool, false for failure and true for success.
> 
> This describes what the patch does rather than why it is doing that.
> The former is clear from the diff while the motivation for this change
> is unclear. I would propose something like:
> 
> alloc_mem_cgroup_per_node_info() returns int that doesn't map to any
> errno error code. The only existing caller doesn't really need an error
> code so change the the function to return bool (true on success) because
> this is slightly less confusing and more consistent with the other code.

Thanks, it looks much better now.

> 
>> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> 
> With changelog clarified feel free to add
> Acked-by: Michal Hocko <mhocko@suse.com>
> 
>> ---
>>  mm/memcontrol.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index d11536ef59ef..69d70feb8e68 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -5653,13 +5653,13 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino)
>>  }
>>  #endif
>>  
>> -static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
>> +static bool alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
>>  {
>>  	struct mem_cgroup_per_node *pn;
>>  
>>  	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
>>  	if (!pn)
>> -		return 1;
>> +		return false;
>>  
>>  	pn->lruvec_stats = kzalloc_node(sizeof(struct lruvec_stats), GFP_KERNEL,
>>  					node);
>> @@ -5675,11 +5675,11 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
>>  	pn->memcg = memcg;
>>  
>>  	memcg->nodeinfo[node] = pn;
>> -	return 0;
>> +	return true;
>>  fail:
>>  	kfree(pn->lruvec_stats);
>>  	kfree(pn);
>> -	return 1;
>> +	return false;
>>  }
>>  
>>  static void free_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
>> @@ -5751,7 +5751,7 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
>>  	}
>>  
>>  	for_each_node(node)
>> -		if (alloc_mem_cgroup_per_node_info(memcg, node))
>> +		if (!alloc_mem_cgroup_per_node_info(memcg, node))
>>  			goto fail;
>>  
>>  	if (memcg_wb_domain_init(memcg, GFP_KERNEL))
>> -- 
>> 2.34.1
>>
> 

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

* Re: [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool
  2024-05-07 11:08 [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool Xiu Jianfeng
  2024-05-07 13:10 ` Michal Hocko
@ 2024-05-07 16:09 ` Roman Gushchin
  2024-05-09 14:05 ` Johannes Weiner
  2 siblings, 0 replies; 5+ messages in thread
From: Roman Gushchin @ 2024-05-07 16:09 UTC (permalink / raw)
  To: Xiu Jianfeng
  Cc: hannes, mhocko, shakeel.butt, muchun.song, akpm, cgroups,
	linux-mm, linux-kernel

On Tue, May 07, 2024 at 11:08:32AM +0000, Xiu Jianfeng wrote:
> Currently alloc_mem_cgroup_per_node_info() returns 1 if failed,
> make it return bool, false for failure and true for success.
> 
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>

I actually liked the previous (ENOMEM) version slightly more,
but this one works too.

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

Thanks!

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

* Re: [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool
  2024-05-07 11:08 [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool Xiu Jianfeng
  2024-05-07 13:10 ` Michal Hocko
  2024-05-07 16:09 ` Roman Gushchin
@ 2024-05-09 14:05 ` Johannes Weiner
  2 siblings, 0 replies; 5+ messages in thread
From: Johannes Weiner @ 2024-05-09 14:05 UTC (permalink / raw)
  To: Xiu Jianfeng
  Cc: mhocko, roman.gushchin, shakeel.butt, muchun.song, akpm, cgroups,
	linux-mm, linux-kernel

On Tue, May 07, 2024 at 11:08:32AM +0000, Xiu Jianfeng wrote:
> Currently alloc_mem_cgroup_per_node_info() returns 1 if failed,
> make it return bool, false for failure and true for success.
> 
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>

I also slightly preferred the -ENOMEM version. But this is better than
the status quo.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

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

end of thread, other threads:[~2024-05-09 14:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 11:08 [PATCH v2 -next] mm: memcg: make alloc_mem_cgroup_per_node_info() return bool Xiu Jianfeng
2024-05-07 13:10 ` Michal Hocko
2024-05-07 13:31   ` xiujianfeng
2024-05-07 16:09 ` Roman Gushchin
2024-05-09 14:05 ` Johannes Weiner

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