From: Boris Burkov <boris@bur.io>
To: akpm@linux-foundation.org
Cc: linux-btrfs@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, kernel-team@fb.com,
shakeel.butt@linux.dev, wqu@suse.com, willy@infradead.org,
mhocko@kernel.org, muchun.song@linux.dev,
roman.gushchin@linux.dev, hannes@cmpxchg.org
Subject: [PATCH v3 2/4] mm: add vmstat for cgroup uncharged pages
Date: Mon, 18 Aug 2025 17:36:54 -0700 [thread overview]
Message-ID: <04b3a5c9944d79072d752c85dac1294ca9bee183.1755562487.git.boris@bur.io> (raw)
In-Reply-To: <cover.1755562487.git.boris@bur.io>
Uncharged pages are tricky to track by their essential "uncharged"
nature. To maintain good accounting, introduce a vmstat counter tracking
all uncharged pages. Since this is only meaningful when cgroups are
configured, only expose the counter when CONFIG_MEMCG is set.
Confirmed that these work as expected at a high level by mounting a
btrfs using AS_UNCHARGED for metadata pages, and seeing the counter rise
with fs usage then go back to a minimal level after drop_caches and
finally down to 0 after unmounting the fs.
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Boris Burkov <boris@bur.io>
---
include/linux/mmzone.h | 3 +++
mm/filemap.c | 17 +++++++++++++++++
mm/vmstat.c | 3 +++
3 files changed, 23 insertions(+)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index fe13ad175fed..8166dadb6a33 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -259,6 +259,9 @@ enum node_stat_item {
NR_HUGETLB,
#endif
NR_BALLOON_PAGES,
+#ifdef CONFIG_MEMCG
+ NR_UNCHARGED_FILE_PAGES,
+#endif
NR_VM_NODE_STAT_ITEMS
};
diff --git a/mm/filemap.c b/mm/filemap.c
index 5004a2cfa0cc..514ccf7c8aa3 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -146,6 +146,19 @@ static void page_cache_delete(struct address_space *mapping,
mapping->nrpages -= nr;
}
+#ifdef CONFIG_MEMCG
+static void filemap_mod_uncharged_vmstat(struct folio *folio, int sign)
+{
+ long nr = folio_nr_pages(folio) * sign;
+
+ mod_node_page_state(folio_pgdat(folio), NR_UNCHARGED_FILE_PAGES, nr);
+}
+#else
+static void filemap_mod_uncharged_vmstat(struct folio *folio, int sign)
+{
+}
+#endif
+
static void filemap_unaccount_folio(struct address_space *mapping,
struct folio *folio)
{
@@ -190,6 +203,8 @@ static void filemap_unaccount_folio(struct address_space *mapping,
__lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr);
filemap_nr_thps_dec(mapping);
}
+ if (test_bit(AS_UNCHARGED, &folio->mapping->flags))
+ filemap_mod_uncharged_vmstat(folio, -1);
/*
* At this point folio must be either written or cleaned by
@@ -987,6 +1002,8 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio,
if (!(gfp & __GFP_WRITE) && shadow)
workingset_refault(folio, shadow);
folio_add_lru(folio);
+ if (!charge_mem_cgroup)
+ filemap_mod_uncharged_vmstat(folio, 1);
}
return ret;
}
diff --git a/mm/vmstat.c b/mm/vmstat.c
index e74f0b2a1021..135f7bab4de6 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1290,6 +1290,9 @@ const char * const vmstat_text[] = {
[I(NR_HUGETLB)] = "nr_hugetlb",
#endif
[I(NR_BALLOON_PAGES)] = "nr_balloon_pages",
+#ifdef CONFIG_MEMCG
+ [I(NR_UNCHARGED_FILE_PAGES)] = "nr_uncharged_file_pages",
+#endif
#undef I
/* system-wide enum vm_stat_item counters */
--
2.50.1
next prev parent reply other threads:[~2025-08-19 0:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-19 0:36 [PATCH v3 0/4] introduce uncharged file mapped folios Boris Burkov
2025-08-19 0:36 ` [PATCH v3 1/4] mm/filemap: add AS_UNCHARGED Boris Burkov
2025-08-19 2:46 ` Matthew Wilcox
2025-08-19 3:57 ` Boris Burkov
2025-08-20 22:06 ` Klara Modin
2025-08-20 22:22 ` Shakeel Butt
2025-08-20 22:52 ` Boris Burkov
2025-08-20 23:15 ` Klara Modin
2025-08-20 23:53 ` Shakeel Butt
2025-08-21 19:37 ` Shakeel Butt
2025-08-19 0:36 ` Boris Burkov [this message]
2025-08-19 2:50 ` [PATCH v3 2/4] mm: add vmstat for cgroup uncharged pages Matthew Wilcox
2025-08-19 4:05 ` Boris Burkov
2025-08-19 15:53 ` Shakeel Butt
2025-08-19 23:46 ` Matthew Wilcox
2025-08-20 1:25 ` Shakeel Butt
2025-08-20 13:19 ` Matthew Wilcox
2025-08-20 16:21 ` Shakeel Butt
2025-08-19 0:36 ` [PATCH v3 3/4] btrfs: set AS_UNCHARGED on the btree_inode Boris Burkov
2025-08-19 0:36 ` [PATCH v3 4/4] memcg: remove warning from folio_lruvec Boris Burkov
2025-08-19 2:41 ` Matthew Wilcox
2025-08-19 5:20 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=04b3a5c9944d79072d752c85dac1294ca9bee183.1755562487.git.boris@bur.io \
--to=boris@bur.io \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=willy@infradead.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox