From patchwork Mon May 15 18:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13242021 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 A8CE3C7EE24 for ; Mon, 15 May 2023 18:04:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74902900011; Mon, 15 May 2023 14:04:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FB0A90000D; Mon, 15 May 2023 14:04:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59B9C900011; Mon, 15 May 2023 14:04:08 -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 421B690000D for ; Mon, 15 May 2023 14:04:08 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1175EA112F for ; Mon, 15 May 2023 18:04:08 +0000 (UTC) X-FDA: 80793263376.08.584EF96 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id C63BD1A004C for ; Mon, 15 May 2023 18:03:45 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LPwbOa+F; spf=pass (imf19.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=1684173826; 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=g+P2pLjwIHGTBC73R7sGDBbFogsWx67Df0W2nS+tUE4=; b=G2JKKWNDmtLivdPEpGfq7+QlijhXFHZsYf8zk6mELyZ2k4PUcIYcyOJtQcME0F+wDODzf3 Ko9jNQMp1pjtX06X2sYaFZTNAp7FUoEv6P3OK7VoZHPvO1QxG2CDead6pSc/xntO5QtEoe erZARw+M6yAB7dtP3wUp2H9tPRUuq8M= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LPwbOa+F; spf=pass (imf19.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=1684173826; a=rsa-sha256; cv=none; b=PYZCdckQgd9zhVMPFO7zn2uYMHIXUBBBBoVC4CxvcGfnjniiYraRiWLEclWEf4B3uC7rzp KR99b2ga57qNeRCKa2X0I8p+5+tSiKQTuBtEWycY7IFK9nOVncGuOInU+KJrMZmZ2TBxAA bLRXiDDRqP/c7qa8oFbJvMz49OzQdPM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684173825; 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=g+P2pLjwIHGTBC73R7sGDBbFogsWx67Df0W2nS+tUE4=; b=LPwbOa+FUHtn5dV0EVawj0fifNw7JpIAoitJ2UHiMyeGaeKJf7KcKgEpRrkn1+LfFLd7C0 ctaphAaz/P07I+aHRO6n58/etDGoURVIXopA6jCPNbUwbxPu9rq9bcBfUpFPNpusfH7JBk WU1RKOnEMtW16pDxu/GRr8kquCZDcYQ= 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-605-3Deovc6xNXishRmnvXFshg-1; Mon, 15 May 2023 14:03:43 -0400 X-MC-Unique: 3Deovc6xNXishRmnvXFshg-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 2844F87082B; Mon, 15 May 2023 18:03:43 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-4.gru2.redhat.com [10.97.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFB9040C6EC4; Mon, 15 May 2023 18:03:42 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 40D304161E50E; Mon, 15 May 2023 15:02:17 -0300 (-03) Message-ID: <20230515180138.442505633@redhat.com> User-Agent: quilt/0.67 Date: Mon, 15 May 2023 15:00:16 -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 , Marcelo Tosatti Subject: [PATCH v8 01/13] vmstat: allow_direct_reclaim should use zone_page_state_snapshot References: <20230515180015.016409657@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C63BD1A004C X-Stat-Signature: eaear97rz6xng3xqn3q1jx5ompqdebgm X-HE-Tag: 1684173825-527701 X-HE-Meta: U2FsdGVkX19xZJwEYsefc4vAWsBngi6bqxm/IxOMl3tz65D9GLMJYtzb8M361QonabiONngFPhfhCZvn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EiKyeGw7VYcwW+Oml+5Ssyi7JPxJMdWT/znRSpmgxkHlfgQvf1c8So2lVDEefYQ24RsYV75UpbQFc2W+cJ4+rB4W9Td1VZioOkkm4ZJfQuA9TcFu4pC0cI1LTkGHT1 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: 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. Change allow_direct_reclaim to use zone_page_state_snapshot, which allows a more precise version of the vmstat counters to be used. allow_direct_reclaim will only be called from try_to_free_pages, which is not a hot path. Suggested-by: Michal Hocko Signed-off-by: Marcelo Tosatti Acked-by: Michal Hocko Reviewed-by: Aaron Tomlin Index: linux-vmstat-remote/mm/vmscan.c =================================================================== --- linux-vmstat-remote.orig/mm/vmscan.c +++ linux-vmstat-remote/mm/vmscan.c @@ -6886,7 +6886,7 @@ static bool allow_direct_reclaim(pg_data continue; pfmemalloc_reserve += min_wmark_pages(zone); - free_pages += zone_page_state(zone, NR_FREE_PAGES); + free_pages += zone_page_state_snapshot(zone, NR_FREE_PAGES); } /* If there are no reserves (unexpected config) then do not throttle */