From patchwork Mon Mar 20 18:03:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13181687 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 D7A3DC7618A for ; Mon, 20 Mar 2023 18:12:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8DFA6B007B; Mon, 20 Mar 2023 14:12:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D16F46B007D; Mon, 20 Mar 2023 14:12:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDF056B007E; Mon, 20 Mar 2023 14:12:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9A9566B007D for ; Mon, 20 Mar 2023 14:12:11 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6329880D4E for ; Mon, 20 Mar 2023 18:12:11 +0000 (UTC) X-FDA: 80590070862.06.83B7194 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id A4BF340018 for ; Mon, 20 Mar 2023 18:12:09 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e9kpL083; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679335929; 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=nxDgSxDt58miOCbO29kj6Q7ncA44wbvUWM1rbcl0z7M=; b=T4jfqloN7HbRhwjSokABT3pS+zrRFSLjQ2G+vFmqCFbHzwujkvMTrqtgg/aTIs2O2+6jxR AJ2H6wjSv5abYUaq26qkNbL/ZII7BjJUcE0/p4uR2vZg9AhKnrErGFGP9UBSnHUftlPOKb G6aIDJMJ6xw2N6rZLkwOQ5O7en7KxeE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e9kpL083; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679335929; a=rsa-sha256; cv=none; b=cummY9swhU7JKOTQ6kpgykE2Es9wfxy2QhFxQ2qBOA0BP71Nv2uocMJsZQ7U7qd7tp/W9x 4T1x90zWzEQ9QEFs+yqLTZdpuEtZ3LNeBlM6PAR8V4k4gaZPSANknTn358DPgaH16o5gjY Q06+2XbKWOGJxLnTAFpIWgI0RMa0pek= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679335929; 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=nxDgSxDt58miOCbO29kj6Q7ncA44wbvUWM1rbcl0z7M=; b=e9kpL083+4kEcsoNgC3xyJEQmqWxgdF8LfuOQmFt3nA7sIBrGZmknu1bsXJgAUaW/mTrlP Qs5KVYuLY+TGtbKMyxNtK9xfJ80xn49rtRfaWQUvyIPpFxng920eQU1q/1otmr/fO3UHUh wBrnrMO/cNd4LtIvPO41qAn7nsWJiJg= 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-138--rX6rrAwMOqsYpUa1YzcdA-1; Mon, 20 Mar 2023 14:12:05 -0400 X-MC-Unique: -rX6rrAwMOqsYpUa1YzcdA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B9671C08786; Mon, 20 Mar 2023 18:12:05 +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 EFD072027062; Mon, 20 Mar 2023 18:12:04 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id D1AD6403BC89A; Mon, 20 Mar 2023 15:08:02 -0300 (-03) Message-ID: <20230320180745.556821285@redhat.com> User-Agent: quilt/0.67 Date: Mon, 20 Mar 2023 15:03:33 -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 v7 01/13] vmstat: allow_direct_reclaim should use zone_page_state_snapshot References: <20230320180332.102837832@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: A4BF340018 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: de6i6ak8t348ymndqixh86nsf4nddiwi X-HE-Tag: 1679335929-311444 X-HE-Meta: U2FsdGVkX18x2zra8rACEaBUw3dcCThiZlg1wCUA4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cBt90JQsM+cpSfxGgsfomfl8aJA2OrwkY30a1LtUncUJMavMGG7fpKEAS1odE2a+hBnlSz+ZGFyiwlZ1zPvKRFtmLkvP2wBvRUkb/nTRWrjL265gPmdVX0e34yG5AIJqpuu717gLyRunBvlTa3W4LBLYKrAcs1iw1nw== 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 Index: linux-vmstat-remote/mm/vmscan.c =================================================================== --- linux-vmstat-remote.orig/mm/vmscan.c +++ linux-vmstat-remote/mm/vmscan.c @@ -6861,7 +6861,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 */