From patchwork Mon Jul 25 09:52:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12927923 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 AE3F3C43334 for ; Mon, 25 Jul 2022 09:52:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2817994000F; Mon, 25 Jul 2022 05:52:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2587D8E0001; Mon, 25 Jul 2022 05:52:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F97794000F; Mon, 25 Jul 2022 05:52:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F06368E0001 for ; Mon, 25 Jul 2022 05:52:22 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C0288AACAF for ; Mon, 25 Jul 2022 09:52:22 +0000 (UTC) X-FDA: 79725156924.26.0F61A84 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf09.hostedemail.com (Postfix) with ESMTP id 07B2F1400A9 for ; Mon, 25 Jul 2022 09:52:19 +0000 (UTC) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220725095216epoutp01572d4c2b666c3c1b4e0ef22aec5a73db~FCbsHye_R2418324183epoutp019 for ; Mon, 25 Jul 2022 09:52:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220725095216epoutp01572d4c2b666c3c1b4e0ef22aec5a73db~FCbsHye_R2418324183epoutp019 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 VJiQnbFo9xaWgn7Bik2N59kaGPv4uhg5OSQETCR2vP/G0sXIxSEksINRomHnC1YI5xOjxK4F +6Gcb4wSjw7dZYZp6Vy/lBkisZdR4vDWRWwQzg9GiYc951lAqtgEtCXeL5gE1i4iMJNRYv6N RWAJZoHF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ISSw 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 X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220725095214epcas1p1cc2019c792560da07d673809a3fc7ef3 References: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658742740; a=rsa-sha256; cv=none; b=EMjBXd1g/HGA7g2QRpjE778vatmTn1XlH3JEVmkSHzJbITDWKW+0laPTDf6nteRL+h4GH3 Hc1Vq+eJtpYvhci/iUzTXxSIPx5L7KPEeJJwoLl3AK1nrSDpnxqIaug9zbbBIw8FdJvtpJ BUr27idwLh1Rz1n+R5ESKMEDb8XdzqI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=RnFMCbzI; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf09.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658742740; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=1SZSN+URK3fPaUP+8oBcbCaH7+pgUXYqMJcXmpr8nqs=; b=1tDoD94wU9VZs7enbc2Xc0dNZ3Qje66r+7whipUTP+/oywu5ZRXKthXPXmaqNslYcb/zzJ zyUAfb1Sa7Wttmdw2wsUe33lDYkuBXMVlzqsjtStkJK/FkcwUShsdSkhP1/aNWMwD1aJEa nEOCdq4kpHDuSyDHGBAYgCGDTfSO1Xk= X-Rspamd-Server: rspam12 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=RnFMCbzI; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf09.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com X-Rspam-User: X-Stat-Signature: 8ucee5zxw4w3kqwom4a513as1iwtrcwd X-Rspamd-Queue-Id: 07B2F1400A9 X-HE-Tag: 1658742739-498280 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: 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; }