From patchwork Tue May 30 14:52:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13260308 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 54238C77B7A for ; Tue, 30 May 2023 14:57:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69ABA6B007B; Tue, 30 May 2023 10:57:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 623246B007D; Tue, 30 May 2023 10:57:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2F1900002; Tue, 30 May 2023 10:57:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 372436B007B for ; Tue, 30 May 2023 10:57:00 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ED489C0245 for ; Tue, 30 May 2023 14:56:59 +0000 (UTC) X-FDA: 80847223758.13.1879122 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 3E891140014 for ; Tue, 30 May 2023 14:56:57 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KSkQgfh+; spf=pass (imf09.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=1685458618; a=rsa-sha256; cv=none; b=bm/ZvThCGTN3GRLCRDclYJW4EhnXDxyPf/KuS5tsOnLgog5fS2tpJdRi41mFZGVTzH8ZCg aLTyoHgAezJPaKirWWHgd5ojFc53dNDJSwkcWDOjDCJE9pQ1IkHfPpygYWdGqYP0q7ukiW 4NOLUWYuG39BgLtUJqWKtkBhDWmcbjg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KSkQgfh+; spf=pass (imf09.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=1685458618; 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=o+BZyclEIaiwakWhfStlzgKt7LvIsSshcDJNqqvHmzs=; b=SvEObPuUS1RL8tiPfgHfdFeP4T49tuLPDaHUL8PrizrYBpqtkJv7ecmX9S1OQUXB7tVW6y 0xs1y9Nm1eoHo1AVSfo7B/E6hKiVHdBfY2lf9MOQ4+yPWCVv67U6lg9oHaYER/krLLDOi3 b3bR5qIYBkNJs05xppf0qB2ivtJXP0s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685458617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=o+BZyclEIaiwakWhfStlzgKt7LvIsSshcDJNqqvHmzs=; b=KSkQgfh+yeC0tBXnSCSCdFjAtw7Y2xareEuh9crJiCe6YF1VLDh1ALjCAFr4tGRM9YR9fH xnktPsWu8Wv6x9rGxwy1/ZpyLEwZ50qgBWRarDuzEeu091NX59wZNwXyVHnrleSl0OyfyW 8sn4z8i3m6WevbUBlHaEyvT5kgX8T1Y= 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-473-XcWcgHydOZqpI-U3YQbJBg-1; Tue, 30 May 2023 10:56:51 -0400 X-MC-Unique: XcWcgHydOZqpI-U3YQbJBg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FBD380231B; Tue, 30 May 2023 14:56:51 +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 0ED2C40C6EC4; Tue, 30 May 2023 14:56:51 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 442AE40195510; Tue, 30 May 2023 11:56:33 -0300 (-03) Message-ID: <20230530145234.968927611@redhat.com> User-Agent: quilt/0.67 Date: Tue, 30 May 2023 11:52:34 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Michal Hocko Subject: [PATCH 0/4] vmstat bug fixes for nohz_full CPUs X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3E891140014 X-Stat-Signature: ciw1i1nwgeiyqpdqk1yn67mqpzu13uip X-Rspam-User: X-HE-Tag: 1685458617-853975 X-HE-Meta: U2FsdGVkX1/AXJfhdECXaQRtUAlY8q7W4r5z5oA58XX4h9d/ksY5X0SyZsdGqJrNAZfnp2PjK+5/ussYyHYU47ooQEj3oCECGmlG9sxQB7ziwTjtsnEifIpj3n3kSy0c0k6bOUBUAnWK5vToNT2MWwldwJ9sxWy9y1ARMlXFrxv91FiPaC0+G7dFL9qRC01cWs+ImVANYflqlBfsFOWz4YOD/vN/TayoKBHQBE7fOC+nvqkx60Fqxx1K4WYpXKhF2buyPxgqaNlsgD8ECV+/GjY5d+vUDqJsLQrMcBz7sTzEzo4ypvZXgFNKUYqcta/umOoc2oFLBIcIEISob4Rf8LaOjaHpOUzO3Bfpqhgu3gryPeLF67iOBZDgf9Ch/RRiTOakcMSt9z/GgiQt3JG9dOTD+uOe/dnwZKoHJ2DY12ZGpY2dE9SK+sKTrGti+oQzKWUq2D5BWAi1lxLDRJgeU7FC3eb6PUHdiXR1c70un3KkBGX9dek1gDENN1u0VUv06GRiXeBSRoZhgxa3YOCeDilWw6Rf2sdMxUPS3qtPnjAOV4kH8j2+yXP8vtpGO9Fit0HaFSXCGeagmmf0MShE/x/cAbR2hWhXnbDt4OY6UcZTlI51DSBvKtds1iBDh6NUq1OgbFC89ZkQ9rZPB8Hm5UmZtpYkv1XyXgv0Od9xdG+MIAnw29byYAYRPXEbeZQiR359mnuI3m67qAKQDWOTHFwY+ocGHg3Ic3E4MUKE1oMG37+V+N685eKMZRdtewrLdzC3/+mhfIGo6HVu90EUTnaaYt9kgcxDYHGRPfMSTtsjShBWHGZbNh8TcOQm/oqf3br9hqrJ6nkpnjkJTdwWVj6bsahDz7bQ42BIpzcL5gYFCHKeH//t9gSqYB9mKepA3noSCockEkJEpopzYtfE9LToDNIu1MRq8inZOIH59XXMzKfDTLBuGMODb1DwmPl0KeJoz6S7ey9sY9sd3Q5 MgQORPox bo8gJyXj7Wkdzk/tVqxc717NBMxwAnrlFbLnt/3dFZA5WsS8Up4RhaspV9s8d6KQ+q+za1OIHHtArBxSESUJlJqxPBkfjySgaRMlgCC6ZjNNPA2IIExFHZtMoZirJpTXE5Ew7t5PiGpNXGQnS4c5+loav/l9Vh/wBa039 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 indicating that a process was stalled in direct reclaim: - 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 task that busy loops on a given CPU, the kworker interruption to execute vmstat_update is undesired and may exceed latency thresholds for certain applications. First issue is solved by using _snapshot version of the counters on allow_direct_reclaim. Second issue is fixed by disabling periodic vmstat updates for nohz_full CPUs. Thanks to Aaron Tomlin for diagnosing issue 1 and writing the initial patch series. Performance details for the kworker interruption: oslat 1094.456862: sys_mlock(start: 7f7ed0000b60, len: 1000) oslat 1094.456971: workqueue_queue_work: ... function=vmstat_update ... oslat 1094.456974: sched_switch: prev_comm=oslat ... ==> next_comm=kworker/5:1 ... kworker 1094.456978: sched_switch: prev_comm=kworker/5:1 ==> next_comm=oslat ... The example above shows an additional 7us for the oslat -> kworker -> oslat switches. In the case of a virtualized CPU, and the vmstat_update interruption in the host (of a qemu-kvm vcpu), the latency penalty observed in the guest is higher than 50us, violating the acceptable latency threshold for certain applications. include/linux/workqueue.h | 1 + kernel/workqueue.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 2 +- mm/vmstat.c | 11 +++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-)