public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Dmitry Ilvokhin <d@ilvokhin.com>
To: Breno Leitao <leitao@debian.org>
Cc: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org, kas@kernel.org,
	shakeel.butt@linux.dev, usama.arif@linux.dev,
	kernel-team@meta.com
Subject: Re: [PATCH] mm/vmstat: spread vmstat_update requeue across the stat interval
Date: Thu, 9 Apr 2026 12:27:21 +0000	[thread overview]
Message-ID: <adebKQaiAP4G3liv@shell.ilvokhin.com> (raw)
In-Reply-To: <adaGcf2hKNGHwVPd@gmail.com>

[...]

> 
> commit d725f0664b70aa5c677215b0fc1abc0117aaf114
> Author: Breno Leitao <leitao@debian.org>
> Date:   Wed Apr 8 09:01:02 2026 -0700
> 
>     mm/vmstat: fix vmstat_shepherd double-scheduling vmstat_update
>     
>     vmstat_shepherd uses delayed_work_pending() to check whether
>     vmstat_update is already scheduled for a given CPU before queuing it.
>     However, delayed_work_pending() only tests WORK_STRUCT_PENDING_BIT,
>     which is cleared the moment a worker thread picks up the work to
>     execute it.
>     
>     This means that while vmstat_update is actively running on a CPU,
>     delayed_work_pending() returns false. If need_update() also returns
>     true at that point (per-cpu counters not yet zeroed mid-flush), the
>     shepherd queues a second invocation with delay=0, causing vmstat_update
>     to run again immediately after finishing.
>     
>     On a 72-CPU system this race is readily observable: before the fix,
>     many CPUs show invocation gaps well below 500 jiffies (the minimum
>     round_jiffies_relative() can produce), with the most extreme cases
>     reaching 0 jiffies—vmstat_update called twice within the same jiffy.
>     
>     Fix this by replacing delayed_work_pending() with work_busy(), which
>     returns non-zero for both WORK_BUSY_PENDING (timer armed or work
>     queued) and WORK_BUSY_RUNNING (work currently executing). The shepherd
>     now correctly skips a CPU in all busy states.

Great find. Thanks for taking the time to track this down.

> 
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index d59eff1582547..5489549241b51 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -2156,7 +2156,7 @@ static void vmstat_shepherd(struct work_struct *w)
>  			if (cpu_is_isolated(cpu))
>  				continue;
>  
> -			if (!delayed_work_pending(dw) && need_update(cpu))
> +			if (!work_busy(&dw->work) && need_update(cpu))
>  				queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0);
>  		}
>  

Reviewed-by: Dmitry Ilvokhin <d@ilvokhin.com>


  parent reply	other threads:[~2026-04-09 12:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01 13:57 [PATCH] mm/vmstat: spread vmstat_update requeue across the stat interval Breno Leitao
2026-04-01 14:25 ` Johannes Weiner
2026-04-01 14:39   ` Breno Leitao
2026-04-01 14:57     ` Johannes Weiner
2026-04-01 14:47 ` Breno Leitao
2026-04-01 15:01 ` Kiryl Shutsemau
2026-04-01 15:23 ` Usama Arif
2026-04-01 15:43   ` Breno Leitao
2026-04-01 15:50     ` Usama Arif
2026-04-01 15:52       ` Breno Leitao
2026-04-01 17:46 ` Vlastimil Babka (SUSE)
2026-04-02 12:40   ` Vlastimil Babka (SUSE)
2026-04-02 13:33     ` Breno Leitao
2026-04-07 15:39       ` Breno Leitao
2026-04-08 10:13         ` Vlastimil Babka (SUSE)
2026-04-08 15:13           ` Breno Leitao
2026-04-08 17:00             ` Breno Leitao
2026-04-09  9:36               ` Vlastimil Babka (SUSE)
2026-04-09 12:27               ` Dmitry Ilvokhin [this message]
2026-04-09  9:17             ` Vlastimil Babka (SUSE)
2026-04-02 12:43   ` Dmitry Ilvokhin
2026-04-02  7:18 ` Michal Hocko
2026-04-02 12:49 ` Matthew Wilcox
2026-04-02 13:26   ` Breno Leitao

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=adebKQaiAP4G3liv@shell.ilvokhin.com \
    --to=d@ilvokhin.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    /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