Skip to content

Commit 681519b

Browse files
Muchun Songjfvogel
authored andcommitted
writeback: prevent memory cgroup release in writeback 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 function get_mem_cgroup_css_from_folio() and the rcu read lock are employed to safeguard against the release of the memory cgroup. This serves as a preparatory measure for the reparenting of the LRU pages. Signed-off-by: Muchun Song <[email protected]> Orabug: 37997580 Conflicts: include/trace/events/writeback.h mm/memcontrol.c fs/fs-writeback.c Most of the functions were already converted by the commit 4717687 ("mm: memcontrol: make all the callers of {folio,page}_memcg() safe"), mem_cgroup_track_foreign_dirty() was not converted. This suppresses the warning: WARNING: CPU: 0 PID: 638 at include/linux/memcontrol.h:407 folio_account_dirtied+0x2a8/0x2e0 [...] Call Trace: <TASK> __folio_mark_dirty+0x3e/0xb0 filemap_dirty_folio+0x61/0xa0 iomap_page_mkwrite+0x1c8/0x2f0 xfs_write_fault+0x1cc/0x2f0 [xfs] ? __xfs_filemap_fault+0x39/0x1a0 [xfs] do_page_mkwrite+0x45/0xf0 do_wp_page+0xe5/0x760 __handle_mm_fault+0x58f/0x770 handle_mm_fault+0xde/0x390 do_user_addr_fault+0x1b9/0x640 exc_page_fault+0x76/0x210 asm_exc_page_fault+0x26/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 9ffa045 commit 681519b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/linux/memcontrol.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,9 +1657,14 @@ static inline void mem_cgroup_track_foreign_dirty(struct folio *folio,
16571657
if (mem_cgroup_disabled())
16581658
return;
16591659

1660+
if (!folio_memcg_charged(folio))
1661+
return;
1662+
1663+
rcu_read_lock();
16601664
memcg = folio_memcg(folio);
1661-
if (unlikely(memcg && &memcg->css != wb->memcg_css))
1665+
if (unlikely(&memcg->css != wb->memcg_css))
16621666
mem_cgroup_track_foreign_dirty_slowpath(folio, wb);
1667+
rcu_read_unlock();
16631668
}
16641669

16651670
void mem_cgroup_flush_foreign(struct bdi_writeback *wb);

0 commit comments

Comments
 (0)