From patchwork Wed Feb 1 19:50:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13124916 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 C8229C636D7 for ; Wed, 1 Feb 2023 19:52:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D25E66B0074; Wed, 1 Feb 2023 14:52:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD64A6B0075; Wed, 1 Feb 2023 14:52:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9DD86B0078; Wed, 1 Feb 2023 14:52:36 -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 A189F6B0074 for ; Wed, 1 Feb 2023 14:52:36 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7A689A0F7C for ; Wed, 1 Feb 2023 19:52:36 +0000 (UTC) X-FDA: 80419770312.23.964D960 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id B95F7180009 for ; Wed, 1 Feb 2023 19:52:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BDQsxnKP; spf=pass (imf06.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=1675281154; 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=5/RVJiIAz9b+9GlCe0yao1cdf4Ljv2ahozjVsA9E+ck=; b=5kZHWN0kED5XK9iyd0tBZyCecxKAjPzh8kt3Lo0Rp1TJ8eQPp3JkPNXKJ7q2OZOKu9ckla P8tVsX60WXDCzRkkM/tvftZYnWwLMZBrKGuMNBHYmcuq0Um1w03iQ+MPmZqoM7B730Cul6 fDzBAaFMuDwf4kQkPP7ivb/Tm5bde/s= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BDQsxnKP; spf=pass (imf06.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=1675281154; a=rsa-sha256; cv=none; b=AyH7qgwqAUNQDChyEDHOhYz3EVsXrxiLmQ5es4S9A15cdcpDe+oi7JByUCfrIA+mouRzA9 ESNCbYPGWSF0vllX/lmZLQSZtoAnAWGE6ZPxHF1A1LWcydiA5f0Yb4JyfrOaAFozGjg2wL GGaZsUaHePnC6gQ72HmxXbJYk/osd38= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675281154; 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=5/RVJiIAz9b+9GlCe0yao1cdf4Ljv2ahozjVsA9E+ck=; b=BDQsxnKP8AoJD8cqa7pHVz1tXMfTXSPLo9tB0ct3KfF0WKT8jAkyEcqAjPQZxXL3G7LlTZ /EupkvZeFsK/BqCEtbUQmmsqa5nvyWvkjsLXNE2StL+W7HIDw5rKb8aPwvWmovMDUc3Zgl jrqfNSdyv3XAlNH9z5XyOpWdkVdh7L8= 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-664-incrzUbIOv2YRg8uK3EuQw-1; Wed, 01 Feb 2023 14:52:30 -0500 X-MC-Unique: incrzUbIOv2YRg8uK3EuQw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 498A32806053; Wed, 1 Feb 2023 19:52: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 059CF140EBF4; Wed, 1 Feb 2023 19:52:30 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 16264403C47C7; Wed, 1 Feb 2023 16:51:49 -0300 (-03) Message-ID: <20230201195104.484635830@redhat.com> User-Agent: quilt/0.67 Date: Wed, 01 Feb 2023 16:50:17 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Marcelo Tosatti Subject: [PATCH 4/5] mm/vmstat: switch vmstat shepherd to flush per-CPU counters remotely References: <20230201195013.881721887@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: qh3nrt6up4gm6jbmd81m5th5zwudzzz3 X-Rspamd-Queue-Id: B95F7180009 X-HE-Tag: 1675281154-800229 X-HE-Meta: U2FsdGVkX1/YnyTSsaRrvtlfm1pM91AqLMsqPr11OP7KIegfWb0AKMSOtwPDR221PveJbMoUmmhqYl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GUzVRhT6nzvgfEt/gheGu3ZMcfFCy3dpkoJvflnu1ED9ZDPsw8= 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 @@ -2007,6 +2007,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; @@ -2026,6 +2043,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) {