Re: [PATCH v7 1/3] mm/vmstat: Use per cpu variable to track a vmstat discrepancy

From: Andrew Morton
Date: Wed Aug 24 2022 - 16:21:02 EST


On Wed, 17 Aug 2022 16:13:47 -0300 Marcelo Tosatti <mtosatti@xxxxxxxxxx> wrote:

> From: Aaron Tomlin <atomlin@xxxxxxxxxx>
>
> Add CPU-specific variable namely vmstat_dirty to indicate if
> a vmstat imbalance is present for a given CPU. Therefore, at the
> appropriate time, we can fold all the remaining differentials.
>
> This speeds up quiet_vmstat in case no per-CPU differentials exist.
>
> Based on
> https://lore.kernel.org/lkml/20220204173554.763888172@fedora.localdomain/
>
> Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxx>
> Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
>
> ---
> mm/vmstat.c | 54 ++++++++++++++++++++----------------------------------
> 1 file changed, 20 insertions(+), 34 deletions(-)
>
> Index: linux-2.6/mm/vmstat.c
> ===================================================================
> --- linux-2.6.orig/mm/vmstat.c
> +++ linux-2.6/mm/vmstat.c
> @@ -195,6 +195,12 @@ void fold_vm_numa_events(void)
> #endif
>
> #ifdef CONFIG_SMP
> +static DEFINE_PER_CPU_ALIGNED(bool, vmstat_dirty);
> +
> +static inline void mark_vmstat_dirty(void)
> +{
> + this_cpu_write(vmstat_dirty, true);
> +}

If we're to have a helper for this then how about helpers for clearing
it and reading it?

Also, vmstat_mark_dirty(), vmstat_clear_dirty() and vmstat_dirty()
would be better identifiers.

Then those helper functions become good sites for comments explaining
what's going on.