Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2449453rwn; Fri, 16 Sep 2022 10:23:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4LVjzTt1J5JB0Qukd7GMU6VupoUXuvyAN5ctpnBkSTLoVHpJA9c+CGx2K818tauUKtHXOv X-Received: by 2002:a17:907:2711:b0:77a:15d6:931e with SMTP id w17-20020a170907271100b0077a15d6931emr4324243ejk.154.1663349036026; Fri, 16 Sep 2022 10:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663349036; cv=none; d=google.com; s=arc-20160816; b=pLgNX/c3cyOO3CvcEgqjIe9knuHPx1so6zuo463qA4caxqgEEE5TneMEbrF10ujMIB irAMg7gPR89KZurW6TgMNWfEgh97sD02TaOpYm4h0sSarcgDm7+GTiPRMXD02E17cQnW If6KoSNB1vAb4XdpW2GgEWg0MJlC8nMduMKneEtxjmseBm031Jy7T5QKhpGm5RX5oftn bVxBjvcAIgbJZuS4M+nanCEYZ5IfaC4CqZAniqT7Qo808wPVVQNeEH1baCYarXl6qoGb ZxsyhmNztopHoECsDWMitz6BiTPYdRUAM8ijxpZjhJ4QDZ4G8ZC1w75Q4PpeSWd9iZEh Eiiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=ZQ4epJy4kuC71aqt6/p49SxHHX9PRTr4w8eT6UANlFc=; b=kaxI9kG5w+QUWcsGGe4CWn4vPTHGYuj6eFcuev8VYMw80gOaD38WfdQqkLzBOZr+u2 jI96r0SACCbEoVr+EniJip48u1uSDluvgV+HS4w2K2kPT7NE9VQm+5FhW3QlR5RxIXos Re3xncwf5zjE7TSEwBru4+KEop2ojY59djweBzGJdipvAnGEBLpmDXyJFDx7jq6U49Hy dB4w6xFVwOTh4aR73y2Lah0YyaA+UrGABusbfAcGDQ1TbqbUC4KsZLZJS+6LS68f8Sq2 HKEOn3dftrIPqNsB5WQnK20kyAS2g0LuyXVdCIPXMGyDwhT7m+ZIvf7aH3bPtsiaq7zh 5W1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UrXbed1s; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd16-20020a170907629000b00770887ad669si21013551ejc.219.2022.09.16.10.23.30; Fri, 16 Sep 2022 10:23:56 -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=@gmail.com header.s=20210112 header.b=UrXbed1s; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbiIPRHU (ORCPT + 99 others); Fri, 16 Sep 2022 13:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbiIPRHM (ORCPT ); Fri, 16 Sep 2022 13:07:12 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F451B69D7; Fri, 16 Sep 2022 10:07:03 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id s18so16059981plr.4; Fri, 16 Sep 2022 10:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date; bh=ZQ4epJy4kuC71aqt6/p49SxHHX9PRTr4w8eT6UANlFc=; b=UrXbed1sCIkZkoXBLB070iyqZTAzOAN2KFDdu45xcMpXshpGd3wMlebzLUat9IFHMt Y5kJ17jTnRaD8bsyStt0bfoTJv80SeaWYfcs0pTOtcHdsV9DmKouMLlcvsfuE4LPuOF7 QAD1TAlbgowEDf0XOGYzNIcB/mNl9+CIr7sAdOBwFOaeyDg/45C7TEdvUxkcNvFhgAWA LjBxZ29QPC94uvnEM3upZDPSZBC9RQtIXM3vpLBqc6eo7TBHgRANzdWNnU8EXSDmzFTr qQZys+qqptAtEqvzt17ZSOLFRv5JCCWqhcJJ6Ky2Ypq2wXQDCTdsdOtSSLNtvsCeRk1V XdGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date; bh=ZQ4epJy4kuC71aqt6/p49SxHHX9PRTr4w8eT6UANlFc=; b=TW9eLMnD9+4i5p96vlHrDJDTMus13dWF+VyIqrocyNE7dodPccmNVHVvdY1DmnS4PZ g4GuPFhY+xtnGXjQN7AWx4DTifAUFR8EeKUni+dH6+e1eaTlR0nQ0bUmbryqlNrOWQ9o TWXsfehtmdhsX4t3dD+piaPhvoOdiFLGbfgmmY1lwT2yiZ3bHbFgc6au4lr/Qi/V/pxR /fH2iebfBPAznFzP+dho1gVXcqQ5VxTOSUoYcXYlfHTF3YLDxFz64lE7uyAKsQ/1Wbli neX0we0BmjIehTjxnBMeGPwvxLtYV/ESN9nwwPPHp1QPOVEZe4eRav4dcm0j0nuuG7xN XMjg== X-Gm-Message-State: ACrzQf2CYzAHwSIQCl4c1dlFQf856IYq469y7yLgIv5EVFO8ChmyW0J3 liOvGo6nFMO4GmRmoqAVwoc= X-Received: by 2002:a17:903:2290:b0:178:272b:e414 with SMTP id b16-20020a170903229000b00178272be414mr805886plh.120.1663348022490; Fri, 16 Sep 2022 10:07:02 -0700 (PDT) Received: from localhost.localdomain ([117.176.186.9]) by smtp.gmail.com with ESMTPSA id z12-20020a170903018c00b00176d4b093e1sm15386677plg.16.2022.09.16.10.06.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Sep 2022 10:07:02 -0700 (PDT) From: wangyong X-Google-Original-From: wangyong To: gregkh@linuxfoundation.org Cc: jaewon31.kim@samsung.com, linux-kernel@vger.kernel.org, mhocko@kernel.org, stable@vger.kernel.org, wang.yong12@zte.com.cn, yongw.pur@gmail.com, Minchan Kim , Baoquan He , Vlastimil Babka , Johannes Weiner , Yong-Taek Lee , stable@vger.kerenl.org, Andrew Morton Subject: [PATCH 3/3] page_alloc: fix invalid watermark check on a negative value Date: Fri, 16 Sep 2022 10:05:49 -0700 Message-Id: <1663347949-20389-4-git-send-email-wang.yong12@zte.com.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1663347949-20389-1-git-send-email-wang.yong12@zte.com.cn> References: <1663347949-20389-1-git-send-email-wang.yong12@zte.com.cn> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 From: Jaewon Kim There was a report that a task is waiting at the throttle_direct_reclaim. The pgscan_direct_throttle in vmstat was increasing. This is a bug where zone_watermark_fast returns true even when the free is very low. The commit f27ce0e14088 ("page_alloc: consider highatomic reserve in watermark fast") changed the watermark fast to consider highatomic reserve. But it did not handle a negative value case which can be happened when reserved_highatomic pageblock is bigger than the actual free. If watermark is considered as ok for the negative value, allocating contexts for order-0 will consume all free pages without direct reclaim, and finally free page may become depleted except highatomic free. Then allocating contexts may fall into throttle_direct_reclaim. This symptom may easily happen in a system where wmark min is low and other reclaimers like kswapd does not make free pages quickly. Handle the negative case by using MIN. Link: https://lkml.kernel.org/r/20220725095212.25388-1-jaewon31.kim@samsung.com Fixes: f27ce0e14088 ("page_alloc: consider highatomic reserve in watermark fast") Signed-off-by: Jaewon Kim Reported-by: GyeongHwan Hong Acked-by: Mel Gorman Cc: Minchan Kim Cc: Baoquan He Cc: Vlastimil Babka Cc: Johannes Weiner Cc: Michal Hocko Cc: Yong-Taek Lee Cc: Signed-off-by: Andrew Morton --- mm/page_alloc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 237463d..d6d8a37 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3243,11 +3243,15 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order, * need to be calculated. */ if (!order) { - long fast_free; + long usable_free; + long reserved; - fast_free = free_pages; - fast_free -= __zone_watermark_unusable_free(z, 0, alloc_flags); - if (fast_free > mark + z->lowmem_reserve[classzone_idx]) + usable_free = free_pages; + reserved = __zone_watermark_unusable_free(z, 0, alloc_flags); + + /* reserved may over estimate high-atomic reserves. */ + usable_free -= min(usable_free, reserved); + if (usable_free > mark + z->lowmem_reserve[classzone_idx]) return true; } -- 2.7.4