The previous patch provided support for deferred recharging of folios
when their memcgs go offline. This patch adds recharging hooks to
folio_mark_accessed() and folio_mark_dirty().
This should cover a variety of code paths where folios are accessed by
userspace.
The hook, folio_memcg_deferred_recharge() only checks if the folio is
charged to an offline memcg in the common fast path (i.e checks
folio->memcg_data). If yes, an asynchronous worker is queued to do the
actual work.
Signed-off-by: Yosry Ahmed <[email protected]>
---
mm/page-writeback.c | 2 ++
mm/swap.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index d3f42009bb70..a644530d98c7 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2785,6 +2785,8 @@ bool folio_mark_dirty(struct folio *folio)
{
struct address_space *mapping = folio_mapping(folio);
+ folio_memcg_deferred_recharge(folio);
+
if (likely(mapping)) {
/*
* readahead/folio_deactivate could remain
diff --git a/mm/swap.c b/mm/swap.c
index cd8f0150ba3a..296c0b87c967 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -457,6 +457,8 @@ static void folio_inc_refs(struct folio *folio)
*/
void folio_mark_accessed(struct folio *folio)
{
+ folio_memcg_deferred_recharge(folio);
+
if (lru_gen_enabled()) {
folio_inc_refs(folio);
return;
--
2.41.0.255.g8b1d071c50-goog