linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memcg: bail out early when !memcg in mem_cgroup_lruvec
@ 2020-11-27  3:08 Alex Shi
  2020-11-28  4:02 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Shi @ 2020-11-27  3:08 UTC (permalink / raw)
  Cc: Andrew Morton, Johannes Weiner, Shakeel Butt, Roman Gushchin,
	Lorenzo Stoakes, Stephen Rothwell, Alexander Duyck, Yafang Shao,
	Wei Yang, linux-kernel

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.shi@linux.alibaba.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Cc: Yafang Shao <laoar.shao@gmail.com>
Cc: Wei Yang <richard.weiyang@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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-30 20:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-27  3:08 [PATCH] mm/memcg: bail out early when !memcg in mem_cgroup_lruvec Alex Shi
2020-11-28  4:02 ` Andrew Morton
2020-11-29  4:43   ` Alex Shi
2020-11-30 19:44     ` Dmitry Osipenko
2020-11-30 20:19       ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).