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 EA2FCC433FE for ; Wed, 9 Nov 2022 20:04:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 829026B0072; Wed, 9 Nov 2022 15:04:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D9208E0001; Wed, 9 Nov 2022 15:04:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A0646B0074; Wed, 9 Nov 2022 15:04:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 56A6E6B0072 for ; Wed, 9 Nov 2022 15:04:38 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2655F1A05B3 for ; Wed, 9 Nov 2022 20:04:38 +0000 (UTC) X-FDA: 80114981436.03.B7B63AE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id B988520008 for ; Wed, 9 Nov 2022 20:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668024276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4JpgViCI9N5nOLLYCx04E2zRWLxWK/5vOHmovPG9dcM=; b=QdEu9MwnTQAGtPc15a48cWKxa++xtfH95SU2+EnfGhkhh1XAQRR+lXy2J/mR4ALk9kffNJ 49u88aiN2cJev25NkHpssAdB8ac2/2qKYV14NnrgJGdmkqbMA7NEEqCY1Jj1cZOXIy+NoV R7o0xk8qmTGzRcCWEQw2Yp261t8T1Kw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-184-nW6RJhzMNL2jlX4G5MQ8kQ-1; Wed, 09 Nov 2022 15:04:33 -0500 X-MC-Unique: nW6RJhzMNL2jlX4G5MQ8kQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CD8A1C0879D; Wed, 9 Nov 2022 20:04:32 +0000 (UTC) Received: from fuller.cnet (ovpn-112-4.gru2.redhat.com [10.97.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0CD04B3FC6; Wed, 9 Nov 2022 20:04:31 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 9BFE3416D89A; Wed, 9 Nov 2022 16:40:26 -0300 (-03) Date: Wed, 9 Nov 2022 16:40:26 -0300 From: Marcelo Tosatti To: Frederic Weisbecker 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: 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: <20221024110311.GA1285913@lothringen> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668024276; a=rsa-sha256; cv=none; b=YU7cAo6o0jyk1ZW1YWRigcFt6f5XsgndCw3ZIWXC8zt5E/yR3O6lByVFL2pOvCUxvVfZDb FBsL2Op5mGfT6Xun1ZPjGYiWodM5uN7lTilDZ0W2RDmKPX8VafD+RjBEfwV2iblGjcl1s6 9Nmv+RjJ2tiXfBlaMaWVx2kfgEo/VEk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QdEu9Mwn; spf=pass (imf03.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668024276; 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=4JpgViCI9N5nOLLYCx04E2zRWLxWK/5vOHmovPG9dcM=; b=24vW6jUAx1TZ0xoSxX1p5VAcElwV6hGUGFeUBivradTIwchKqLbS+Y8gaKjihqDWzhQghk YDMqY7Ha/hQdemK/jmlCL7fcu8sDgLmD8Lclk93rsE2DNdkOhJrDPQ0CxJijTnA21wms5/ z8GzfIklTh3xDwKZmI80aPkfnuoy52Y= X-Stat-Signature: pq8fmgah9pu99ixe7phzq9gq6bp5peke X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QdEu9Mwn; spf=pass (imf03.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Queue-Id: B988520008 X-Rspamd-Server: rspam09 X-HE-Tag: 1668024276-317377 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 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?