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@xxxxxxxx> --- mm/workingset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } /* -- 2.45.2