diff mbox series

[v2,1/3] mm/memcg: set memcg after css verified and got reference

Message ID 20220330234719.18340-2-richard.weiyang@gmail.com (mailing list archive)
State New
Headers show
Series mm/memcg: some cleanup for mem_cgroup_iter() | expand

Commit Message

Wei Yang March 30, 2022, 11:47 p.m. UTC
Instead of reset memcg when css is either not verified or not got
reference, we can set it after these process.

No functional change, just simplified the code a little.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
---
 mm/memcontrol.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Roman Gushchin March 31, 2022, 12:20 a.m. UTC | #1
On Wed, Mar 30, 2022 at 11:47:17PM +0000, Wei Yang wrote:
> Instead of reset memcg when css is either not verified or not got
> reference, we can set it after these process.
> 
> No functional change, just simplified the code a little.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>

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

Nice cleanup!

> ---
>  mm/memcontrol.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index dc193e83794d..eed9916cdce5 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1057,15 +1057,10 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
>  		 * is provided by the caller, so we know it's alive
>  		 * and kicking, and don't take an extra reference.
>  		 */
> -		memcg = mem_cgroup_from_css(css);
> -
> -		if (css == &root->css)
> -			break;
> -
> -		if (css_tryget(css))
> +		if (css == &root->css || css_tryget(css)) {
> +			memcg = mem_cgroup_from_css(css);
>  			break;
> -
> -		memcg = NULL;
> +		}
>  	}
>  
>  	if (reclaim) {
> -- 
> 2.33.1
> 
>
diff mbox series

Patch

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index dc193e83794d..eed9916cdce5 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1057,15 +1057,10 @@  struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
 		 * is provided by the caller, so we know it's alive
 		 * and kicking, and don't take an extra reference.
 		 */
-		memcg = mem_cgroup_from_css(css);
-
-		if (css == &root->css)
-			break;
-
-		if (css_tryget(css))
+		if (css == &root->css || css_tryget(css)) {
+			memcg = mem_cgroup_from_css(css);
 			break;
-
-		memcg = NULL;
+		}
 	}
 
 	if (reclaim) {