Re: [PATCH] mm: Add AnonZero accounting for zero-filled anonymous pages
From: Wenchao Hao
Date: Tue Feb 17 2026 - 10:22:40 EST
On Sat, Feb 14, 2026 at 4:45 PM Wenchao Hao <haowenchao22@xxxxxxxxx> wrote:
>
> Add kernel command line option "count_zero_page" to track anonymous pages
> have been allocated and mapped to userspace but zero-filled.
>
> 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/
Sorry for the late reply. We are now on Chinese New Year holiday, so...
The original goal of this patch is to measure memory waste from anonymous
THPs - pages pre-allocated on fault but never accessed.
On memory-sensitive devices like mobile phones, this helps us make better
decisions about when and how to enable THP. I think this is useful for
guiding THP policies, even as a debugging feature.
Let me summarize the discussion so far:
- Matthew Wilcox questioned the value and raised concerns fork but haven't
exec path
- Michal Hocko criticized the inefficiency of scanning zero-filled pages.
- Kiryl Shutsemau prefers a system-call-based interface.
- David Hildenbrand acknowledged the value and suggested implementation
improvements.
Please correct me if I missed or misrepresented anything.
I suggest we first agree whether this functionality is useful for upstream,
before discussing implementation details.
Reasons why this should go upstream from me:
- Anonymous THP can introduce real memory waste, but we currently have no
good way to measure it.
- With accurate metrics, we can make better THP policy: disable for
low-utilization cases, or early-unmap to relieve memory pressure and so
on. This is especially valuable for mobile/embedded devices.
Possible implementations:
1. A new smaps counter (default-off) to count zero-filled pages.
2. A new madvise command like MADV_GET_ZEROPAGE
3. A dedicated system call
I welcome feedback on whether this is useful, and any better approaches.
Thank you.