From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D29DC4332F for ; Mon, 14 Nov 2022 12:12:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11DCA8E0001; Mon, 14 Nov 2022 07:12:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CB446B0073; Mon, 14 Nov 2022 07:12:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED5658E0001; Mon, 14 Nov 2022 07:12:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DAED46B0072 for ; Mon, 14 Nov 2022 07:12:32 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B05561A0201 for ; Mon, 14 Nov 2022 12:12:32 +0000 (UTC) X-FDA: 80131935744.14.09EB1D1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 5108614000C for ; Mon, 14 Nov 2022 12:12:31 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4FFBF6111F; Mon, 14 Nov 2022 12:12:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CCC6C433C1; Mon, 14 Nov 2022 12:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668427949; bh=+ef3W1sVbm/swEdirvU3QG6zn6qU/vBbry+/iQwJyzM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YwYQx7UDj1Kn2tE0MeizUmHWmEWCpCTE+ZXi5P1DLEhTJ0us4W0GyPRjwQb6fL6vr QOJG6F5q+VGcNeKi8nbyYzNXMkc3VIzv+1q9k6cVy/Z7mI0mL9gCMtON6hWbi7Rn3g JjBCI/Bc7OwRTcv+w8fGz4OCYHegQcWsExnbayXjTi3JGa45br/1G4i/t2Vdp9PWbt a24fLzjNftoLH82CwHvU8/2Y7KsfjsxQpbLFIxuZP5hVG9Bf+gMJenalVSgUqE+yHE aHk6KCW0icmgbBw+uyDHYp21LJHWAj2N0mQzZzyS4U700UD5rdN21C0pNomJc/pMKX AZLjkdcNjO76A== Date: Mon, 14 Nov 2022 13:12:26 +0100 From: Frederic Weisbecker To: Marcelo Tosatti Cc: Aaron Tomlin , 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 Message-ID: <20221114121226.GB590078@lothringen> References: <20220924152227.819815-1-atomlin@redhat.com> <20220924152227.819815-4-atomlin@redhat.com> <20221024110311.GA1285913@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668427951; a=rsa-sha256; cv=none; b=zMGujv/zb8fekLX3SzOsnIdsThQOY3KJDeowjLNv/pldbOGD9Mk76S4Xaflj9dFjkTBl85 SzoSd9wUCen35ytYFHPLZYe0mUcOCyJXcn9PNgfl7kpe+I5F7F70XmhH9SZqwfkjoqc5er ouMUL1dTbANN72LS1qJi6vRhPl/YeqE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YwYQx7UD; spf=pass (imf26.hostedemail.com: domain of frederic@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668427951; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4rMs1/1c0GgTsBK+HBsdtxQRjmi1APm4RkZLoojp/r0=; b=TOLSMOcBx8fpKeRvICpnrS7rOmJFtx1OiK26zIa04p5+6ej17X0lG5aLMrHKWDzf/BzOHj I0z5gSSW5nmNe6BbyCO2JfOT6DADoYIS5pln/YM9Plea2EG0k5CBvxxtDs2cNG4O5qcgGQ sI5iV6kooqKDY0vil98tk9S/1Obo0h4= X-Rspam-User: X-Stat-Signature: oxhjnztiawkfysrzixmrsdmcmjdhfew6 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5108614000C Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YwYQx7UD; spf=pass (imf26.hostedemail.com: domain of frederic@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1668427951-34079 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 09, 2022 at 04:40:26PM -0300, Marcelo Tosatti wrote: > 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 > > > > > > 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 > > > --- > > > 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 > > > #include > > > #include > > > +#include > > > > > > #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? That means adding an smp_mb() on user enter, or atomic_cmpxchg(). But then deferred IPI would handle all that for you, right?