diff mbox series

mm: memcontrol: Don't css_get() on root_mem_cgroup in get_mem_cgroup_from_mm()

Message ID 20231012161504.3445042-1-longman@redhat.com (mailing list archive)
State New
Headers show
Series mm: memcontrol: Don't css_get() on root_mem_cgroup in get_mem_cgroup_from_mm() | expand

Commit Message

Waiman Long Oct. 12, 2023, 4:15 p.m. UTC
As reference counting in the root memcg is disabled, there is no need
to get a reference if root memcg is to be returned.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 mm/memcontrol.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michal Hocko Oct. 13, 2023, 2:17 p.m. UTC | #1
On Thu 12-10-23 12:15:04, Waiman Long wrote:
> As reference counting in the root memcg is disabled, there is no need
> to get a reference if root memcg is to be returned.

Does this give any measurable wins?
 
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  mm/memcontrol.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 5b009b233ab8..2b3864194042 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1060,8 +1060,10 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
>  	rcu_read_lock();
>  	do {
>  		memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
> -		if (unlikely(!memcg))
> +		if (unlikely(!memcg)) {
>  			memcg = root_mem_cgroup;
> +			break;
> +		}
>  	} while (!css_tryget(&memcg->css));
>  	rcu_read_unlock();
>  	return memcg;
> -- 
> 2.39.3
diff mbox series

Patch

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5b009b233ab8..2b3864194042 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1060,8 +1060,10 @@  struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
 	rcu_read_lock();
 	do {
 		memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-		if (unlikely(!memcg))
+		if (unlikely(!memcg)) {
 			memcg = root_mem_cgroup;
+			break;
+		}
 	} while (!css_tryget(&memcg->css));
 	rcu_read_unlock();
 	return memcg;