Re: [PATCH] mm/memcontrol: expose anon and file reclaim statistics in memory.stat
From: Michal Hocko
Date: Thu Nov 26 2026 - 03:30:50 EST
On Tue 24-11-26 15:51:27, Xueyuan Chen wrote:
> The aggregate reclaim counters in memory.stat do not show how reclaim
> is split between the anonymous and file LRUs of a cgroup.
>
> Expose the existing per-memcg scan and steal counters by LRU type so
> userspace can measure reclaim balance and efficiency when evaluating
> reclaim policy. Report the same counters per node in memory.numa_stat.
> Both files report the counters in base pages.
We have found these stats quite useful when debugging issues at the
global level many times. So I think this is a useful addition to memcg
stats as well. Especially when we already collect the data so this is
purely a change to show the already available information.
> Signed-off-by: Xueyuan Chen <xueyuan.chen21@xxxxxxxxx>
Acked-by: Michal Hocko <mhocko@xxxxxxxx>
Thanks!
> ---
> Documentation/admin-guide/cgroup-v2.rst | 20 ++++++++++++++++++--
> mm/memcontrol.c | 8 ++++++++
> 2 files changed, 26 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
> index 9e3c67b02ae2..eeeaf635754c 100644
> --- a/Documentation/admin-guide/cgroup-v2.rst
> +++ b/Documentation/admin-guide/cgroup-v2.rst
> @@ -1726,6 +1726,22 @@ The following nested keys are defined.
> pgsteal_proactive (npn)
> Amount of reclaimed pages proactively
>
> + pgscan_anon
> + Number of base pages scanned for reclaim from the anonymous
> + LRU. With the multi-gen LRU, counts pages isolated for reclaim.
> +
> + pgscan_file
> + Number of base pages scanned for reclaim from the file LRU.
> + With the multi-gen LRU, counts pages isolated for reclaim.
> +
> + pgsteal_anon
> + Number of base pages reclaimed from the anonymous LRU,
> + including pages demoted to another node.
> +
> + pgsteal_file
> + Number of base pages reclaimed from the file LRU,
> + including pages demoted to another node.
> +
> pgfault (npn)
> Total number of page faults incurred
>
> @@ -1829,11 +1845,11 @@ The following nested keys are defined.
> application performance by combining this information with the
> application's CPU allocation.
>
> - All memory amounts are in bytes.
> + All memory amounts are in bytes. Reclaim counters are in base pages.
>
> The output format of memory.numa_stat is::
>
> - type N0=<bytes in node 0> N1=<bytes in node 1> ...
> + type N0=<value for node 0> N1=<value for node 1> ...
>
> The entries are ordered to be human readable, and new entries
> can show up in the middle. Don't rely on items remaining in a
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 1ebc9330aeae..ac12ff69a633 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1647,10 +1647,14 @@ static const struct memory_stat memory_stats[] = {
> { "pgsteal_direct", PGSTEAL_DIRECT },
> { "pgsteal_khugepaged", PGSTEAL_KHUGEPAGED },
> { "pgsteal_proactive", PGSTEAL_PROACTIVE },
> + { "pgsteal_anon", PGSTEAL_ANON },
> + { "pgsteal_file", PGSTEAL_FILE },
> { "pgscan_kswapd", PGSCAN_KSWAPD },
> { "pgscan_direct", PGSCAN_DIRECT },
> { "pgscan_khugepaged", PGSCAN_KHUGEPAGED },
> { "pgscan_proactive", PGSCAN_PROACTIVE },
> + { "pgscan_anon", PGSCAN_ANON },
> + { "pgscan_file", PGSCAN_FILE },
> { "pgrefill", PGREFILL },
> #ifdef CONFIG_NUMA_BALANCING
> { "pgpromote_success", PGPROMOTE_SUCCESS },
> @@ -1699,10 +1703,14 @@ static int memcg_page_state_output_unit(int item)
> case PGSTEAL_DIRECT:
> case PGSTEAL_KHUGEPAGED:
> case PGSTEAL_PROACTIVE:
> + case PGSTEAL_ANON:
> + case PGSTEAL_FILE:
> case PGSCAN_KSWAPD:
> case PGSCAN_DIRECT:
> case PGSCAN_KHUGEPAGED:
> case PGSCAN_PROACTIVE:
> + case PGSCAN_ANON:
> + case PGSCAN_FILE:
> case PGREFILL:
> #ifdef CONFIG_NUMA_BALANCING
> case PGPROMOTE_SUCCESS:
>
> ---
> base-commit: b024a51b0184b1efb6f55b11aaf7b15a490a6307
>
> --
> Best regards,
> Xueyuan
>
--
Michal Hocko
SUSE Labs