linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: atomlin@atomlin.com, cl@linux.com, tglx@linutronix.de,
	mingo@kernel.org, peterz@infradead.org, pauld@redhat.com,
	neelx@redhat.com, oleksandr@natalenko.name,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v12 2/6] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies
Date: Sat, 31 Dec 2022 21:38:04 -0300	[thread overview]
Message-ID: <Y7DV7A9GDTbYIDZB@tpad> (raw)
In-Reply-To: <20221230132132.GA186035@lothringen>

On Fri, Dec 30, 2022 at 02:21:32PM +0100, Frederic Weisbecker wrote:
> On Tue, Dec 27, 2022 at 09:11:39AM -0300, Marcelo Tosatti wrote:
> > @@ -606,6 +608,7 @@ static inline void mod_zone_state(struct
> >  
> >  	if (z)
> >  		zone_page_state_add(z, zone, item);
> > +	vmstat_mark_dirty();
> >  }
> >  
> >  void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
> > @@ -674,6 +677,7 @@ static inline void mod_node_state(struct
> >  
> >  	if (z)
> >  		node_page_state_add(z, pgdat, item);
> > +	vmstat_mark_dirty();
> 
> Looking at this further, about the two above chunks, there is a risk to
> mark the wrong CPU dirty because those functions are preemptible and rely
> on this_cpu_cmpxchg() to deal with preemption.
> 
> Thanks.

Hi Frederic,

Yes, good catch: if the CPU is preempted after this_cpu_cmpxchg(),
but before vmstat_mark_dirty, then one ends up with a CPU with
per-CPU vm counters dirty and the per-CPU vmstat dirty bit unset.

This could cause a CPU to remain with the per-CPU vm counters dirty
for longer than sysctl_stat_interval.

Should move vmstat_mark_dirty() above "if (z)", then do
preempt_disable() on function entry and preempt_enable()
after vmstat_mark_dirty. Luckily preempt_disable()/preempt_enable()
is much cheaper than local_irq_disable()/local_irq_enable().



  reply	other threads:[~2023-01-04 12:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-27 12:11 [PATCH v12 0/6] Ensure quiet_vmstat() is called when returning to userpace and when idle tick is stopped Marcelo Tosatti
2022-12-27 12:11 ` [PATCH v12 1/6] mm/vmstat: Add CPU-specific variable to track a vmstat discrepancy Marcelo Tosatti
2022-12-27 12:11 ` [PATCH v12 2/6] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies Marcelo Tosatti
2022-12-30 13:21   ` Frederic Weisbecker
2023-01-01  0:38     ` Marcelo Tosatti [this message]
2023-01-04 13:34     ` Aaron Tomlin
2022-12-27 12:11 ` [PATCH v12 3/6] mm/vmstat: manage per-CPU stats from CPU context when NOHZ full Marcelo Tosatti
2022-12-27 12:11 ` [PATCH v12 4/6] tick/nohz_full: Ensure quiet_vmstat() is called on exit to user-mode when the idle tick is stopped Marcelo Tosatti
2022-12-27 12:11 ` [PATCH v12 5/6] tick/sched: Ensure quiet_vmstat() is called when the idle tick was stopped too Marcelo Tosatti
2022-12-27 12:11 ` [PATCH v12 6/6] mm/vmstat: avoid queueing work item if cpu stats are clean Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y7DV7A9GDTbYIDZB@tpad \
    --to=mtosatti@redhat.com \
    --cc=atomlin@atomlin.com \
    --cc=cl@linux.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=neelx@redhat.com \
    --cc=oleksandr@natalenko.name \
    --cc=pauld@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox