From patchwork Sat Sep 24 15:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 12987727 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 B76F3C6FA86 for ; Sat, 24 Sep 2022 15:22:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 111CC8E000A; Sat, 24 Sep 2022 11:22:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0734C8E0007; Sat, 24 Sep 2022 11:22:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB6138E000A; Sat, 24 Sep 2022 11:22:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C34A18E0007 for ; Sat, 24 Sep 2022 11:22:40 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5D265A0E81 for ; Sat, 24 Sep 2022 15:22:40 +0000 (UTC) X-FDA: 79947346080.12.07062DD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 0D3CC180026 for ; Sat, 24 Sep 2022 15:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664032959; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vx+xKpue7wTXyWig6qL4Y2Lw1zImsNhejs2t+QDspOc=; b=iwFL8+gY+xjbmdhR/Rha5jWi6/n4icTwnLan/h8bu+YzhFsZiVlmiULkpyr5NtcxnifK3T +h3XVAXsdkLxnMtyLz1gSMJmKc1M7gTCRU8o+twDHSn8Zs4arj9duVzwzMnZIItFmftmyQ TAeajTlMXizvOuJnKRDo3t/b9h8Jo5w= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-583-eMxxyPVSNXOwbp4KuN0vCA-1; Sat, 24 Sep 2022 11:22:38 -0400 X-MC-Unique: eMxxyPVSNXOwbp4KuN0vCA-1 Received: by mail-wm1-f70.google.com with SMTP id l15-20020a05600c4f0f00b003b4bec80edbso1624025wmq.9 for ; Sat, 24 Sep 2022 08:22:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=vx+xKpue7wTXyWig6qL4Y2Lw1zImsNhejs2t+QDspOc=; b=fRFYTpTQFdXwsOPC4o976UQBPK1WwruxKIVArVi1TP4CGPpvlHLTrBHwbSzgNnxmMk QHzuvXx7s47xxOKqR31bUyZdoL93HUQG/zlHZI2zcrMze1SCcqvaoMsTEegmUvKgt0rF WtTDDHj1INrclg08+jkeKRBQiUrGQxNH9qgRBr+7uoL35qXn+lblzS+XSeGcEJx029yP JRoiPT66Dind/WB+IfT3RynUClIckJMG8Gcld54rQA+Sghp5rTB3+/it2ZTFr/vVKpl9 dFlIrA82+YfAWxBJfzoglX2XEbpwy6l9SGtILccxYbynZhpNPc7hC2HQ+9oC7/DM32HB 5IMA== X-Gm-Message-State: ACrzQf0CQFRTtugH4mXLp9A3fCENlFsJmPQ+ciJX7Mto1c7+3JTxYBVp Mp4bDCyksV0jNkaQ5lYmA0usFp7AVVfPVdOKm5CAm24tT+02EN2ylgZzfUUBc832xh80L/F9pbC xoBiixh5/dQ== X-Received: by 2002:adf:ea86:0:b0:22b:9f9f:a3b with SMTP id s6-20020adfea86000000b0022b9f9f0a3bmr5684016wrm.130.1664032957441; Sat, 24 Sep 2022 08:22:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4XlRA/1nNXyboTHo5AUkSzsW77JkBgIWvz5OJ8eCCBl08evcHlFngS43fDNqZ1Sk/si/OyYQ== X-Received: by 2002:adf:ea86:0:b0:22b:9f9f:a3b with SMTP id s6-20020adfea86000000b0022b9f9f0a3bmr5683998wrm.130.1664032957196; Sat, 24 Sep 2022 08:22:37 -0700 (PDT) Received: from localhost (cpc111743-lutn13-2-0-cust979.9-3.cable.virginm.net. [82.17.115.212]) by smtp.gmail.com with ESMTPSA id f11-20020a5d664b000000b0022af63bb6f2sm9701817wrw.113.2022.09.24.08.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 08:22:36 -0700 (PDT) From: Aaron Tomlin To: frederic@kernel.org, mtosatti@redhat.com Cc: 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: [PATCH v8 2/5] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies Date: Sat, 24 Sep 2022 16:22:24 +0100 Message-Id: <20220924152227.819815-3-atomlin@redhat.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220924152227.819815-1-atomlin@redhat.com> References: <20220924152227.819815-1-atomlin@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664032960; a=rsa-sha256; cv=none; b=pfiWJ2n1jAFwo/QY/6vIOBi9mQ6uEEcBURBsjoh/OKWSFdXJx2fuEqw3VXk2ymPap22g4e quEvVXoc9xGqOhwUCvfFe3J+LBbUXgRDZx7M24X/WDZJBLZDxAISbajLTuxmRj2pmA7Tiy +kyxyNceMq7HVXS0rEzJq8+BuxJGRyQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iwFL8+gY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of atomlin@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=atomlin@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664032960; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vx+xKpue7wTXyWig6qL4Y2Lw1zImsNhejs2t+QDspOc=; b=nvrG4pALlZzKY2Ux3a4SP5nJSNEb6RHSUDU6Y2ZmIPBekPueZFC6ybqtB+LnpdrbXtJUOw CGqLOp9R3wbykkOprDzxx+p7XbwiRbBHyokln4Bof6Ezh8enQQsEsipmi5fZ/SHF3gDR+M 3EWes3pTi9AXzaZ56OOfAHXyVD5+iE8= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iwFL8+gY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of atomlin@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=atomlin@redhat.com X-Rspam-User: X-Stat-Signature: fa3pdfztbih6w84rj97kna41fm13ykjt X-Rspamd-Queue-Id: 0D3CC180026 X-Rspamd-Server: rspam06 X-HE-Tag: 1664032959-692497 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: This patch will now use the previously introduced CPU-specific variable namely vmstat_dirty to indicate if a vmstat differential/or imbalance is present for a given CPU. So, at the appropriate time, vmstat processing can be initiated. The hope is that this particular approach is "cheaper" when compared to need_update(). The idea is based on Marcelo's patch [1]. [1]: https://lore.kernel.org/lkml/20220204173554.763888172@fedora.localdomain/ Signed-off-by: Aaron Tomlin --- mm/vmstat.c | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index 24c67b2e58fd..472175642bd9 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -383,6 +383,7 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, x = 0; } __this_cpu_write(*p, x); + vmstat_mark_dirty(); if (IS_ENABLED(CONFIG_PREEMPT_RT)) preempt_enable(); @@ -421,6 +422,7 @@ void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, x = 0; } __this_cpu_write(*p, x); + vmstat_mark_dirty(); if (IS_ENABLED(CONFIG_PREEMPT_RT)) preempt_enable(); @@ -619,6 +621,7 @@ static inline void mod_zone_state(struct zone *zone, if (z) zone_page_state_add(z, zone, item); + vmstat_mark_dirty(); } void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, @@ -687,6 +690,7 @@ static inline void mod_node_state(struct pglist_data *pgdat, if (z) node_page_state_add(z, pgdat, item); + vmstat_mark_dirty(); } void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, @@ -841,6 +845,14 @@ static int refresh_cpu_vm_stats(bool do_pagesets) int global_node_diff[NR_VM_NODE_STAT_ITEMS] = { 0, }; int changes = 0; + /* + * Clear vmstat_dirty before clearing the percpu vmstats. + * If interrupts are enabled, it is possible that an interrupt + * or another task modifies a percpu vmstat, which will + * set vmstat_dirty to true. + */ + vmstat_clear_dirty(); + for_each_populated_zone(zone) { struct per_cpu_zonestat __percpu *pzstats = zone->per_cpu_zonestats; #ifdef CONFIG_NUMA @@ -1971,35 +1983,6 @@ static void vmstat_update(struct work_struct *w) } } -/* - * Check if the diffs for a certain cpu indicate that - * an update is needed. - */ -static bool need_update(int cpu) -{ - pg_data_t *last_pgdat = NULL; - struct zone *zone; - - for_each_populated_zone(zone) { - struct per_cpu_zonestat *pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); - struct per_cpu_nodestat *n; - - /* - * The fast way of checking if there are any vmstat diffs. - */ - if (memchr_inv(pzstats->vm_stat_diff, 0, sizeof(pzstats->vm_stat_diff))) - return true; - - if (last_pgdat == zone->zone_pgdat) - continue; - last_pgdat = zone->zone_pgdat; - n = per_cpu_ptr(zone->zone_pgdat->per_cpu_nodestats, cpu); - if (memchr_inv(n->vm_node_stat_diff, 0, sizeof(n->vm_node_stat_diff))) - return true; - } - return false; -} - /* * Switch off vmstat processing and then fold all the remaining differentials * until the diffs stay at zero. The function is used by NOHZ and can only be @@ -2010,10 +1993,7 @@ void quiet_vmstat(void) if (system_state != SYSTEM_RUNNING) return; - if (!delayed_work_pending(this_cpu_ptr(&vmstat_work))) - return; - - if (!need_update(smp_processor_id())) + if (!is_vmstat_dirty()) return; /* @@ -2044,7 +2024,7 @@ static void vmstat_shepherd(struct work_struct *w) for_each_online_cpu(cpu) { struct delayed_work *dw = &per_cpu(vmstat_work, cpu); - if (!delayed_work_pending(dw) && need_update(cpu)) + if (!delayed_work_pending(dw) && per_cpu(vmstat_dirty, cpu)) queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0); cond_resched();