Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2633756rwd; Fri, 2 Jun 2023 12:12:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZTe7jLnvso9QPNwrCDzNwHtuHNvstRptgCiSziwHvIgDo2sjyqLNJPPv7C/8+BfUuBk2X X-Received: by 2002:a17:902:e84a:b0:1b1:8902:e07e with SMTP id t10-20020a170902e84a00b001b18902e07emr1018199plg.43.1685733125123; Fri, 02 Jun 2023 12:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685733125; cv=none; d=google.com; s=arc-20160816; b=qelmjNlvOMt5EKiQYXj6RRvNQZwmFyptkVaS0SMnTDvCrfJl4Y2TC/72FmKRH6Zt/K Mbj0ZYFBITxDnPGH3bDDxuaweylnFeqHRkCO5Xbc2Mzt+CI+kJ32Ci1aXfLVhfjZT6qR laz8kXPtDj8BX94WBhZwTAEKG77XDcv2pdAxtbAHoH1pZekmf8wc/9o0e3YHwu9K9QEg nFyxON+Rg+uuRNVrIYQGAPms2Nssi7/gpclwM+s/1gp6lhap3un9DzoA/0RahLqNuaEl Sj1tFZHIFa6SxWQ+a2/N/Yk4sHQ2SIHTH8ThXEmDki1X1LwCrldg6V9KR9YUax4BFqIT 6XMw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a170902ba8500b001aae741abafsi1261135pls.440.2023.06.02.12.11.52; Fri, 02 Jun 2023 12:12:05 -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 S236922AbjFBTE7 (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 Content-Type: text/plain; charset=UTF-8 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 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 */