diff mbox series

[v13,1/6] mm/vmstat: Add CPU-specific variable to track a vmstat discrepancy

Message ID 20230105125248.772766288@redhat.com (mailing list archive)
State New
Headers show
Series Ensure quiet_vmstat() is called when returning to userpace and when idle tick is stopped | expand

Commit Message

Marcelo Tosatti Jan. 5, 2023, 12:52 p.m. UTC
From: Aaron Tomlin <atomlin@atomlin.com>

Introduce a 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 patch also provides trivial helpers for modification and testing.

Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 mm/vmstat.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Christoph Lameter Jan. 10, 2023, 11:58 a.m. UTC | #1
On Thu, 5 Jan 2023, Marcelo Tosatti wrote:

> +static inline void vmstat_mark_dirty(void)
> +{
> +	this_cpu_write(vmstat_dirty, true);
> +}

this_cpu_write() is intended for an per cpu atomic context. You are not
using it in that way. The processor may have changed before or after and
thus vmstat_dirty for another CPU may  have been marked dirty.

I guess this would have to be called __vmstat_mark_dirty() and be using
__this_cpu_write(*) with a requirement that preemption be disabled before
using this function.

> +static inline void vmstat_clear_dirty(void)
> +{
> +	this_cpu_write(vmstat_dirty, false);
> +}

Same

> +static inline bool is_vmstat_dirty(void)
> +{
> +	return this_cpu_read(vmstat_dirty);
> +}

This function would only work correctly if preemption is disabled.
Otherwise the processor may change.
Frederic Weisbecker Jan. 10, 2023, 12:12 p.m. UTC | #2
On Tue, Jan 10, 2023 at 12:58:32PM +0100, Christoph Lameter wrote:
> On Thu, 5 Jan 2023, Marcelo Tosatti wrote:
> 
> > +static inline void vmstat_mark_dirty(void)
> > +{
> > +	this_cpu_write(vmstat_dirty, true);
> > +}
> 
> this_cpu_write() is intended for an per cpu atomic context. You are not
> using it in that way. The processor may have changed before or after and
> thus vmstat_dirty for another CPU may  have been marked dirty.
> 
> I guess this would have to be called __vmstat_mark_dirty() and be using
> __this_cpu_write(*) with a requirement that preemption be disabled before
> using this function.

You're right. So this patchset also arranges for these vmstat functions to be
called with preemption disabled. I'm converting the this_cpu operations
to __this_cpu versions to make sure of that. And I believe the __this_cpu
WARN if preemptible().


> 
> > +static inline void vmstat_clear_dirty(void)
> > +{
> > +	this_cpu_write(vmstat_dirty, false);
> > +}
> 
> Same
> 
> > +static inline bool is_vmstat_dirty(void)
> > +{
> > +	return this_cpu_read(vmstat_dirty);
> > +}
> 
> This function would only work correctly if preemption is disabled.
> Otherwise the processor may change.

Indeed that should apply as __this_cpu_read() as well.

Thanks!
diff mbox series

Patch

Index: linux-2.6/mm/vmstat.c
===================================================================
--- linux-2.6.orig/mm/vmstat.c
+++ linux-2.6/mm/vmstat.c
@@ -194,6 +194,22 @@  void fold_vm_numa_events(void)
 #endif
 
 #ifdef CONFIG_SMP
+static DEFINE_PER_CPU_ALIGNED(bool, vmstat_dirty);
+
+static inline void vmstat_mark_dirty(void)
+{
+	this_cpu_write(vmstat_dirty, true);
+}
+
+static inline void vmstat_clear_dirty(void)
+{
+	this_cpu_write(vmstat_dirty, false);
+}
+
+static inline bool is_vmstat_dirty(void)
+{
+	return this_cpu_read(vmstat_dirty);
+}
 
 int calculate_pressure_threshold(struct zone *zone)
 {