diff mbox series

[2/2] mm: vmpressure: use mem_cgroup_is_root API

Message ID 1581398649-125989-2-git-send-email-yang.shi@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series [1/2] mm: vmpressure: don't need call kfree if kstrndup fails | expand

Commit Message

Yang Shi Feb. 11, 2020, 5:24 a.m. UTC
Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
open coding.

Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
 mm/vmpressure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Rientjes Feb. 12, 2020, 2:08 a.m. UTC | #1
On Tue, 11 Feb 2020, Yang Shi wrote:

> Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
> open coding.
> 
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>

Acked-by: David Rientjes <rientjes@google.com>
Michal Hocko Feb. 12, 2020, 8:23 a.m. UTC | #2
On Tue 11-02-20 13:24:09, Yang Shi wrote:
> Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
> open coding.

Yes, the direct use outside of memcontrol.c should be really an
exception. The only other similar case is cgwb_bdi_init and there is no
easy way to replace - except for adding a helper which is not worth it.

> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>

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

Thanks!

> ---
>  mm/vmpressure.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 0590f00..d69019f 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
>  		enum vmpressure_levels level;
>  
>  		/* For now, no users for root-level efficiency */
> -		if (!memcg || memcg == root_mem_cgroup)
> +		if (!memcg || mem_cgroup_is_root(memcg))
>  			return;
>  
>  		spin_lock(&vmpr->sr_lock);
> -- 
> 1.8.3.1
>
David Hildenbrand Feb. 12, 2020, 11:19 a.m. UTC | #3
On 11.02.20 06:24, Yang Shi wrote:
> Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
> open coding.
> 
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> ---
>  mm/vmpressure.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 0590f00..d69019f 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
>  		enum vmpressure_levels level;
>  
>  		/* For now, no users for root-level efficiency */
> -		if (!memcg || memcg == root_mem_cgroup)
> +		if (!memcg || mem_cgroup_is_root(memcg))
>  			return;
>  
>  		spin_lock(&vmpr->sr_lock);
> 

Reviewed-by: David Hildenbrand <david@redhat.com>
Yang Shi Feb. 13, 2020, 3:18 a.m. UTC | #4
On 2/12/20 12:23 AM, Michal Hocko wrote:
> On Tue 11-02-20 13:24:09, Yang Shi wrote:
>> Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
>> open coding.
> Yes, the direct use outside of memcontrol.c should be really an
> exception. The only other similar case is cgwb_bdi_init and there is no
> easy way to replace - except for adding a helper which is not worth it.

Yes, it seems so. cgwb_bdi_init just deferences root_mem_cgroup to 
access its css. It is the only user outside memcontrol.c, so I agree a 
helper for it might be overkilling. Once we have more users, it should 
be considered.

>
>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> Acked-by: Michal Hocko <mhocko@suse.com>

Thanks.

>
> Thanks!
>
>> ---
>>   mm/vmpressure.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
>> index 0590f00..d69019f 100644
>> --- a/mm/vmpressure.c
>> +++ b/mm/vmpressure.c
>> @@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
>>   		enum vmpressure_levels level;
>>   
>>   		/* For now, no users for root-level efficiency */
>> -		if (!memcg || memcg == root_mem_cgroup)
>> +		if (!memcg || mem_cgroup_is_root(memcg))
>>   			return;
>>   
>>   		spin_lock(&vmpr->sr_lock);
>> -- 
>> 1.8.3.1
>>
diff mbox series

Patch

diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 0590f00..d69019f 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -280,7 +280,7 @@  void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
 		enum vmpressure_levels level;
 
 		/* For now, no users for root-level efficiency */
-		if (!memcg || memcg == root_mem_cgroup)
+		if (!memcg || mem_cgroup_is_root(memcg))
 			return;
 
 		spin_lock(&vmpr->sr_lock);