Sometime, we use NULL memcg in mem_cgroup_lruvec(memcg, pgdat)
so we could get out early in the situation to avoid useless checking.

Also warning if both parameter are NULL.

Signed-off-by: Alex Shi <alex....@linux.alibaba.com>
Cc: Andrew Morton <a...@linux-foundation.org>
Cc: Johannes Weiner <han...@cmpxchg.org>
Cc: Shakeel Butt <shake...@google.com>
Cc: Roman Gushchin <g...@fb.com>
Cc: Lorenzo Stoakes <lstoa...@gmail.com>
Cc: Stephen Rothwell <s...@canb.auug.org.au>
Cc: Alexander Duyck <alexander.h.du...@linux.intel.com>
Cc: Yafang Shao <laoar.s...@gmail.com>
Cc: Wei Yang <richard.weiy...@gmail.com>
Cc: linux-kernel@vger.kernel.org
---
 include/linux/memcontrol.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 3e6a1df3bdb9..4cdb110f84e0 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -613,14 +613,13 @@ static inline struct lruvec *mem_cgroup_lruvec(struct 
mem_cgroup *memcg,
        struct mem_cgroup_per_node *mz;
        struct lruvec *lruvec;
 
-       if (mem_cgroup_disabled()) {
+       VM_WARN_ON_ONCE(!memcg && !pgdat);
+
+       if (mem_cgroup_disabled() || !memcg) {
                lruvec = &pgdat->__lruvec;
                goto out;
        }
 
-       if (!memcg)
-               memcg = root_mem_cgroup;
-
        mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
        lruvec = &mz->lruvec;
 out:
-- 
2.29.GIT

Reply via email to