diff mbox series

[1/2] mm: make lru_gen_eviction() to handle folios without memcg info

Message ID e1036b9cc8928be9a7dec150ab3a0317bd7180cf.1720572937.git.wqu@suse.com (mailing list archive)
State New
Headers show
Series mm: skip memcg for certain address space | expand

Commit Message

Qu Wenruo July 10, 2024, 1:07 a.m. UTC
Currently lru_gen_eviction() fully relies on folio_memcg() to grab the
memcg.
It's fine for now as only file folios can enter workingset_eviction().

But for the incoming change which will skip memcg for certain address
space, we will hit folios without an memcg info in the future.

In that case, mem_cgroup_id() would lead to NULL pointer dereference.
Enhance lru_gen_eviction() to handle such situatioin by calling
lruvec_memcg() instead of using folio_memcg() directly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 mm/workingset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mm/workingset.c b/mm/workingset.c
index c22adb93622a..449042d10803 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -253,7 +253,7 @@  static void *lru_gen_eviction(struct folio *folio)
 	hist = lru_hist_from_seq(min_seq);
 	atomic_long_add(delta, &lrugen->evicted[hist][type][tier]);
 
-	return pack_shadow(mem_cgroup_id(memcg), pgdat, token, refs);
+	return pack_shadow(mem_cgroup_id(lruvec_memcg(lruvec)), pgdat, token, refs);
 }
 
 /*