From patchwork Fri Jun 2 18:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 102676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1242160vqr; Fri, 2 Jun 2023 12:12:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51PjHpnBMGVmbY5mq01/U4MYhYiMfICUzQl5YG+Z6Ec2sbq5W+5lhhc5S91YY6ZTzToyag X-Received: by 2002:a05:6a00:1693:b0:647:4dee:62b7 with SMTP id k19-20020a056a00169300b006474dee62b7mr12127976pfc.29.1685733127257; Fri, 02 Jun 2023 12:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685733127; cv=none; d=google.com; s=arc-20160816; b=aFzNoyRxT841cmBaoIa9EOMDHFzockIDKZaEx3OrPcCouMib0Dcas8C6opAAsYjYK8 uyOiyqiDAbfksOdcjFrLepRnk3Rz5UiwKvMmk+PyjIGylc+xvioAt3A83/3nCd0ADFe0 zuWo/i8m/JuqLUasgC3nnP2Zx2XmGLHCvyIim22ga0QNtXXcRMbz+eCvz/vtP7bTlYI+ gAN4aZ8VP4vQ/XZUZ5hC7YOWg9UKaBRiKnCNWhPHxZNwQquS5C4j8/+I9h2P34XxUVs8 5tpy4s7lrO1M+jnHMdwCfrjKwQoje67uAJoGsoGD7uwZL+x7sk6ea0xLUSLUf0j+59c/ zW3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=N0hJfqn4EoxiBlmJOP3aHXOKCKD0R3BQJl7dwB2jg74=; b=ATSsN1B8qzMpWbblPKL86/PSkPexrF0xZfY//LiF50iHefa9s3+BCH5laKCrmB00XW j16783AjTm6IApeYm9IEOzC1P6EgbE82d3dbiHA/h6oeSLJ6CXp1Q72alQb6DRlGJjHR 0LkssF4Tl44/kyGamrcojOj6v7ZB2TNhUO+5EotABMDEEqSElYmNYOrAo+aFu3ZQQG9g UzOUPcUuKxu6hPMiRzZxF0Qkwht4orH+zylzXVevgdwpFcu11ZRc3nBmsbdSVadWlYtD PuDtpR/Xm3wHs+oUIex9rkNe1/R/PMxGIo0XPGBJTMO/3GzhWuH/qf7bVcVnTuYiHnz9 8LlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TL9h9fat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020aa79592000000b0064d2cca82b1si1197766pfj.48.2023.06.02.12.11.54; Fri, 02 Jun 2023 12:12:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TL9h9fat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237118AbjFBTE7 (ORCPT + 99 others); Fri, 2 Jun 2023 15:04:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbjFBTEz (ORCPT ); Fri, 2 Jun 2023 15:04:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B06B1A5 for ; Fri, 2 Jun 2023 12:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685732653; 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=N0hJfqn4EoxiBlmJOP3aHXOKCKD0R3BQJl7dwB2jg74=; b=TL9h9fat51oaDIijWMJ90zFKM0oVYeR0irqAZXkKul/fqIuk1fhdeqEBYiJu95ljQEVmI8 fT3huhhxAsTCLF1agGupP7isqMuPXnrcoQsbARDwFjjAc743uwd5/QJzhtPOSdzbXeYHJI l26oxQu0bmS7IQhlnGEhZpxTq+K2q4w= 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-542-ljUmNRMxP0CjAd128YeQiQ-1; Fri, 02 Jun 2023 15:04:08 -0400 X-MC-Unique: ljUmNRMxP0CjAd128YeQiQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D0248030D6; Fri, 2 Jun 2023 19:04:06 +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 38DDC140E95D; Fri, 2 Jun 2023 19:04:06 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 0D626401E1576; Fri, 2 Jun 2023 16:03:42 -0300 (-03) Message-ID: <20230602190115.497160508@redhat.com> User-Agent: quilt/0.67 Date: Fri, 02 Jun 2023 15:57:58 -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 , Marcelo Tosatti Subject: [PATCH v2 1/3] vmstat: allow_direct_reclaim should use zone_page_state_snapshot References: <20230602185757.110910188@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767619300020680930?= X-GMAIL-MSGID: =?utf-8?q?1767619300020680930?= 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. Testing: Due to difficulties accessing the system, it has not been possible for the reproducer to test the patch (however its clear from available data and analysis that it should fix it). Reviewed-by: Michal Hocko Reviewed-by: Aaron Tomlin Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/mm/vmscan.c =================================================================== --- linux-vmstat-remote.orig/mm/vmscan.c +++ linux-vmstat-remote/mm/vmscan.c @@ -6887,7 +6887,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 */