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 3C19DC4332F for ; Fri, 23 Dec 2022 14:41:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89085900003; Fri, 23 Dec 2022 09:41:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8402F900002; Fri, 23 Dec 2022 09:41:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70800900003; Fri, 23 Dec 2022 09:41:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5E5E5900002 for ; Fri, 23 Dec 2022 09:41:57 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2747B160186 for ; Fri, 23 Dec 2022 14:41:57 +0000 (UTC) X-FDA: 80273835474.23.9A719E7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 9AF981C0016 for ; Fri, 23 Dec 2022 14:41:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kox8nRoW; spf=pass (imf20.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=1671806515; 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=8o+UIo9FiDlWfFDeauUPvj3jRYbIOH5zfA9HbrsYyR8=; b=ulVjM0GFUbm8Av9O+zwzSnzU723yE/DSuQFfuUlELBSRtNEnckbxkSNQMKL0u7PILFSvnb RqS2UXB3SQhIyZ4oPrDytBqrh3MTH8PfBy2w+YVImwiM6nHsxfEbxV1I7a3me4ZpNdgtus foh00bX6SOmWPTWGmmlBJOQWdDTn7D4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kox8nRoW; spf=pass (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671806515; a=rsa-sha256; cv=none; b=USnU1JxyQ1G9hRTZMDhhJKnc45fTkm+3pw230GPNtNtFB+iRwCc8N4iu3DBelydFJwqpw8 R4gQHQlxbYKWmSr7c/2328hH/a34rtgaUB2TjXsov4OwMACSDoLrFGvWS+Qb8W1M/pwVeZ log+eHz+XhdZ7emMzjiIN46v1PWF2KU= 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 6C077611F0; Fri, 23 Dec 2022 14:41:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A76DC433D2; Fri, 23 Dec 2022 14:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671806513; bh=37BtRM3lBO+1nDbvr3DPq5coHa2cgacS+AVXyWnLNOc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kox8nRoWLjje3Cjgbtjsl1MUkRM6pr89A0hlUvaZL1bXsWL6WvlOZT8S5LNQ437Ik 9MGEtfPFcaJvdgRCrlFQ1nWuCz8f4iAB8NwrZe3hhfkHWq3yJ7N6Z72IF6otN52F+P QvaIQtXHPH5dWnGMu6tagb/hP9Lh+/8AzXx+a0gNepIwzX5CCRwejwtS4xlHRxGf2/ UQWBAU0CaKLo3GT9R2CObcJeSb3TvX31aIAhX383GjJFp7KgXe/XeMKYrH+nGRKjWG ls9M/e9igPRFWQMahWwo7ivthVHTKTH/1JOstNMAxAKqpYpsBXRtl0YMaAHyaiQgIz FjSJasnbusqFw== Date: Fri, 23 Dec 2022 15:41:50 +0100 From: Frederic Weisbecker To: Marcelo Tosatti Cc: atomlin@atomlin.com, cl@linux.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v11 3/6] mm/vmstat: manage per-CPU stats from CPU context when NOHZ full Message-ID: <20221223144150.GA79369@lothringen> References: <20221221165801.362118576@redhat.com> <20221221170436.330627967@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221221170436.330627967@redhat.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9AF981C0016 X-Rspam-User: X-Stat-Signature: jimq3d55te1akh699of6fi4kth1oe54p X-HE-Tag: 1671806515-675762 X-HE-Meta: U2FsdGVkX1+k1iITDh0n6dFiTaRkQXN+9xI6UYkH+Z8riVg0snMiw6vBxoM9Lg7IazInJE+uKMNk+6fcbvcUFibVYHIZibVRAV2oSBxaDmjfbOHULx8SbPs6Z80023xGUAOHNAHmCbGD+CPh2oFf6ED1L+zGJiIpMGQZu/Ht22Xp3vIUM7q4ULa4/G1ZlApn61Z94Kuni8psI38pIOZSoyvFkvPl+Dq1EkhKfLHnWUN276wAKfze9rDrYEv+J+Bjq1FIPT6W/fFDwXoncuXlQLf5O+6CDTS3hrnfVVyUrr+ihgYQu3zqkwfPYJCd00f2OXgq8/nRQd0RJT8YywNQ1HT9B4FZKcwSwP5yb4iXGCC413rbtnx7I6QwVsR3gyElRHwt2bhXbYiUoQK19PlPB+rcoZGtFYMTPDyoRMXsovL7mprEpc6S2rUyBxICp2iqjT1AMY/hKrY2jHXaaaFvTgPKCRNgOzUsMtNUTpe6IjhPoq1i+4ePfKkXNFtcGqEnfUg9l4O6DT+uJqFYvivXz2Qzk6DttxR2hhzj3zR4mOTGfyUhVv9ch9Pn2Uk4YeTRVabd+E0FmEaLtQvxNwfAsSQrBNkJ+7IoYol0eg12KJVagRfcBOWC2Nen6Cx0nMSDFmtTj+A3rYIPUQXmcx+Zcq0dCZst55pvBEVnmXjtCE87h5XkCdLZxGrVQb6do56UHXzows0JIihJB8tXehvEawNZvbZO/SaS2IW90dJuL/LAvQ963v0Yebc3r6YLgm1H5eM205Yj2/havDjhUpoeU6z9CjkgzHM4G1WZ+V8uBWdeA6ukY2W2g5sZqQBdQH4Iz1f5sQjQmVMyjuMCVqW8ZRtwt+rlAtDZTPyoIREdor16AnHMr8LOKOpYUqB2cEqGsXTzCzs5euZA2dIP8fy94uLmU8AQHPc8dxtUSU6be7x1gNj91Rb4whGhhjDck6hHJ119Zy5BBzB8cgIcgtG iSdlhLXo lWVAEhDo3HSu4opW8ctm/nv6zfyRKhFWgJKh1 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, Dec 21, 2022 at 01:58:04PM -0300, Marcelo Tosatti wrote: > @@ -194,21 +195,50 @@ void fold_vm_numa_events(void) > #endif > > #ifdef CONFIG_SMP > -static DEFINE_PER_CPU_ALIGNED(bool, vmstat_dirty); > + > +struct vmstat_dirty { > + bool dirty; > + bool cpuhotplug; May be call it "online" for clarity. Also should it depend on CONFIG_FLUSH_WORK_ON_RESUME_USER? > +}; > + > +static DEFINE_PER_CPU_ALIGNED(struct vmstat_dirty, vmstat_dirty_pcpu); > +static DEFINE_PER_CPU(struct delayed_work, vmstat_work); > +int sysctl_stat_interval __read_mostly = HZ; > > static inline void vmstat_mark_dirty(void) > { > - this_cpu_write(vmstat_dirty, true); > + struct vmstat_dirty *vms = this_cpu_ptr(&vmstat_dirty_pcpu); > + > +#ifdef CONFIG_FLUSH_WORK_ON_RESUME_USER Please avoid ifdeffery in the middle of a function when possible. This block could be in a different function or use IS_ENABLED() for example. > + int cpu = smp_processor_id(); > + > + if (tick_nohz_full_cpu(cpu) && !vms->dirty) { > + struct delayed_work *dw; > + > + dw = this_cpu_ptr(&vmstat_work); > + if (!delayed_work_pending(dw) && !vms->cpuhotplug) { > + unsigned long delay; > + > + delay = round_jiffies_relative(sysctl_stat_interval); > + queue_delayed_work_on(cpu, mm_percpu_wq, dw, delay); > + } > + } > +#endif > + vms->dirty = true; > } > > static inline void vmstat_clear_dirty(void) > { > - this_cpu_write(vmstat_dirty, false); > + struct vmstat_dirty *vms = this_cpu_ptr(&vmstat_dirty_pcpu); > + > + vms->dirty = false; You could keep this_cpu_write(vmstat_dirty.dirty, false) > } > > static inline bool is_vmstat_dirty(void) > { > - return this_cpu_read(vmstat_dirty); > + struct vmstat_dirty *vms = this_cpu_ptr(&vmstat_dirty_pcpu); > + > + return vms->dirty; Ditto with this_cpu_read()? > } > > int calculate_pressure_threshold(struct zone *zone) > @@ -1981,13 +2008,18 @@ void quiet_vmstat(void) > if (!is_vmstat_dirty()) > return; > > + refresh_cpu_vm_stats(false); > + > +#ifdef CONFIG_FLUSH_WORK_ON_RESUME_USER This can use IS_ENABLED() > + if (!user) > + return; > /* > - * 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); > + if (delayed_work_pending(this_cpu_ptr(&vmstat_work))) > + cancel_delayed_work(this_cpu_ptr(&vmstat_work)); > +#endif > } > > /* > @@ -2008,8 +2040,15 @@ static void vmstat_shepherd(struct work_ > /* Check processors whose vmstat worker threads have been disabled */ > for_each_online_cpu(cpu) { > struct delayed_work *dw = &per_cpu(vmstat_work, cpu); > + struct vmstat_dirty *vms = per_cpu_ptr(&vmstat_dirty_pcpu, cpu); > > - if (!delayed_work_pending(dw) && per_cpu(vmstat_dirty, cpu)) > +#ifdef CONFIG_FLUSH_WORK_ON_RESUME_USER Same here. > + /* NOHZ full CPUs manage their own vmstat flushing */ > + if (tick_nohz_full_cpu(cpu)) > + continue; > +#endif > + > + if (!delayed_work_pending(dw) && vms->dirty) > queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0); > > cond_resched(); > @@ -2053,8 +2111,15 @@ static int vmstat_cpu_online(unsigned in > return 0; > } > > +/* > + * ONLINE: The callbacks are invoked on the hotplugged CPU from the per CPU > + * hotplug thread with interrupts and preemption enabled. This is OFFLINE and the reason behind that comment is confusing. > + */ > static int vmstat_cpu_down_prep(unsigned int cpu) > { > + struct vmstat_dirty *vms = per_cpu_ptr(&vmstat_dirty_pcpu, cpu); > + > + vms->cpuhotplug = true; this_cpu_write() ? > cancel_delayed_work_sync(&per_cpu(vmstat_work, cpu)); > return 0; > } > +config FLUSH_WORK_ON_RESUME_USER > + bool "Flush per-CPU vmstats on user return (for nohz full CPUs)" > + depends on NO_HZ_FULL > + default y > + > + help > + By default, nohz full CPUs flush per-CPU vm statistics on return > + to userspace (to avoid additional interferences when executing > + userspace code). This has a small but measurable impact on > + system call performance. You can disable this to improve system call > + performance, at the expense of potential interferences to userspace > + execution. Can you move that below config CPU_ISOLATION ? Thanks! > + > # multi-gen LRU { > config LRU_GEN > bool "Multi-Gen LRU" > >