From: Wei Yang Date: Thu, 14 Apr 2022 06:07:04 +0000 (-0700) Subject: mm/memcg: set memcg after css verified and got reference X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5e1ad4c4c6a481bdd8ec1550af155cbcb41b481e;p=users%2Fjedix%2Flinux-maple.git mm/memcg: set memcg after css verified and got reference Patch series "mm/memcg: some cleanup for mem_cgroup_iter()", v2. No functional change, try to make it more readable. This patch (of 3): Instead of resetting 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. Link: https://lkml.kernel.org/r/20220330234719.18340-1-richard.weiyang@gmail.com Link: https://lkml.kernel.org/r/20220330234719.18340-2-richard.weiyang@gmail.com Signed-off-by: Wei Yang Acked-by: Johannes Weiner Reviewed-by: Roman Gushchin Cc: Michal Hocko Cc: Shakeel Butt Signed-off-by: Andrew Morton --- diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 84ebec1bd39cf..4610712fb11d4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1066,15 +1066,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) {