Re: [PATCH] mm: Add AnonZero accounting for zero-filled anonymous pages

From: David Hildenbrand (Arm)

Date: Mon Feb 16 2026 - 07:16:38 EST


On 2/14/26 09:45, Wenchao Hao wrote:
Add kernel command line option "count_zero_page" to track anonymous pages
have been allocated and mapped to userspace but zero-filled.

"count_zero_page" is rather sub-optimal parameter name. "anonzero_in_smaps" or sth like that?

Still wondering if there could be a better way to enable this dynamically.

In particular, not using a core parameter.

If you use a module parameter, you can just set on the cmdline

proc.anonzero_in_smaps=1

And dynamically set/observe it in

/sys/module/proc/parameters/anonzero_in_smaps


diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index d7d52e259055..0301b9cd28f8 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -34,6 +34,10 @@
#define SEQ_PUT_DEC(str, val) \
seq_put_decimal_ull_width(m, str, (val) << (PAGE_SHIFT-10), 8)
+
+static bool anonzero_in_smaps;
+module_param(anonzero_in_smaps, bool, 0644);
+
void task_mem(struct seq_file *m, struct mm_struct *mm)
{
unsigned long text, lib, swap, anon, file, shmem;



This feature is mainly used to debug large folio mechanism, which
pre-allocates and map more pages than actually needed, leading to memory
waste from unaccessed pages.

Export the result in /proc/pid/smaps as "AnonZero" field.

Link: https://lore.kernel.org/linux-mm/20260210043456.2137482-1-haowenchao22@xxxxxxxxx/
Signed-off-by: Wenchao Hao <haowenchao22@xxxxxxxxx>
---
Documentation/filesystems/proc.rst | 5 +++++
fs/proc/task_mmu.c | 10 ++++++++++
2 files changed, 15 insertions(+)

diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index b0c0d1b45b99..573c8b015e39 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -545,6 +545,11 @@ replaced by copy-on-write) part of the underlying shmem object out on swap.
does not take into account swapped out page of underlying shmem objects.
"Locked" indicates whether the mapping is locked in memory or not.
+"AnonZero" shows the size of anonymous pages that have never been accessed
+after mapping, and it can reflect the memory waste caused by huge pages.

That's not correct. They could be read/written, but with zeroes.

+Implemented by scanning the size of zero-filled pages of the VMA. It
+is default disabled, and enabled via cmdline param "count_zero_page=true".

Probably best to keep it simpler:

"AnonZero" shows the size of anonymous pages that contain zeroes. Zero-filled
pages can indicate memory waste caused by memory-overallocation with (m)THPs.
Availability is controlled through XYZ.

--
Cheers,

David