Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6793930rwi; Mon, 24 Oct 2022 06:16:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4aiGnl9DaOr+skXNqTYg0PrFlpiwUmX1fVJQiaEm3G4WpasGJ8OjDKTv/0Rrl/158/Y26n X-Received: by 2002:a17:907:701:b0:780:2c44:e4dd with SMTP id xb1-20020a170907070100b007802c44e4ddmr28291021ejb.589.1666617366629; Mon, 24 Oct 2022 06:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666617366; cv=none; d=google.com; s=arc-20160816; b=M1+Q9a/JJLZ+3RccBZsGz0l2WzXGXLoPVSZjIVINFVsVjjYi7y7RDXWx3zrympr2Sk pJZGC17x2wApG3FW8pzluOwLNgZTR527oyfavbO66Y8W0CchlIpEwaPTSkAMaD/ITSqc 9zUlrxsadZgIKXQqg7pasYnqRppIClDh2phVsC5OYORWotcNAqNQ6bzQQWb0CykwSgNz jbfrMaIKqxMfKmNjOBwxmShnPz3MAm8W9oBJU8R09x/oFRjl+mNFcsSeeiv1Hrm8S5Zf mmAZJ6bc+Q9iZmpHbjY3LyAuI92l+bi2FHVg2rkaMkCnVU+QWCDcCQZ3g1iQn9VDwGGr 6hIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0oCFss8FuFvFgx6838iX7pudCZ+rQZPWM5NmWpkzRlg=; b=YYzxPLGJ6AiuuAHjeix/7NjUaL5PAYTJLxp6O+HDWTBY+4FtKXIdDHoh949mndTzWd +3zIxtrPZQWrZLcmAkCN6l9x4nFFmWWNEN+GEkawHyuIriNJcm2cRT0/LCFeq/hn8esX ce/MrHtAu6O2eF9pAJa826RZ5eJevtQ5fgtsxCEx0SOvvuwXC3OVgbEibmg8J+OXtiw9 Z7sk3DGlIf8fstQyWUEen7mvZ/l84thrAuElkqrjOirWik17f/JW/u27GqhJe/HQIIE/ Wu8dxJQyXs+B6KaynHcW7Oafr1R2U5T3dBWdU0ZCjlO96EMzHYYycBteQRNpbEFlope4 QL/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SFgncGQw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a0564021e8f00b00461e63fe88fsi1665028edf.596.2022.10.24.06.15.41; Mon, 24 Oct 2022 06:16:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SFgncGQw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233029AbiJXMPt (ORCPT + 99 others); Mon, 24 Oct 2022 08:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233161AbiJXMOU (ORCPT ); Mon, 24 Oct 2022 08:14:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37BB931DD0 for ; Mon, 24 Oct 2022 04:55:07 -0700 (PDT) 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 20E04612E4 for ; Mon, 24 Oct 2022 11:54:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DBDBC433C1; Mon, 24 Oct 2022 11:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666612469; bh=/o+mi3lqLRFkJ7ON565vkXhmtzUNxmeBz98aaAWoL/o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SFgncGQwAjO9MyLrbGxP8Pz9fziukwMyBVefnpDoyTRqHqE4ETly6+FvTKZZZXs5j lwOxgMLfvEjZfa+j1jd+8KXTsXOO0s/kqU/LQvPorh0IqKn0YkrFZ6+v/xKIwBdhch NEXwbbBR4JZG+5Y1Q6xsesdqkbyvlGDL7HGTVYejKmFP1vB3inLU6U79LfFAlL5grr 8UFLCbzjzgXZJRillYBJzoZ3MlQJ3ktTIo6eDi68ev3lWlYVhb/vaZDybclLzl06Hu dam8tzXpjgshwgI7ecZzEomgH0H71zjcFUS10wL+bPabaNgXI6wVo8yZ5Fr59zcfNO 3pNKk+k4gWTBw== Date: Mon, 24 Oct 2022 13:54:26 +0200 From: Frederic Weisbecker To: Aaron Tomlin Cc: mtosatti@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 Message-ID: <20221024115426.GA1287228@lothringen> References: <20220924152227.819815-1-atomlin@redhat.com> <20220924152227.819815-4-atomlin@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220924152227.819815-4-atomlin@redhat.com> X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); This is doing the costly cancel_delayed_work() which is only necessary right before entering entering in user. There are places where the tick is stopped but it's not necessary to cancel the work: * nohz_full enter idle * idle IRQs * nohz_full exit idle * nohz_full IRQ exit I suggest having quiet_vmstat_enter_user() which does: void quiet_vmstat_enter_user(void) { quiet_vmstat(); if (delayed_work_pending(dw) && tick_nohz_tick_stopped()) cancel_delayed_work(dw); } And call this one only before leaving the kernel. The rest can use quiet_vmstat(). Thanks.