From patchwork Mon Mar 13 16:25: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: 13172854 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 C6ED4C74A4B for ; Mon, 13 Mar 2023 16:27:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E7EF6B0083; Mon, 13 Mar 2023 12:27:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1990B6B0082; Mon, 13 Mar 2023 12:27:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF37E6B0087; Mon, 13 Mar 2023 12:27:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CAD786B0082 for ; Mon, 13 Mar 2023 12:27:49 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A53CB1C640E for ; Mon, 13 Mar 2023 16:27:49 +0000 (UTC) X-FDA: 80564406258.11.9285519 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id ED18E20013 for ; Mon, 13 Mar 2023 16:27:47 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eEBEbGe3; spf=pass (imf03.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=1678724868; 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=tZRdfptRFY5Vlp762UsZ6/anX9gl/kIpoSRft9xlHEw=; b=8FshL8+1EPxugY1bJ1Lp0sg8uUEz91W4vI+gjvmS4vKkNs7EZeCGR5Nq7WYAVh6uvjg3hY 010m8CmLJoCE2YHWCVqDlrZIzG3h8JyDZdxk+t1DE12N8vkLK1EluPOcgj1iRfh0E5iJep IOt8VfkSqrhZGmiRtjBAzS/IoTck7XA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eEBEbGe3; spf=pass (imf03.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=1678724868; a=rsa-sha256; cv=none; b=lA77vvUO7bzmNFg2QxuCSf0PiXY13KW4J4FOwZBsB3SovVQrdID9xEi6z98GZK6hUkO7PU k2VqM73tV8fUvwSQer0GLmcfbMzBIfMrt5fqTZtqHxxeiJvuWkyg6LlYVEvEQou2pC5QQH GTm74gEc11sGWSewElAsar/OF8X6zdk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678724867; 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=tZRdfptRFY5Vlp762UsZ6/anX9gl/kIpoSRft9xlHEw=; b=eEBEbGe3YxquFhDpHqybxCrg6Y4Zhd2kEZqdfD12QjhZkrGh9il/u86kOK48NLK0a0i9+6 sV3CYF7pKsj9+fAHILn6u1ZTDfvJoMMlNtpEFuCiQXFYMj07S9Jyr4tfkHm+PXpMI0wAAI KVu/tvWvwkkywdLQ0QF+h0Ite5CgqOg= 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-126-Z4BMmYaWPeK5kERbohyfSA-1; Mon, 13 Mar 2023 12:27:43 -0400 X-MC-Unique: Z4BMmYaWPeK5kERbohyfSA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0022B3814949; Mon, 13 Mar 2023 16:27: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 C6F47C164E7; Mon, 13 Mar 2023 16:27:41 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 38FD44038AB8A; Mon, 13 Mar 2023 13:26:44 -0300 (-03) Message-ID: <20230313162634.509267576@redhat.com> User-Agent: quilt/0.67 Date: Mon, 13 Mar 2023 13:25:17 -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, Vlastimil Babka , Marcelo Tosatti Subject: [PATCH v5 10/12] mm/vmstat: switch vmstat shepherd to flush per-CPU counters remotely References: <20230313162507.032200398@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: ED18E20013 X-Stat-Signature: d9mjkqhuniis35ywkjp4akzy9qbf7cdp X-Rspam-User: X-HE-Tag: 1678724867-476571 X-HE-Meta: U2FsdGVkX18WMsdB3Q/49SxqeM0uDHqF7b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A4GLmp2HApKGavICkKbBLJRJTmqMjPa26UQAzBusZ/lfJdC+YDlQ= 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 @@ -2043,6 +2043,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; @@ -2062,6 +2079,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) {