From patchwork Fri Dec 16 19:45:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13075345 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 4E4D2C4167B for ; Fri, 16 Dec 2022 19:52:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C781C8E0003; Fri, 16 Dec 2022 14:52:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C284C8E0001; Fri, 16 Dec 2022 14:52:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEFF68E0003; Fri, 16 Dec 2022 14:52:41 -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 A09D78E0001 for ; Fri, 16 Dec 2022 14:52:41 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 69C5A1404C1 for ; Fri, 16 Dec 2022 19:52:41 +0000 (UTC) X-FDA: 80249216922.10.118C3B1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id A1F354000B for ; Fri, 16 Dec 2022 19:52:38 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LVsLHdJm; spf=pass (imf04.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=1671220359; a=rsa-sha256; cv=none; b=lTXCew2ltSrblWb2xWav7fiKZDDtuiMZdkrfjFlKHpMBKdqZPxWlEU+aHAss4dQXJpeYMC wbpUxw/ok1JwUjCmZVZ/zZDycrjHURprtF+HLFtCXz0+Hqiv9qGQPuFgnexwMYHwvdggox 3/gxOS3EX6VrBAAZZaPzqkk8XktXt+0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LVsLHdJm; spf=pass (imf04.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=1671220359; 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: references:references:dkim-signature; bh=9wyWU7q9zcUtfqIAPMNd6wk67vz331U9cm7/N6A7Uqs=; b=FVR0pm/xqYZf9Lj4bDyXlx1VoaIlNlbZBA2PTSrkenLcKWm06v9micjyNfJO+bQP4GrJ66 ysV8NDppKTdSnT+Vlu4pePFV159OYJ5i/hwNjDT4SuZg2hxKSjs1x8eUEKrm3lOZZL52ff flMNxW8/678sGYD1AEMov2B1Z9u0QyI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671220358; 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: references:references; bh=9wyWU7q9zcUtfqIAPMNd6wk67vz331U9cm7/N6A7Uqs=; b=LVsLHdJmPCCHQURK/SHNVu4reUstQm6cJ765vUf9BA6Oewl/OT9i5YbO1V9BUv6h7Gcu+1 qffDzImoE28i6M+rv1qMyy25+aiwX6f75aifQllbqmOk0b/glc/dgt+8rdTg/RYdoG22GL pDz5BgcGBZ/7eul6NBnKFeVaLxNCwuU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-59YoxDBaO_aCqgO6Mf_Ftg-1; Fri, 16 Dec 2022 14:52:36 -0500 X-MC-Unique: 59YoxDBaO_aCqgO6Mf_Ftg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28D2D2805585; Fri, 16 Dec 2022 19:52:36 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-3.gru2.redhat.com [10.97.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6250649BB6A; Fri, 16 Dec 2022 19:52:35 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id C7D304269CA80; Fri, 16 Dec 2022 16:52:10 -0300 (-03) Message-ID: <20221216194904.115519799@redhat.com> User-Agent: quilt/0.66 Date: Fri, 16 Dec 2022 16:45:42 -0300 From: Marcelo Tosatti To: atomlin@redhat.com, frederic@kernel.org Cc: 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, Marcelo Tosatti Subject: [PATCH v10 2/6] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies References: <20221216194540.202752779@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A1F354000B X-Stat-Signature: 8stmosdh9p8pshj68paqc97c1dtnfmyp X-HE-Tag: 1671220358-521742 X-HE-Meta: U2FsdGVkX1/9uUNPvwu6uQIQ0b3mHKXKxjTDw+//FKJi0j1qtnurmamRElK6CsjN2jKdzYp7s6louZLxc2qsg+CFYAzp2/mkUHadwXg/SmtqSWO/5hxu9gjtnV/7aVvcOTfuVch6vuI1e3Wz46R0cDRaYfB0fkqLIf2w7uB9yNThCZbctbVlC9kQHS89g4rohY3qdZ71bAu7k+zREER42BZQ2EGSD7uH65gsO2GSo9F1l+Df6qje1/EgdOZc0S6fIZnf2owPWNfH4s+Vfr3AZM5xQyQ6kUbep0LJVfjCYtbKDCdlZ814HiaVN6tgBfc3MFj4yZsSaRxpIGc6qmE0BDs6DN76fPaMwc3JJ92a+F/GefzbQQoXGidyfO7DsMxLKH+gj5VPY/uGWrGZ1HWr3wwsmA1NIhhzWPM/grGN56Z8QwO9++rX+6tcbqG+PwtArR8Qg0WGiDZon8Rz6ZqYlfb/0gLsF0u4vZ+PiAAb+is5gZJ56NXjo0vaIBuOJ/ex6nZaPCneOuRHcY9qbH2UvA7ZhLFCdigmItE1O4eWliX2jtjJfXMCjZuJyZd0gzMvMBukrwr2A0NIQ3hsfYHhrorAut2tIylm9UA7vTZBRTs6QxFiJKZAhtMGnWAsH0tRAhJJEykPAzN8gZKRlAsHDyJ+05IRfALlK2LnNbq/j/GvO1Um3+PKYIHQtLnjGIOZUrfrCpdrhrsNR+Qan8mCIrBT6Rn4bhSKPwx13NIj7YmpvJTBJ25ChyXJQ+oG/Q539oEb9reylyr4Wvk+7k3a+kEHpvsPaQWL1gKW7FHAlfwb3g6JpN8TaPymWBLBl8HM1E1Ax+9jJSN/Ucdmz/KnPwdFfUfc6HZGztFJis05U4g1FqLvD1sPSrYhNj1vLphWfEKB3GgYma7QInhBaO7rKh8nMmo6tQB4T65VawNzbFs= 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: From: Aaron Tomlin 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 Signed-off-by: Marcelo Tosatti --- mm/vmstat.c | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) Index: linux-2.6/mm/vmstat.c =================================================================== --- linux-2.6.orig/mm/vmstat.c +++ linux-2.6/mm/vmstat.c @@ -381,6 +381,7 @@ void __mod_zone_page_state(struct zone * x = 0; } __this_cpu_write(*p, x); + vmstat_mark_dirty(); preempt_enable_nested(); } @@ -417,6 +418,7 @@ void __mod_node_page_state(struct pglist x = 0; } __this_cpu_write(*p, x); + vmstat_mark_dirty(); preempt_enable_nested(); } @@ -606,6 +608,7 @@ static inline void mod_zone_state(struct 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, @@ -674,6 +677,7 @@ static inline void mod_node_state(struct 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, @@ -828,6 +832,14 @@ static int refresh_cpu_vm_stats(bool do_ 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 @@ -1957,35 +1969,6 @@ static void vmstat_update(struct work_st } /* - * 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 * invoked when tick processing is not active. @@ -1995,10 +1978,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; /* @@ -2029,7 +2009,7 @@ static void vmstat_shepherd(struct work_ 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();