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 4A4CFC3DA7A for ; Fri, 6 Jan 2023 13:01:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC9B38E0002; Fri, 6 Jan 2023 08:01:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A791E8E0001; Fri, 6 Jan 2023 08:01:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F4828E0002; Fri, 6 Jan 2023 08:01:31 -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 7B8C78E0001 for ; Fri, 6 Jan 2023 08:01:31 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 24B311C5682 for ; Fri, 6 Jan 2023 13:01:31 +0000 (UTC) X-FDA: 80324385582.04.A5308E1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 025E5180022 for ; Fri, 6 Jan 2023 13:01:28 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XqHNU1Cy; spf=pass (imf16.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=1673010089; 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=ym1HIba5hHhgKrJESNW1DYb3f7111AlEKPxGR4GLiE4=; b=oHUOBzyB15BL8jE6lHivnF4d1it4+Hz+tro66tKOCZBruRg1n0fyKGdzVrI0ZVDFb8l7rV mGwbFUxIlzGhxaGbBLaNB8wuzl5/OtznRutenq/68iVOPJW7RJrIEx+z6YyArPhRF0Ab0w NNBgi1WU8MwPn7mybFikfqjJ+Uirb80= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XqHNU1Cy; spf=pass (imf16.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673010089; a=rsa-sha256; cv=none; b=xI/x44t+qByRKBy0At/fyLdLW6f3pQ2JIuj6f9V5ztZYROoNZoN1fxdSP7AE5lyD3nAJ4n uGBLl4ah8ZRPIBktn4c467Q3Kj1uRdy6CQgq2dDBZtRIjA9pCl/hBs1+lDLMBNCi3fnKNY 78khCUzrc8nzK2kfCI9IPx5aA5RFY5c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673010088; 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=XqHNU1Cy7suQYkw0AuP9ObCUv+3KrAz9g2x1oJH00GmHcNApn5ZHPGYEfnv0XpB9i8zVVL SgwlxD0S6K9kf+Z4ovKFWnZBMRMPRM9BYoaIW+U2Q+/a873LGkPUIXUfUNqhWAJpfR+vPk d7KXJoUAGZtnpFBKYGpWXyGgFsgkoPk= 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-Stat-Signature: 3gnf6yaw3izz3756i9brazdmeqxeg1ta X-Rspam-User: X-Rspamd-Queue-Id: 025E5180022 X-Rspamd-Server: rspam06 X-HE-Tag: 1673010088-790032 X-HE-Meta: U2FsdGVkX19mtrrNlu1pADxrh38M8WYoD80qGiCvlhMPJHXhDv+aexWHsRVvT/+9DZNJpVntNMliJqD/25zzI/hEEq5Q4vH/LEBmKTJYUCONN7y9k8s5PoYNdHPngXckSjSNHy1p69yFoIeZ9qQAVrc58QdI891S9lCiwSuT6HjIelCjhr4KpPWb6/SHe/Jd69BpYnBAoLJI1cA1pGUtdfqKLGG70p7zpL4kEPH/gs5V/ilWblL+tiMdlUlHn53HPcVbkL/FJtWrXj27nAFJx7bUP7byJzQgpMzKtPR8Y5xtJy9E8AydXxZ3MGg2u/DlRTZH/Affl+Elq0qGTMjxzzwTV4C5Zw+rDOBAE9EICZSlCWeinFwMWIMnfl9AjFllS6mBWRGDMQpStFjipsIaFRfnC0rUP5IwO5uIb4f7Su4z8EYdU61Ha8x0QrqPVl7x5JkMit6Df4w9eebOOm5FniE4P95pnK6plxPkzU80sFyZepOxNLOAdOYrVeziH13R4v2zxWtZ02bDmMea6ZpRZNFv1E4re60qiLANQSA7sLwyW4VKSSXyEq+hGDwnX1WQH7O/VnE431XHqgum2AexG98ruDwmYjMjj32CyLzL9ShN9xgBbR/eqEPCwGaQu2WxpGRaIE2wVy4mBkhxCSJnWCH7+AiZX3NqyLS/zZ2tRp3pQm0znHSUbcSL4+wWw+1fbpo4M1uWoQXZqw5FdaMIILs3kHZXADUxdtJEYXQ8lHHqtETLjGutnO+MwZsMlQvP1qB9Vt2s+rkLddwImp/P3lhDHDvrgnmlEU0FZffH3Wx7YRmv44p1zAFIVkoMQf5ht2/68P/Xyi9s+m0fht7YGqxM1crWlL2wOb/ruS4WdChrhCweqAm3MA== 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 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.