From patchwork Fri Mar 3 19:58:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159452 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 A7AE4C64EC4 for ; Fri, 3 Mar 2023 20:00:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8A696B007D; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEB8F6B0080; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB35B6B0082; Fri, 3 Mar 2023 15:00:40 -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 977C66B007D for ; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6689D1A13E9 for ; Fri, 3 Mar 2023 20:00:40 +0000 (UTC) X-FDA: 80528654640.06.98213F2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 4A3611C0027 for ; Fri, 3 Mar 2023 20:00:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677873638; 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=tHAQYo4aXRrl160KH7pJqqqPegg14fiAPRCJhIKS8fE=; b=2aovifAI7Zk0m8WtK8e8YT37uQNl+xjx0yLUMfmgiSlxa64XYlBgwFdj2MEUtelm7Z0Xvh xQ0v8oUK+UnDTCKgrikFEyeY+W3b7pJpqBgzgRdIM302hl2Kflrt4ltaH15s5AZ4Iai/hy Oeki/3HG7dPMI/02OAsCAMs/rBkJ7Wk= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677873638; a=rsa-sha256; cv=none; b=FiVs7bft5VXmKpynaECOz/HcsUM0oFEXPv0yg5gHcOofbOScy7Y/j2/FRTt7l1F+xXIzCV +HYUDr8ujab71S2UNAVydRzm+DZv/DNAbFp9kgnVb3f/rnP2NGBa/Qb0oPEJNeHwYXkJSD GPUz7KanpDKhkPqkEtQb9/bZ5F1NxVk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873637; 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=tHAQYo4aXRrl160KH7pJqqqPegg14fiAPRCJhIKS8fE=; b=C+SMje5gYEckt1DDg+VAbZ4kji2VGss2AxngIGm0PVUznX4w0ZJWiw6wznDXoga+Nb0aap kCJ7eW2j0oRtWnNTGr4QfpiJde/OFZXHJEA+Puqlw1m2lezcRGtJ8QFnCuh8v5/S7rdLnC 1n6cuAMJuO7pYtd9+kEJ/8QOC1oA9b4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873637; 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=tHAQYo4aXRrl160KH7pJqqqPegg14fiAPRCJhIKS8fE=; b=C+SMje5gYEckt1DDg+VAbZ4kji2VGss2AxngIGm0PVUznX4w0ZJWiw6wznDXoga+Nb0aap kCJ7eW2j0oRtWnNTGr4QfpiJde/OFZXHJEA+Puqlw1m2lezcRGtJ8QFnCuh8v5/S7rdLnC 1n6cuAMJuO7pYtd9+kEJ/8QOC1oA9b4= 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-294-29M75UO_NkSSiK0Vpi9pvg-1; Fri, 03 Mar 2023 15:00:31 -0500 X-MC-Unique: 29M75UO_NkSSiK0Vpi9pvg-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 55C1A803491; Fri, 3 Mar 2023 20:00:30 +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 2861A492B00; Fri, 3 Mar 2023 20:00:30 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id AFB1442919633; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195909.003776725@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:51 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Russell King , Huacai Chen , Heiko Carstens , x86@kernel.org, Marcelo Tosatti Subject: [PATCH v3 10/11] mm/vmstat: switch vmstat shepherd to flush per-CPU counters remotely References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4A3611C0027 X-Stat-Signature: ar6b8ycisn66xwp38iyrt79ufudu3n4s X-HE-Tag: 1677873638-794624 X-HE-Meta: U2FsdGVkX1/oJb9pUxKsHer94XWc9whqf4kM/D/0KJW2mNksYiNwKOHFpB34dj4YpGtH/mBNak6vwnwmBURMxT2AN8EcjxovwtKYP8yjfKfUOLoEqTEZb3bIcFq9pJlSQCpCOZ0R8ZIHcrsPp3IcYQXRq9ts/DKgs9J7GsWtYfPdMDCRRDzPxiAv4Owqc7YTwVy/Oa55KIlJrCW/77NOlc0EGYQpMjfxiplC/bSk5VTx8qpZmrDOa1Ik6lhYGW0OUR2jxbi2ICefG8887xNSCZp6LpbsAJjJxtflMjuv3Wv3ZrFVUeQ8PHCOJNW1FO5zC3BPyJG5F9kychru2sesHJDfpqEh6p279FBjtQQ+JzgPswNyjN6wfei9LwStYbyF+JYsrpPqJ1Bs3V0xYqa7UDObXbrBFzVpQvzhkOEFPYpmCuiWdX03Arbd5QrO1uZP5D3ENntwrigADU1zJwkI5E9IPReHeT6YAEHE4qg+cxntmQGNJnQrIAv+I0onkt3ILhsJdPrKJHXRBybopMT1YSl/vWBbgvaGOT5qspZO2uN5eCmmBHkAUkZWWtrEl8vibLNaxk5FP8wCID6fwW+w0mDbYzy2ZUcF4sEa65KrV7JizWrCSRPoTjF+4AysitX+DSX7utxkrHM7X43ML5NRzMyaOEPP3Qq+IEAXUXZPPjc3TQr5I9XsGxbCGG7ccEXD8r1nO+NRoc74r/RfEU16F2A9H+uzqvgmnUGx/042RKqa0xKPkZ9QMxi/BC6Q3Lv8AfeRNpKsqk813kMlRvbw5B7DJ6voRRPocjBcdGzvhn4ZlmYs8vAaQFhCVV0/ly2ipd9BETVVQfPej0lc7/Q/tE3MPf7anyT9JolsiwadRWMppOfpdaHCGHXT4FpxR5BwxnkBKNtavRHVcbUuJBuxgJe5qzqpQsFhIAwBl/2/R0ONMaj0vGSeBm58f0SyWcJErvOtaCete1agDDCOVEW 2/DeORwY rsxJB6Oz1jvx0M+mqKL2IjJnruPtJIAtA4DDK7E9PxTgXftHncqfV4tBMWFQxjGS+6DX9L0nsaaY7N3YXsU98EeDJ7Mr8EeK1EqhbcHINK9KmJJHfrEOVVCKCUmpFMK8snYIwpzP1WshUkAoaNH6LE2pY682fwHhvfNxw1/YVzxIhQq9hZVqWqU6UT0HSBJX/EdFdGVqV7OCIHnM= 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: Now that the counters are modified via cmpxchg both CPU locally (via the account functions), and remotely (via cpu_vm_stats_fold), its possible to switch vmstat_shepherd to perform the per-CPU vmstats folding remotely. This fixes the following two problems: 1. A customer provided some evidence which indicates that the idle tick was stopped; albeit, CPU-specific vmstat counters still remained populated. Thus one can only assume quiet_vmstat() was not invoked on return to the idle loop. If I understand correctly, I suspect this divergence might erroneously prevent a reclaim attempt by kswapd. If the number of zone specific free pages are below their per-cpu drift value then zone_page_state_snapshot() is used to compute a more accurate view of the aforementioned statistic. Thus any task blocked on the NUMA node specific pfmemalloc_wait queue will be unable to make significant progress via direct reclaim unless it is killed after being woken up by kswapd (see throttle_direct_reclaim()) 2. With a SCHED_FIFO task that busy loops on a given CPU, and kworker for that CPU at SCHED_OTHER priority, queuing work to sync per-vmstats will either cause that work to never execute, or stalld (i.e. stall daemon) boosts kworker priority which causes a latency violation Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/mm/vmstat.c =================================================================== --- linux-vmstat-remote.orig/mm/vmstat.c +++ linux-vmstat-remote/mm/vmstat.c @@ -2004,6 +2004,23 @@ static void vmstat_shepherd(struct work_ static DECLARE_DEFERRABLE_WORK(shepherd, vmstat_shepherd); +#ifdef CONFIG_HAVE_CMPXCHG_LOCAL +/* Flush counters remotely if CPU uses cmpxchg to update its per-CPU counters */ +static void vmstat_shepherd(struct work_struct *w) +{ + int cpu; + + cpus_read_lock(); + for_each_online_cpu(cpu) { + cpu_vm_stats_fold(cpu); + cond_resched(); + } + cpus_read_unlock(); + + schedule_delayed_work(&shepherd, + round_jiffies_relative(sysctl_stat_interval)); +} +#else static void vmstat_shepherd(struct work_struct *w) { int cpu; @@ -2023,6 +2040,7 @@ static void vmstat_shepherd(struct work_ schedule_delayed_work(&shepherd, round_jiffies_relative(sysctl_stat_interval)); } +#endif static void __init start_shepherd_timer(void) {