From: Hirotaka Yamagata <hiro@pisnp.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-api@vger.kernel.org, "Liam R. Howlett" <liam@infradead.org>,
Lorenzo Stoakes <ljs@kernel.org>,
David Hildenbrand <david@kernel.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
cgroups@vger.kernel.org, John Stultz <jstultz@google.com>,
Minchan Kim <minchan@kernel.org>,
Alexandre Marciano Gimenez <raging@google.com>,
Tatsuyuki Ishi <ishitatsuyuki@google.com>
Subject: [RFC PATCH v1 4/4] mm/volatile: add PGPURGE vmstat counter and purge tracepoint
Date: Mon, 30 Nov 2026 17:34:07 +0900 [thread overview]
Message-ID: <20261130083407.2669584-5-hiro@pisnp.net> (raw)
In-Reply-To: <20261130083407.2669584-1-hiro@pisnp.net>
Add accounting and a tracepoint for volatile folio purging:
- Add the PGPURGE ("pgpurge") vmstat and memcg event item counting the
pages discarded by purge_volatile_folio(). Pages are counted once
their mappings hold PTE_MARKER_PURGED markers and the swap cache is
gone, and are charged to the folio's memcg as well, so memory.stat
shows purges per cgroup.
- Add the mm_purge_volatile_folio tracepoint in
include/trace/events/vmscan.h recording the folio PFN, page count, and
whether the folio was purged or, being a large folio, left to swap.
Cc: John Stultz <jstultz@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Alexandre Marciano Gimenez <raging@google.com>
Cc: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Signed-off-by: Hirotaka Yamagata <hiro@pisnp.net>
---
include/linux/vm_event_item.h | 1 +
include/trace/events/vmscan.h | 24 ++++++++++++++++++++++++
mm/memcontrol.c | 1 +
mm/mvolatile.c | 20 ++++++++++++++++++--
mm/vmstat.c | 1 +
5 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 2628ccda076a..9832711eafa7 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -38,6 +38,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
PGFREE, PGACTIVATE, PGDEACTIVATE, PGLAZYFREE,
PGFAULT, PGMAJFAULT,
PGLAZYFREED,
+ PGPURGE,
PGREUSE,
PGSCAN_DIRECT_THROTTLE,
#ifdef CONFIG_NUMA
diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h
index b4bf7b8def1f..15e22b119914 100644
--- a/include/trace/events/vmscan.h
+++ b/include/trace/events/vmscan.h
@@ -429,6 +429,30 @@ TRACE_EVENT(mm_vmscan_write_folio,
show_reclaim_flags(__entry->reclaim_flags))
);
+TRACE_EVENT(mm_purge_volatile_folio,
+
+ TP_PROTO(struct folio *folio, bool purged),
+
+ TP_ARGS(folio, purged),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, pfn)
+ __field(unsigned long, nr_pages)
+ __field(bool, purged)
+ ),
+
+ TP_fast_assign(
+ __entry->pfn = folio_pfn(folio);
+ __entry->nr_pages = folio_nr_pages(folio);
+ __entry->purged = purged;
+ ),
+
+ TP_printk("pfn=0x%lx nr_pages=%lu purged=%d",
+ __entry->pfn,
+ __entry->nr_pages,
+ __entry->purged)
+);
+
TRACE_EVENT(mm_vmscan_reclaim_pages,
TP_PROTO(int nid,
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1271d390b617..d075920cdd2b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -608,6 +608,7 @@ static const unsigned int memcg_vm_event_stat[] = {
PGDEACTIVATE,
PGLAZYFREE,
PGLAZYFREED,
+ PGPURGE,
#ifdef CONFIG_SWAP
SWPIN_ZERO,
SWPOUT_ZERO,
diff --git a/mm/mvolatile.c b/mm/mvolatile.c
index c111bc4f111d..aa532d72d81c 100644
--- a/mm/mvolatile.c
+++ b/mm/mvolatile.c
@@ -15,6 +15,9 @@
#include <linux/swap.h>
#include <linux/swapops.h>
#include <linux/pagewalk.h>
+#include <linux/memcontrol.h>
+#include <linux/vmstat.h>
+#include <trace/events/vmscan.h>
#include "internal.h"
#include "vma.h"
@@ -261,9 +264,13 @@ enum purge_result __purge_volatile_folio(struct folio *folio)
if (!mapped)
return PURGE_NONE;
- /* Only order-0 folios are supported for now. */
+ /*
+ * Only order-0 folios are supported for now. Checked after the
+ * volatile test so that the tracepoint shows large volatile folios
+ * falling back to swap.
+ */
if (folio_test_large(folio))
- return PURGE_NONE;
+ goto fail;
try_to_unmap(folio, TTU_PURGE | TTU_SYNC);
@@ -280,6 +287,11 @@ enum purge_result __purge_volatile_folio(struct folio *folio)
if (folio_test_swapcache(folio) && !folio_free_swap(folio))
return PURGE_NONE;
+ /* Count before the freeze, so that a retry is not counted again. */
+ count_vm_events(PGPURGE, folio_nr_pages(folio));
+ count_memcg_folio_events(folio, PGPURGE, folio_nr_pages(folio));
+ trace_mm_purge_volatile_folio(folio, true);
+
freeze:
/*
* Like __remove_mapping(), back off on a transient reference. No new
@@ -292,4 +304,8 @@ enum purge_result __purge_volatile_folio(struct folio *folio)
folio_unlock(folio);
return PURGE_DONE;
+
+fail:
+ trace_mm_purge_volatile_folio(folio, false);
+ return PURGE_NONE;
}
diff --git a/mm/vmstat.c b/mm/vmstat.c
index cb57714539fb..c2d4be97e0b0 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1347,6 +1347,7 @@ const char * const vmstat_text[] = {
[I(PGFAULT)] = "pgfault",
[I(PGMAJFAULT)] = "pgmajfault",
[I(PGLAZYFREED)] = "pglazyfreed",
+ [I(PGPURGE)] = "pgpurge",
[I(PGREUSE)] = "pgreuse",
[I(PGSCAN_DIRECT_THROTTLE)] = "pgscan_direct_throttle",
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-30 8:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 8:34 [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1 Hirotaka Yamagata
2026-11-30 8:34 ` [RFC PATCH v1 1/4] mm: introduce VM_VOLATILE and MADV_VOLATILE/MADV_NONVOLATILE VMA handling Hirotaka Yamagata
2026-11-30 8:34 ` [RFC PATCH v1 2/4] mm: add PTE_MARKER_PURGED and TTU_PURGE for purged volatile pages Hirotaka Yamagata
2026-11-30 8:34 ` [RFC PATCH v1 3/4] mm/volatile: purge volatile anonymous folios during reclaim Hirotaka Yamagata
2026-11-30 8:34 ` Hirotaka Yamagata [this message]
2026-11-30 10:39 ` [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1 David Hildenbrand (Arm)
2026-11-30 18:18 ` Lorenzo Stoakes (ARM)
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=20261130083407.2669584-5-hiro@pisnp.net \
--to=hiro@pisnp.net \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=cgroups@vger.kernel.org \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=ishitatsuyuki@google.com \
--cc=jstultz@google.com \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mhocko@kernel.org \
--cc=minchan@kernel.org \
--cc=raging@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shakeel.butt@linux.dev \
/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
all inboxes | Powered by JetHome®