From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28BBA3C4555 for ; Thu, 9 Apr 2026 12:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775737648; cv=none; b=PHJijk6KPliM6VhImGwYUF+P4Agq0rBDCQ+UE5vQjC2lycxL/F2gZCY3izT2dLEPaelhmOO72LAvJRLN6/d6YUxOctoDl7H0MxBRmphJ2uCMNMzx8hAG9b29WJOUXbqrzBEZ0rIN+8TKvV80Bl+fuuy1suHLKund8kwG4z342HY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775737648; c=relaxed/simple; bh=1mOjUhcBGEPTYkBtXv/fdyMZDYM5JQ4MKudKDlnAphM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cKLGsxCZtANPfAuyUb/np/ujhA1ujBUXUdlgtMwALuOfZNuHevKzQr/0RxymW/mLwI8xQXo76OgLgkBVPjXXHSaznqt7oKsRUtG6yQ7wjEjypqKKkWcjIbL6lzRvbQqFdm/OCU2YPAgTeYW3QJQTYMI/OdtVsdpk1oEIeeCMl8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=RwRP/kx1; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="RwRP/kx1" Received: from shell.ilvokhin.com (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 1217DBE7B5; Thu, 09 Apr 2026 12:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1775737645; bh=uZPTbiLq53ot9iWPM7HtJltAZddmRwOh2+RL/t3MN08=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=RwRP/kx1/fnQuR6igiUGPuZojD7cXA7EjCwFkUqUkh6S4q3UaVWxC8VDyW9owGu6n ve6oiIzDxXFd/8QXcZnJQDSiemlUcYZQG2OnEMy5vYBKtJX9RsFaoo/BAA+xq6F8XJ xctfxwGP4CklzotslG0wHr7L1oZtFzNrTXw/FdOY= Date: Thu, 9 Apr 2026 12:27:21 +0000 From: Dmitry Ilvokhin To: Breno Leitao Cc: "Vlastimil Babka (SUSE)" , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , 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 Message-ID: References: <20260401-vmstat-v1-1-b68ce4a35055@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: [...] > > commit d725f0664b70aa5c677215b0fc1abc0117aaf114 > Author: Breno Leitao > 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