Skip to content

Commit adfd07a

Browse files
Muchun Songjfvogel
authored andcommitted
mm: page_io: prevent memory cgroup release in page_io module
In the near future, a folio will no longer pin its corresponding memory cgroup. To ensure safety, it will only be appropriate to hold the rcu read lock or acquire a reference to the memory cgroup returned by folio_memcg(), thereby preventing it from being released. In the current patch, the rcu read lock is employed to safeguard against the release of the memory cgroup in swap_writepage() and bio_associate_blkg_from_page(). This serves as a preparatory measure for the reparenting of the LRU pages. Signed-off-by: Muchun Song <[email protected]> Orabug: 37997580 Conflicts: mm/page_io.c While converting bio_associate_blkg_from_page() was converted in the commit 4717687 ("mm: memcontrol: make all the callers of {folio,page}_memcg() safe"), swap_writepage() was not converted. This suppresses the warning: WARNING: CPU: 0 PID: 56 at include/linux/memcontrol.h:407 swap_writepage+0x255/0x280 [...] Call Trace: <TASK> pageout+0x163/0x370 shrink_folio_list+0x7c6/0x10a0 shrink_inactive_list+0x185/0x4f0 shrink_lruvec+0x3a0/0x4b0 ? __lock_release.isra.0+0x66/0x180 ? percpu_ref_put_many.constprop.0+0x5d/0x110 shrink_node_memcgs+0x1db/0x270 shrink_node+0x11d/0x420 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_acquire+0x107/0x140 ? balance_pgdat+0x30f/0x750 balance_pgdat+0x28d/0x750 kswapd+0xf8/0x1d0 ? __pfx_kswapd+0x10/0x10 kthread+0xd6/0x110 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x34/0x50 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Link: https://lore.kernel.org/linux-mm/[email protected]/ Fixes: 4717687 ("mm: memcontrol: make all the callers of {folio,page}_memcg() safe") Reviewed-by: Imran Khan <[email protected]> Signed-off-by: Harry Yoo <[email protected]>
1 parent 0f240e5 commit adfd07a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/page_io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,14 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
280280
folio_unlock(folio);
281281
return 0;
282282
}
283+
284+
rcu_read_lock();
283285
if (!mem_cgroup_zswap_writeback_enabled(folio_memcg(folio))) {
286+
rcu_read_unlock();
284287
folio_mark_dirty(folio);
285288
return AOP_WRITEPAGE_ACTIVATE;
286289
}
290+
rcu_read_unlock();
287291

288292
__swap_writepage(folio, wbc);
289293
return 0;

0 commit comments

Comments
 (0)