From patchwork Thu Jan 5 12:52:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13089807 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 3861DC3DA7D for ; Thu, 5 Jan 2023 12:56:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25332900003; Thu, 5 Jan 2023 07:56:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BD0B900007; Thu, 5 Jan 2023 07:56:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D325B900003; Thu, 5 Jan 2023 07:56:48 -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 BA930900005 for ; Thu, 5 Jan 2023 07:56:48 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7EEF71A0D28 for ; Thu, 5 Jan 2023 12:56:48 +0000 (UTC) X-FDA: 80320744896.30.AA4A621 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id E4C9640004 for ; Thu, 5 Jan 2023 12:56:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e0KcPP9w; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.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=1672923406; 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=AWWNy27PnDV2BzrRi18CQGy2pR4xt8zt+F15YzdMHas=; b=B2h20QVETkFrkIMGOpSM/tESFfftutBkipV1sWztM+ZmA/hbyfdDFr3v8prd6enKH3tAlT vjsB81bcmsPC3TMozR1jhXXp7a3LOiYKkoTbhg/XgGS4g9ZUwE3BTOHPGvsLBSAK0K5WQk 9mrc6vBNTOghgngcdYGrFgMcKpqgxDc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e0KcPP9w; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.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=1672923406; a=rsa-sha256; cv=none; b=o5te24S/3gwuhn1NBkuWjMwoikGZ19y+1RVrbiRrN0AtyosEfYi8QQ9PjoWxiWKQWiRP4T eGOlbSWjBJ+cxc0L8f3C83bCmKgY0wXM2SFvY5W7Ztqc0nd7vr+vxePcbWUZyTMdxgM2oQ XHQgn+dtWXDEYPAf+OeyMRsVvUOE/zI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672923406; 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=AWWNy27PnDV2BzrRi18CQGy2pR4xt8zt+F15YzdMHas=; b=e0KcPP9wqxdWVV0zbR0iSSuB6efDhXeY/iNAAryZCN7Ikg4x5q2t7g7rCJSS++XRJVX6JE UIAnpXmkoPH2vqJ3I2lZSHaCBUnEMysbNioGxwxFzU1U5DfMSJ4X3V/9lPlC+YQpO6rD68 45Ptab/DoQ1UKXnF+ZLrWuH2efBEo7Q= 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-191--cpSVXu9NI2oKV4L1YUfng-1; Thu, 05 Jan 2023 07:56:43 -0500 X-MC-Unique: -cpSVXu9NI2oKV4L1YUfng-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD5AD80234E; Thu, 5 Jan 2023 12:56:42 +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 4916153A0; Thu, 5 Jan 2023 12:56:42 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 98FF240502F3A; Thu, 5 Jan 2023 09:54:47 -0300 (-03) Message-ID: <20230105125248.813825852@redhat.com> User-Agent: quilt/0.66 Date: Thu, 05 Jan 2023 09:52:20 -0300 From: Marcelo Tosatti To: atomlin@atomlin.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 v13 2/6] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies References: <20230105125218.031928326@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Queue-Id: E4C9640004 X-Stat-Signature: mw5xnt5b8mpaq4iqz9o8x3njxmteigk4 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1672923406-389981 X-HE-Meta: U2FsdGVkX18aofFnymHD2a4W3GEeY/V5e4vvkmvJUA4jec6r1lYLf5IUzxkljJaXqqPRbUTtNlER6KRpY2zhXybFDUQNsgcRJUhRSzJB+m+5/W8/206UgtOFzf4yTTqNSBrHLjKYoG6WE/UQhyUS7uGpCMP74saH46S30KvyJsf6VQRWQHjZ6dxxpwysYrhEEyZk1wdQczS0aomTrl7vZkDroV0lXtlYHnxAM7pqbbPDqdlqlpQqr0SCB/mdHxo9pFxt8/K0TlkC+GlGUDm3zZ38pduJIq5y3DUdLJ3jdjHx1SkKyye/GxtdNQADcwodqpRMVqNdZW2C50P3P05WbBKtKP1U06LgkXJ7fFD6k2Y3jWTYdb5Ar7WIsv+J9+Xc0FMrt/WnWhyOkL55EI+h9vzbLcPy3TtnCvNdWB1cLd1niIx8j3EFnlplOGkOuJsi9haxNEWP6CUQo0K6gUq3f6SOFoTk9iuYSZtfYD31mVeqUCnnosqwX8GD93Ip/ZD2ZQfjFtQybv6YZEFyv6WFlEk9J8AgPFaL0fv2k1byIL1NxN7/sAgWrv45g9+QhhlmY8D1cMFvkYCJ2NFqkpMoc9qHlxSO6jhvVAylRe8391FbKN5PLBUe1drmNKlqJChtopYbkqOjrLpc3zsJmipphjzy3ehMu15xyQvp7aHGxXwT7p1DZ1UCM2rVwt7bpxAXzVp+e/hUwtSWCx7HaIwITXs8GpJ6DsD5OWnZ+w6FcHCzOO/ypkkQ6lmJLP3+nPl5LfThB0jnPEG5pKYsjHF4GK7XN9z1brZTqjE5BOpZ3z0qdquKGHCAchWMHBc7P2Hey3/eJhjlMAOmemN6L1Tf9DeBpXOOL+pxNCwfbi5iZwVslkxqNWq18FvgVhRxxqddmUeM8EvISbaPTYorzx+xYA42Lxqm86l5kZn3QygHqRg= 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(); } @@ -577,6 +579,9 @@ static inline void mod_zone_state(struct s8 __percpu *p = pcp->vm_stat_diff + item; long o, n, t, z; + /* cmpxchg and vmstat_mark_dirty should happen on the same CPU */ + preempt_disable(); + do { z = 0; /* overflow to zone counters */ @@ -606,6 +611,8 @@ static inline void mod_zone_state(struct if (z) zone_page_state_add(z, zone, item); + vmstat_mark_dirty(); + preempt_enable(); } void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, @@ -645,6 +652,8 @@ static inline void mod_node_state(struct delta >>= PAGE_SHIFT; } + /* cmpxchg and vmstat_mark_dirty should happen on the same CPU */ + preempt_disable(); do { z = 0; /* overflow to node counters */ @@ -674,6 +683,8 @@ static inline void mod_node_state(struct if (z) node_page_state_add(z, pgdat, item); + vmstat_mark_dirty(); + preempt_enable(); } void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, @@ -828,6 +839,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 +1976,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 +1985,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 +2016,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();