From patchwork Tue Mar 14 18:59:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13174924 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 314B0C05027 for ; Tue, 14 Mar 2023 19:01:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 914AC8E0002; Tue, 14 Mar 2023 15:01:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BA178E0001; Tue, 14 Mar 2023 15:01:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 609978E0002; Tue, 14 Mar 2023 15:01:11 -0400 (EDT) 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 463F16B0075 for ; Tue, 14 Mar 2023 15:01:11 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1FD481A0AE4 for ; Tue, 14 Mar 2023 19:01:11 +0000 (UTC) X-FDA: 80568421542.13.52679B8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 2BCC014003B for ; Tue, 14 Mar 2023 19:01:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ANUUVsj+; spf=pass (imf09.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=1678820468; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=AyHd4n90cFHn3Luv5sQXSwJ2Z0MI24C3Jhi1jfEoG60=; b=Cy+XZYPnxQWekj2T3KrrbOTUxC31jhQrqFQPsta4Dx4wxqe2N09c/4HXw8dJoIjkWNQyZM rISAnASCdxva206Wj0/kzk1uFcaOWwHgN/Kz7MX1rUyvUQc5PVQb4l36fCOw0ymjCxSIDq R3qxj7z4TOKu/fTmRo4wfN+HavVfhpk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ANUUVsj+; spf=pass (imf09.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=1678820468; a=rsa-sha256; cv=none; b=NEj9mPWT9StWbXLNPdx8qEqwVyB8IpfPHs+ABUgATXepXhgHG35GbSuN7MF93xcKwdhjrc j5fxW20LodhdZeNYcOYRjumqHavlwj3fPwC50L0N6wAxJzCT67X7n1Q12DNsUzmMFGG/Cf Jkjjlg+I3sGKvP4LeIMvVrbI1zcDF7s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678820467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=AyHd4n90cFHn3Luv5sQXSwJ2Z0MI24C3Jhi1jfEoG60=; b=ANUUVsj+wjYsaUNYX48UVy/r4A06t6kBJ3icFmcd/UNXWzmjZYjKAcFE42BWPd8ys0Wf1n 2qLz/A5+IhIvrF+RL7etSpY2675PvJH+6w9rRoQPaWFQG4smaByYYMCrQ9vC+IpcZWPOZP DWIPzPZ1diW0mm/ky38FIPRQzpXKVzY= 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-232-ysHsOFL6P62V2VFkUCAX5w-1; Tue, 14 Mar 2023 15:01:04 -0400 X-MC-Unique: ysHsOFL6P62V2VFkUCAX5w-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 A18D8857AA4; Tue, 14 Mar 2023 19:01:03 +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 4B21A1731B; Tue, 14 Mar 2023 19:01:03 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 520C34038EDB3; Tue, 14 Mar 2023 16:00:44 -0300 (-03) Message-ID: <20230314185914.836510860@redhat.com> User-Agent: quilt/0.67 Date: Tue, 14 Mar 2023 15:59:14 -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 , Michal Hocko Subject: [PATCH v6 00/12] fold per-CPU vmstats remotely X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: thyf3xyq9ienma5g1ay4jm8ysy1ket6r X-Rspamd-Queue-Id: 2BCC014003B X-HE-Tag: 1678820467-311780 X-HE-Meta: U2FsdGVkX18gvRNaCW+JSTzuueg/wBSHcjk/J4Mvhy9NqrZgjZ+5ai4+toF6X+omlv+bUKOifSXGaiIdgZ421RfHfixa6Ij7373F/GInItTbE47bPHmNiKYBtKn1dVqZun3/4/svtfPYuvyT5g0BrGwALpIQvCMVnDjVQUGFQrSKP2o4th4ywNOhlW974qK0U9Gb9XBToKKxwS/KHY+gMf10x53gMPJ2YuStmKugb0WmMPThwUqciWW84Uh6RnYrSyX8004YbMSOpICxU3sd1S6o6YBsD5jRg5kmqRA/54CRe5kOnmjfrLHMMUZNqu4drEqQCQ5iIUyB3YgeXCMDE90jt3y/c6yiQafk2fDsFuWMYbDHqQG8iyVrv59inoeQHJGSx7UUbz8J8VmDMPQVhEa2dnJyYx6A+N8xASibFLxxfcnsnzKYNSbyULxUpCMZyy+rUbvj7B+sAwM4n13aMn1YnYDDFkBEEyPIoS5MESvQkmk4Ggeep90SOqpR97VAaygXYn8yqyfpk50CeqMJ+szUwqw3lY4J1H33dlgznstSE0iGHgnGn+sgVWg9EeBTiTsFMrHJhFyxiIwiT+thIPaNPPhLl+KWuYOSAAtN3k/XU982UgeYGmhtnxSxQWMeyOnWCz+nhU3sD9zQqb2oan48wBNAEt8tOsT807DjWJVM0L2anK0t4yt2zT20rzdEoO5Q19rhrWiVNWhSdbVq+JapqCScYjmvArMKjsp1pI5BIPFvJtyg1of7ks1fLejHOjk8yfBcA1lplDqCkhME/6PrFOxkTndpWu9g5VaIHWcj02u+As+bQfXw8G0fq0NFXv++0yznE4ykZM7cZvkmdCebHcLie1r3hSCEK/A1ZwexBNhNrMvf65o/Xg5Rj+/vPK2k70dHeUoaLW3XdbJbLH+RLQaM/DHUSZKrCxQsFksT79SxC1pxqPzAyKsHbHRe2tlFj7NfvyCn/slNgBg z/QN7DQc E8IYrgFzWQ7ZCYI7S5n/ejagZnyxGZ0mAlSfqCweMGAif0d7dy6WDwvaq4Lbr1huvJNtdxl2oPTlfxj0ioTpb9yCPwb/kDSGffFCUL+AqE5xs/sXQp1kOfuZuwbK4+HBuFmkW 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: This patch series addresses the following two problems: 1. A customer provided 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()). The evidence is: - The process was trapped in throttle_direct_reclaim(). The function wait_event_killable() was called to wait condition allow_direct_reclaim(pgdat) for current node to be true. The allow_direct_reclaim(pgdat) examined the number of free pages on the node by zone_page_state() which just returns value in zone->vm_stat[NR_FREE_PAGES]. - On node #1, zone->vm_stat[NR_FREE_PAGES] was 0. However, the freelist on this node was not empty. - This inconsistent of vmstat value was caused by percpu vmstat on nohz_full cpus. Every increment/decrement of vmstat is performed on percpu vmstat counter at first, then pooled diffs are cumulated to the zone's vmstat counter in timely manner. However, on nohz_full cpus (in case of this customer's system, 48 of 52 cpus) these pooled diffs were not cumulated once the cpu had no event on it so that the cpu started sleeping infinitely. I checked percpu vmstat and found there were total 69 counts not cumulated to the zone's vmstat counter yet. - In this situation, kswapd did not help the trapped process. In pgdat_balanced(), zone_wakermark_ok_safe() examined the number of free pages on the node by zone_page_state_snapshot() which checks pending counts on percpu vmstat. Therefore kswapd could know there were 69 free pages correctly. Since zone->_watermark = {8, 20, 32}, kswapd did not work because 69 was greater than 32 as high watermark. 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 By having vmstat_shepherd flush the per-CPU counters to the global counters from remote CPUs. This is done using cmpxchg to manipulate the counters, both CPU locally (via the account functions), and remotely (via cpu_vm_stats_fold). Thanks to Aaron Tomlin for diagnosing issue 1 and writing the initial patch series. v6: - Add more information on throttle_direct_reclaim problem to commit logs (Michal Hocko) v5: - Drop "mm/vmstat: remove remote node draining" (Vlastimil Babka) - Implement remote node draining for cpu_vm_stats_fold (Vlastimil Babka) v4: - Switch per-CPU vmstat counters to s32, required by RISC-V, ARC architectures v3: - Removed unused drain_zone_pages and changes variable (David Hildenbrand) - Use xchg instead of cmpxchg in refresh_cpu_vm_stats (Peter Xu) - Add drain_all_pages to vmstat_refresh to make stats more accurate (Peter Xu) - Improve changelog of "mm/vmstat: switch counter modification to cmpxchg" (Peter Xu / David) - Improve changelog of "mm/vmstat: remove remote node draining" (David Hildenbrand) v2: - actually use LOCK CMPXCHG on counter mod/inc/dec functions (Christoph Lameter) - use try_cmpxchg for cmpxchg loops (Uros Bizjak / Matthew Wilcox) arch/arm64/include/asm/percpu.h | 16 ++ arch/loongarch/include/asm/percpu.h | 23 +++- arch/s390/include/asm/percpu.h | 5 arch/x86/include/asm/percpu.h | 39 +++---- include/asm-generic/percpu.h | 17 +++ include/linux/mmzone.h | 3 include/linux/percpu-defs.h | 2 kernel/fork.c | 2 kernel/scs.c | 2 mm/page_alloc.c | 23 ---- mm/vmstat.c | 424 +++++++++++++++++++++++++++++++++++++++++------------------------------------ 11 files changed, 307 insertions(+), 249 deletions(-)