Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2601234imi; Mon, 25 Jul 2022 03:11:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t0BPpoiltbpZvJD4mOcAt+8NgfeDMvFlyHQB21GmGsWjjX8SmAwShum99y+FqAbA/dTiE1 X-Received: by 2002:a63:696:0:b0:41a:1c20:bf5f with SMTP id 144-20020a630696000000b0041a1c20bf5fmr10461157pgg.402.1658743873935; Mon, 25 Jul 2022 03:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658743873; cv=none; d=google.com; s=arc-20160816; b=FEN55/29PM6u08jN2aciPbPUN3Qzn5rFfRYSwt5UmWe+TLxpLv3jkNMqhT4epsPyyL YmyjS57zprZsYh0vOlcd57ODBoxUAce3bTBfA20lcSOHsQFvOEzKBbwBgKTroW6eLkXH rekkry9vK9A8cKZuj2LT5PHoxDEcRP8qOTnw6I4A28fsUSPyEA6ssDqaJbhvy6oxh3nV W1JT1RXC9Y11o3djXD9LHZf4Dk7hnxSV7b+03Dg0IJ2tJnVuX9Nrm5ZckWvW6mxO+U33 SxrBEMG7MZJBpYslL8Xhd/TpyE4NO6ZdmQz0edd9T6yrBiX+QgddWnL1iixSlscbLNqw P9Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=1SZSN+URK3fPaUP+8oBcbCaH7+pgUXYqMJcXmpr8nqs=; b=0EjM0CiibpCCIUbcbBgENxpHkXp6FivSO2VPy1QVVRWv8GKz7hf1mC1N/Gy70EwivG Q3KuIQCSEp3bCpUsO/+CFaC6KoRZht8uP+pGfmQyCUNYnXb2/R5787aaU8kfTSoNMCxX 79pmNA5gats8Js8CWvTc9mmV+jA4xrO2KPqAlKcxnvcX1ee7dsQhIoy9OvXctRwSzFMz sQQxU7Y5QSnmmdibXx6H6zznx0Y3R4H8XeITYqUS1QZyyhayI50/F9GKdjsX5Cj5UTj3 GzPjmGsVJjZdgSdACeqshjA6yOBj1WjZ/X06zHjiQ6bi/sakiHIinCb65upO5+faM9PN FU7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=RnFMCbzI; 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=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iq21-20020a17090afb5500b001e0b16a6bb9si12166622pjb.159.2022.07.25.03.10.59; Mon, 25 Jul 2022 03:11:13 -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=@samsung.com header.s=mail20170921 header.b=RnFMCbzI; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233419AbiGYJw2 (ORCPT + 99 others); Mon, 25 Jul 2022 05:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233168AbiGYJw0 (ORCPT ); Mon, 25 Jul 2022 05:52:26 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E073167F9 for ; Mon, 25 Jul 2022 02:52:22 -0700 (PDT) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220725095216epoutp0487e30d94ea26da70980f34a3b72878ae~FCbsSjRoN1657316573epoutp04n for ; Mon, 25 Jul 2022 09:52:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220725095216epoutp0487e30d94ea26da70980f34a3b72878ae~FCbsSjRoN1657316573epoutp04n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1658742736; bh=1SZSN+URK3fPaUP+8oBcbCaH7+pgUXYqMJcXmpr8nqs=; h=From:To:Cc:Subject:Date:References:From; b=RnFMCbzIR2Vnuz6qSbcBf13vjvHKXdVMDd8PTQM3DQcJvlla/aYRifNnVWCF0Ivby IJNGilPlipO6N4PrAts+WklXW64CYBPS9f+rYGwuXGeEoeXFVfvwXyQyNhMc9Z2qZj 16Ng2zdlM4T9LIAbV29Qz6K9gRo8VGf/rsESnnSY= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20220725095215epcas1p30bf348ac3b337b66638d4422dd796729~FCbrSseRB1436114361epcas1p3c; Mon, 25 Jul 2022 09:52:15 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.38.241]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4LrwLl2xf4z4x9Q0; Mon, 25 Jul 2022 09:52:15 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 6C.55.09678.FC76ED26; Mon, 25 Jul 2022 18:52:15 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220725095214epcas1p1cc2019c792560da07d673809a3fc7ef3~FCbqhhizu2036020360epcas1p1-; Mon, 25 Jul 2022 09:52:14 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220725095214epsmtrp122086ac3523b47fc40b9ce78431eac60~FCbqgoIjW1354513545epsmtrp1L; Mon, 25 Jul 2022 09:52:14 +0000 (GMT) X-AuditID: b6c32a39-e67ff700000025ce-a1-62de67cf6dc2 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id CF.35.08905.EC76ED26; Mon, 25 Jul 2022 18:52:14 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.100.104]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220725095214epsmtip2a03a41b1c28accef45748067fba52612~FCbqUYN2t3171331713epsmtip2v; Mon, 25 Jul 2022 09:52:14 +0000 (GMT) From: Jaewon Kim To: minchan@kernel.org, akpm@linux-foundation.org, bhe@redhat.com, vbabka@suse.cz, mgorman@techsingularity.net, hannes@cmpxchg.org, mhocko@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, gh21.hong@samsung.com, ytk.lee@samsung.com, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH v2] page_alloc: fix invalid watemark check on a negative value Date: Mon, 25 Jul 2022 18:52:12 +0900 Message-Id: <20220725095212.25388-1-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpik+LIzCtJLcpLzFFi42LZdlhTV/d8+r0kg/N9QhZz1q9hszj/4Beb xZbfbxgtVm/ytejePJPRovf9KyaLy7vmsFncW/Of1WLH0n1MFq+/LWO2WPb1PbvF7MY+RovH 67kdeD0Ov3nP7LFz1l12j02rOtk8Nn2axO5xYsZvFo/3+66yefRtWcXocWbBEXaPrb/sPD5v kgvgisq2yUhNTEktUkjNS85PycxLt1XyDo53jjc1MzDUNbS0MFdSyEvMTbVVcvEJ0HXLzAE6 XUmhLDGnFCgUkFhcrKRvZ1OUX1qSqpCRX1xiq5RakJJTYFagV5yYW1yal66Xl1piZWhgYGQK VJiQnbFo9xaWgn7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d24PU4/OY9s8fOWXfZPTat6mTz2PRpErvHiRm/WTze77vK5tG3ZRWjx5kFR9g9tv6y8/i8 SS6AK4rLJiU1J7MstUjfLoErY9HuLSwF/YIVmxrPszUw9vF1MXJySAiYSHSuX8rcxcjFISSw m1Fi0779bBAJGYk355+ydDFyANnCEocPF0PUfGOUeHXsGxNIDZuAtsT7BZNYQRIiAgsZJXa+ fwE2iVlgJaPE25fzGEGqhAX8JJYumscKYrMIqEpMfvKMGcTmFbCV2Lu9nx1im7zE6g0HmCcw 8ixgZFjFKJlaUJybnltsWGCYl1quV5yYW1yal66XnJ+7iREcsFqaOxi3r/qgd4iRiYPxEKME B7OSCG9X2u0kId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rwXuk7GCwmkJ5akZqemFqQWwWSZODil Gpjm1/lbrts2u4Sd77dX9R3R1+z32VfU79/+vnu74i3eb+2BEtEic+SEeT6qNUh0vtl8caJA KFuOwZYWS+boGsVbXh/ylK99XXh6TtLs9y94BLg1XgQuZjF/Hq3Vt1ghluPdDU6Tec8Z2k/u ShY4oSj7yixPgHP5ScNTT/cmv92yMmPivJfHrj2+yF/J//y627sl+7pL5N0D4msq1JqMeCP9 fTmj5NUcex9XZj8UDvGUcZPVy3J9rLdM5N1/1p//TiXOtbU8y7rUvXRR69Sz96ofMUc/Uc9e dO3AVUXDDVaet1cwhnILL/txMrHKd5Fo7cEA+wczFkz9NmdzU4TN19eZ/Vr9ySdL9/scWcr2 8YQSS3FGoqEWc1FxIgAhUwPdxwIAAA== X-CMS-MailID: 20220725095214epcas1p1cc2019c792560da07d673809a3fc7ef3 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220725095214epcas1p1cc2019c792560da07d673809a3fc7ef3 References: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 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. Fixes: f27ce0e14088 ("page_alloc: consider highatomic reserve in watermark fast") Reported-by: GyeongHwan Hong Signed-off-by: Jaewon Kim Acked-by: Mel Gorman --- v2: use explicit code suggested by Mel Gorman v1: use signed min --- 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 e008a3df0485..b5b14b78c4fd 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3968,11 +3968,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[highest_zoneidx]) + 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[highest_zoneidx]) return true; } -- 2.17.1