Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2386131rwl; Fri, 6 Jan 2023 05:54:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXv2vZq7FawYFPS0gl8hgYKrJ9CUkdjFpbfXgvU01EB1eq7TinZwlMwR+vOuQ9PCaoaY2Zbw X-Received: by 2002:a05:6a20:bfc3:b0:ad:94d0:ac97 with SMTP id gs3-20020a056a20bfc300b000ad94d0ac97mr64334868pzb.48.1673013244065; Fri, 06 Jan 2023 05:54:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673013244; cv=none; d=google.com; s=arc-20160816; b=wNYivK3xw20xmRQJrqI+ZS8NumTP23YarrXcKO0C5ij1GFhJ+jINj/pjcRR4q+2Abs yX+Ye9WM/liKYJtIen8t0GLQYYDiOIQ4f4d0TjaAtQgq8fR8I8+hdFTAfTIzhgjITF16 ihs3VA7JY6DWfoV/gxJiNQKeyVWY8fL8lUwryM2/uBpiCxOI18WbzTCdt4diB/itZdSX GWB1nLVCGt9yChujQLGMH0/Ju0WZhFmwpLBvqBYQql/t3Yjy/iiX4uPA1a/A6NwbM3sQ 23bdkGZ3mhXY1zbbt1zRdpJvFFoJfNOi+OiPK/OUft2RYxNfpAD7waOJkdlETsnBe3J6 IZRg== 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=ym1HIba5hHhgKrJESNW1DYb3f7111AlEKPxGR4GLiE4=; b=Sg+3thivfdfOrbwiNLLole1FhKafa4dHr8R8H/9GsK/PWRzQ0lE0gIwl3Ue3GFin2z sqvbM7sUXPRrhrZB/VdhyBdiEMR15a836OEgWZVkooPSaWu8/Kr/uD55Kk+Y2e4DfgOH KaYJ4tCi6vMFnbRBBsglXieISa8H1h4MhMQ7L1d7qqTpMoJipYvgHVh/STAkO0y2b0Z2 dDPutQgLPGOX7sa5oniJA39BPmkc9bZ1DOJfssvweDwVwts2Dujg3nzoNnINZzPGydGa iBxcc8bR9iDrm5qNltsEiJJtBwSWPgbU1ZfKLy42DfgcveFgQClPpX0mY/p1pMnRirSv 70vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MaSWMtnO; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020a63d210000000b0049e0bab8d55si1531949pgg.133.2023.01.06.05.53.56; Fri, 06 Jan 2023 05:54:04 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=MaSWMtnO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230501AbjAFNDI (ORCPT + 54 others); Fri, 6 Jan 2023 08:03:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234982AbjAFNCe (ORCPT ); Fri, 6 Jan 2023 08:02:34 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9537071FF7 for ; Fri, 6 Jan 2023 05:01:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673010089; 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=ym1HIba5hHhgKrJESNW1DYb3f7111AlEKPxGR4GLiE4=; b=MaSWMtnO/NN60Zebvb4FgE0UD0WPTTqWq9U+/djrj+i137N1/XQk2kAoS9MCLdGXH+tO9d LL/x78B7+ZckuA1bpk6c1M6E8rPj9Bo5412UI2ilJfPix/afav8JPkzCKo0NT5AsHgOUnP MQIYhcXw74yRcJMq2Pco0sAdmpLsu2I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-6Qm0-ZbEMguIUxFUB3CBdg-1; Fri, 06 Jan 2023 08:01:25 -0500 X-MC-Unique: 6Qm0-ZbEMguIUxFUB3CBdg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B589687A9E1; Fri, 6 Jan 2023 13:01:24 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33C522026D4B; Fri, 6 Jan 2023 13:01:24 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 1F06C401A0A0A; Fri, 6 Jan 2023 09:51:00 -0300 (-03) Date: Fri, 6 Jan 2023 09:51:00 -0300 From: Marcelo Tosatti To: Hillf Danton Cc: atomlin@atomlin.com, frederic@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v13 3/6] mm/vmstat: manage per-CPU stats from CPU context when NOHZ full Message-ID: References: <20230105125218.031928326@redhat.com> <20230106001244.4463-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230106001244.4463-1-hdanton@sina.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Fri, Jan 06, 2023 at 08:12:44AM +0800, Hillf Danton wrote: > On 05 Jan 2023 09:52:21 -0300 Marcelo Tosatti > > For nohz full CPUs, we'd like the per-CPU vm statistics to be > > synchronized when userspace is executing. Otherwise, > > the vmstat_shepherd might queue a work item to synchronize them, > > which is undesired intereference for isolated CPUs. > > > > This means that its necessary to check for, and possibly sync, > > the statistics when returning to userspace. This means that > > there are now two execution contexes, on different CPUs, > > which require awareness about each other: context switch > > and vmstat shepherd kernel threadr. > > > > To avoid the shared variables between these two contexes (which > > would require atomic accesses), delegate the responsability > > of statistics synchronization from vmstat_shepherd to local CPU > > context, for nohz_full CPUs. > > > > Do that by queueing a delayed work when marking per-CPU vmstat dirty. > > > > When returning to userspace, fold the stats and cancel the delayed work. > > > > When entering idle, only fold the stats. > > > > Signed-off-by: Marcelo Tosatti > > --- > > include/linux/vmstat.h | 4 ++-- > > kernel/time/tick-sched.c | 2 +- > > mm/vmstat.c | 41 ++++++++++++++++++++++++++++++++--------- > > 3 files changed, 35 insertions(+), 12 deletions(-) > > > > Index: linux-2.6/mm/vmstat.c > > =================================================================== > > --- linux-2.6.orig/mm/vmstat.c > > +++ linux-2.6/mm/vmstat.c > > @@ -28,6 +28,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "internal.h" > > > > @@ -194,21 +195,57 @@ void fold_vm_numa_events(void) > > #endif > > > > #ifdef CONFIG_SMP > > -static DEFINE_PER_CPU_ALIGNED(bool, vmstat_dirty); > > + > > +struct vmstat_dirty { > > + bool dirty; > > +#ifdef CONFIG_FLUSH_WORK_ON_RESUME_USER > > + bool cpu_offline; > > +#endif > > +}; > > + > > +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; > > + > > +#ifdef CONFIG_FLUSH_WORK_ON_RESUME_USER > > +static inline void vmstat_queue_local_work(void) > > +{ > > + bool vmstat_dirty = this_cpu_read(vmstat_dirty_pcpu.dirty); > > + bool cpu_offline = this_cpu_read(vmstat_dirty_pcpu.cpu_offline); > > + int cpu = smp_processor_id(); > > + > > + if (tick_nohz_full_cpu(cpu) && !vmstat_dirty) { > > + struct delayed_work *dw; > > + > > + dw = this_cpu_ptr(&vmstat_work); > > + if (!delayed_work_pending(dw) && !cpu_offline) { > > + unsigned long delay; > > + > > + delay = round_jiffies_relative(sysctl_stat_interval); > > + queue_delayed_work_on(cpu, mm_percpu_wq, dw, delay); > > Regression wrt V12 if timer is added on the CPU that is not doing HK_TYPE_TIMER? Before this change, the timer was managed (and queued on an isolated CPU) by vmstat_shepherd. Now it is managed (and queued) by the local CPU, so there is no regression. Thanks.