linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: Aaron Tomlin <atomlin@redhat.com>,
	cl@linux.com, tglx@linutronix.de, mingo@kernel.org,
	peterz@infradead.org, pauld@redhat.com, neelx@redhat.com,
	oleksandr@natalenko.name, atomlin@atomlin.com,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v8 3/5] mm/vmstat: Do not queue vmstat_update if tick is stopped
Date: Wed, 9 Nov 2022 16:40:26 -0300	[thread overview]
Message-ID: <Y2wCKjYIxN8Q/FQ+@fuller.cnet> (raw)
In-Reply-To: <20221024110311.GA1285913@lothringen>

On Mon, Oct 24, 2022 at 01:03:11PM +0200, Frederic Weisbecker wrote:
> Lines: 94
> 
> On Sat, Sep 24, 2022 at 04:22:25PM +0100, Aaron Tomlin wrote:
> > From: Marcelo Tosatti <mtosatti@redhat.com>
> > 
> > From the vmstat shepherd, for CPUs that have the tick stopped, do not
> > queue local work to flush the per-CPU vmstats, since in that case the
> > flush is performed on return to userspace or when entering idle. Also
> > cancel any delayed work on the local CPU, when entering idle on nohz
> > full CPUs. Per-CPU pages can be freed remotely from housekeeping CPUs.
> > 
> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> > ---
> >  mm/vmstat.c | 18 +++++++++++++-----
> >  1 file changed, 13 insertions(+), 5 deletions(-)
> > 
> > diff --git a/mm/vmstat.c b/mm/vmstat.c
> > index 472175642bd9..3b9a497965b4 100644
> > --- a/mm/vmstat.c
> > +++ b/mm/vmstat.c
> > @@ -29,6 +29,7 @@
> >  #include <linux/page_ext.h>
> >  #include <linux/page_owner.h>
> >  #include <linux/migrate.h>
> > +#include <linux/tick.h>
> >  
> >  #include "internal.h"
> >  
> > @@ -1990,19 +1991,23 @@ static void vmstat_update(struct work_struct *w)
> >   */
> >  void quiet_vmstat(void)
> >  {
> > +	struct delayed_work *dw;
> > +
> >  	if (system_state != SYSTEM_RUNNING)
> >  		return;
> >  
> >  	if (!is_vmstat_dirty())
> >  		return;
> >  
> > +	refresh_cpu_vm_stats(false);
> > +
> >  	/*
> > -	 * Just refresh counters and do not care about the pending delayed
> > -	 * vmstat_update. It doesn't fire that often to matter and canceling
> > -	 * it would be too expensive from this path.
> > -	 * vmstat_shepherd will take care about that for us.
> > +	 * If the tick is stopped, cancel any delayed work to avoid
> > +	 * interruptions to this CPU in the future.
> >  	 */
> > -	refresh_cpu_vm_stats(false);
> > +	dw = &per_cpu(vmstat_work, smp_processor_id());
> > +	if (delayed_work_pending(dw) && tick_nohz_tick_stopped())
> > +		cancel_delayed_work(dw);
> >  }
> >  
> >  /*
> > @@ -2024,6 +2029,9 @@ static void vmstat_shepherd(struct work_struct *w)
> >  	for_each_online_cpu(cpu) {
> >  		struct delayed_work *dw = &per_cpu(vmstat_work, cpu);
> >  
> > +		if (tick_nohz_tick_stopped_cpu(cpu))
> > +			continue;
> > +
> >  		if (!delayed_work_pending(dw) && per_cpu(vmstat_dirty, cpu))
> >  			queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0);
> 
> All these checks are racy though. You may well eventually:
> 
> 1) Arm the timer after the CPU has entered in userspace
> 2) Not arm the timer when the CPU has entered the kernel
> 
> How about converting that to an IPI instead? This should be a good candidate
> for the future IPI deferment.
> 
> Another possible way to go is this:
> 
> 1) vmstat_shepherd completely ignores nohz_full CPUs
> 2) vmstat_work is only ever armed locally
> 3) A nohz_full CPU turning its local vmstat as dirty checks if vmstat_work is
>    pending. If not, queue it, possibly through a self IPI (IRQ_WORK) to get
>    away with current locking context.

I'm afraid there might be workloads where local vmstat touch is a
hot-path.

> 3) Fold on idle if dirty
> 4) Fold on user enter and disarm vmstat_work if pending
> 
> Does that sound possible?
> 
> Thanks.

I guess so, but proper barriers would also work.

Do you have any particular reason for the 1-4 sequence above 
instead of barriers?



  reply	other threads:[~2022-11-09 20:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24 15:22 [PATCH v8 0/5] Ensure quiet_vmstat() is called when the idle tick was stopped too Aaron Tomlin
2022-09-24 15:22 ` [PATCH v8 1/5] mm/vmstat: Add CPU-specific variable to track a vmstat discrepancy Aaron Tomlin
2022-09-24 15:22 ` [PATCH v8 2/5] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies Aaron Tomlin
2022-10-01 14:55   ` kernel test robot
2022-09-24 15:22 ` [PATCH v8 3/5] mm/vmstat: Do not queue vmstat_update if tick is stopped Aaron Tomlin
2022-10-24 11:03   ` Frederic Weisbecker
2022-11-09 19:40     ` Marcelo Tosatti [this message]
2022-11-10 19:15       ` Marcelo Tosatti
2022-11-14 12:12       ` Frederic Weisbecker
2022-10-24 11:54   ` Frederic Weisbecker
2022-09-24 15:22 ` [PATCH v8 4/5] tick/nohz_full: Ensure quiet_vmstat() is called on exit to user-mode when the idle " Aaron Tomlin
2022-09-27 16:17   ` Rafael Folco
2022-09-29  8:22     ` Aaron Tomlin
2022-09-29 12:49       ` Rafael Folco
2022-10-21 14:50     ` Frederic Weisbecker
2022-11-10 19:14       ` Marcelo Tosatti
2022-09-24 15:24 ` [PATCH v8 5/5] tick/sched: Ensure quiet_vmstat() is called when the idle tick was stopped too Aaron Tomlin
2022-09-25  1:05   ` Hillf Danton
2022-09-26  9:20     ` Aaron Tomlin
2022-10-03 12:44       ` Hillf Danton
2022-10-12 12:41         ` Aaron Tomlin
2022-10-17 16:04         ` 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=Y2wCKjYIxN8Q/FQ+@fuller.cnet \
    --to=mtosatti@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=atomlin@atomlin.com \
    --cc=atomlin@redhat.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