Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795047467; b=r1b2VXRvrFX2wB+wP+63kHp21rK8GmrSuM4vTm1wbx7wfV4twcPu0C+RRHitQt68cn/G n2aDJe8Vh1T5wnMiTMC2jlL+G4AJoM+vDj+dWS1hcxlnfz4dtxuYrXWjMSWhoRuluroWU /hnuBGAARwooMv+eX1HOhfnQ/GVx52c3UHrmZGLPPEIyRLDI0Q9m09JaoU8x+ATrM5m5G 2QSGsCzQkNIt092kMfXd+aJj8sCuq8k0/e9A2GzKkWtoecR7UmRjcmQ4nkFZpLnYxDIB1 Pi4U4AX0WlvG6M+6gtFB4pxZaiSrc26budChuDa4p+ABOkuxJr/XMWyBoxEQFDZOnSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795047467; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=dxAFB+6NPlea2+yVoZQ4IWdjKr6FUaw2SAtU+Xf4fwI=; b=3n5fzgnXHw3DLYrJqze0eANBa0XoGr2yA4h1AiIjgv5xKv6aGm8jJjTIrIemXl3PAncZ tcnzJrDgHUgEeZI+Lr954rcoyLaQsRM7k9d8wSC/T15RHyBqQpUn+sUsQ5F7hCPe7kgyf HEIuAf0P6o8GPu6d4RFyX+gukAUTFm920RGgWSG4E7zRqjw0kSeVxjLizx7tzJmtQ9ppK vSWxXfWA74XECHoiZwsxUEHpsrFOayLbUdOEpqid1Ofz3Ob7GZAreyCsYi2GgYZZwBSZi SpPvEZwJi76AGg00Dw97rw4dudLCwhTLsk8VHuHlaHIcJH2iSTaGEecdvaN78n1qTRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=sIoPC5V0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FFF7606A320; Thu, 19 Nov 2026 00:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=sIoPC5V0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD5841F000C4; Thu, 19 Nov 2026 00:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795047467; bh=dxAFB+6NPlea2+yVoZQ4IWdjKr6FUaw2SAtU+Xf4fwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sIoPC5V0P/4LCp4HgU9JjSQhYa7dQPYnreaJhy9i3bmhaSdQ3cg55DxgBE67y3E0K JP5TdOB42BGO3NvMIyI3PADqgZM2Pxlvv/BFDxczRLuIH2gbIFMp++JuVYV0SeP35a x0kYxejCyBMANen1+Bvg7odcDNfHSthZSR38Es+o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Johannes Weiner , Andrew Morton , Sashiko , Balbir Singh , "Vlastimil Babka (SUSE)" , "Matthew Wilcox (Oracle)" , Salvatore Dipietro , Christoph Hellwig , Dave Chinner , Matt Fleming , Mel Gorman , Michal Hocko , Suren Baghdasaryan , Brendan Jackman , Zi Yan , Sasha Levin Subject: [PATCH 6.1 1650/2857] mm: page_alloc: do not give all non-blocking requests reserve access Date: Wed, 18 Nov 2026 15:44:44 +0100 Message-ID: <20261118150300.743726106@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johannes Weiner [ Upstream commit 6ee3d87b940848aaed5d4e8d005c5f674bf2637a ] Patch series "mm: page_alloc: fix reserve access for non-blocking requests", v2. Two fixes for how non-blocking allocations interact with the highatomic reserve. There are prerequisites for Salvatore's "mm/page_alloc: avoid direct reclaim and compaction for costly __GFP_NORETRY allocations" [0]. Patch 1 narrows which requests may physically take highatomic pages, patch 2 narrows which requests may count them in their watermark check. Both are prerequisites for Salvatore's patch: it clears __GFP_DIRECT_RECLAIM for costly __GFP_NORETRY requests, which turns every large page cache folio allocation that reaches the slowpath into a non-blocking one. Without patch 1, those requests may fall back to the highatomic freelists reserved for atomic requests. Without patch 2, they count the free highatomic pages in their watermark check while being served from regular memory, so they can consume regular high-order blocks below the min watermark by the size of the reserve. GFP_NOWAIT requests hit both paths today, so these are existing problems worthy of their own stable backports; but Salvatore's patch would widen them significantly. Patch 2 reproduction: a GFP_NOWAIT burst under memory pressure can drain regular free memory to zero while the highatomic reserve sits idle. Measured on a 32G box with an anonymous working set, swap, and a full 290M reserve, three synthetic bursts drove the 28G Normal zone's regular free memory to 28M, 0.8M and 0.6M against a 60M min watermark. Swapout failed its swap table allocation inside reclaim, reclaim scanned 13M pages to free 200k, and page faults stalled for tens to hundreds of milliseconds. With the fix the burst stops at the min watermark and nothing else happens. This was found in review and reproduced synthetically; it has not been observed in production. GFP_ATOMIC order-0 requests have a milder version of the same problem: They are entitled to the reserve but are served regular memory first, so the fix there has to change the watermark check and the freelist order together. Salvatore's change doesn't interact with this, though; fixing that is left for a separate patch. This patch (of 2): 281dd25c1a01 ("mm/page_alloc: let GFP_ATOMIC order-0 allocs access highatomic reserves") accidentally gave all non-blocking allocation requests access to highatomic reserves, which includes GFP_NOWAIT and other sites clearing __GFP_DIRECT_RECLAIM. While this improved atomic request success rate, it's unintentionally broad and can actually worsen highatomic requests by squandering the reserves on requests that don't need it. There are concurrent efforts to clear __GFP_DIRECT_RECLAIM altogether for costly order __GFP_NORETRY requests, which would then also fall into this exemption and deplete reserves even faster. What GFP_ATOMIC has over the others is __GFP_HIGH, which alloc_flags_slowpath() translates to ALLOC_MIN_RESERVE. Narrow the exemption to contexts that have both ALLOC_NON_BLOCK | ALLOC_MIN_RESERVE. Link: https://lore.kernel.org/20261001082152.2879289-1-dipiets@amazon.it [0] Link: https://lore.kernel.org/linux-mm/arFBWvzXPYrKuIYi@cmpxchg.org/ [1] Link: https://lore.kernel.org/linux-mm/20261001082152.2879289-1-dipiets@amazon.it/ [2] Link: https://lore.kernel.org/20261028171719.2043421-1-hannes@cmpxchg.org Link: https://lore.kernel.org/20261028171719.2043421-2-hannes@cmpxchg.org Fixes: 281dd25c1a01 ("mm/page_alloc: let GFP_ATOMIC order-0 allocs access highatomic reserves") Signed-off-by: Johannes Weiner Signed-off-by: Andrew Morton Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260904115629.3993331-1-dipiets@amazon.it Acked-by: Balbir Singh Reviewed-by: Vlastimil Babka (SUSE) Cc: Matthew Wilcox (Oracle) Cc: Salvatore Dipietro Cc: Christoph Hellwig Cc: Dave Chinner Cc: Matt Fleming Cc: Mel Gorman Cc: Michal Hocko Cc: Suren Baghdasaryan Cc: Brendan Jackman Cc: Zi Yan Cc: [ sashal: placed ALLOC_MASK_ATOMIC in the existing internal header instead of the separate page allocation header ] Signed-off-by: Sasha Levin --- mm/internal.h | 3 +++ mm/page_alloc.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/internal.h b/mm/internal.h index f99d9812c48d7..1c1b37bd4226d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -797,6 +797,9 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, /* Flags that allow allocations below the min watermark. */ #define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) +/* Flags that mean GFP_ATOMIC */ +#define ALLOC_MASK_ATOMIC (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE) + enum ttu_flags; struct tlbflush_unmap_batch; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index de91843b80fad..edafc2c27d407 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3777,7 +3777,9 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, * reserves as failing now is worse than failing a * high-order atomic allocation in the future. */ - if (!page && (alloc_flags & (ALLOC_OOM|ALLOC_NON_BLOCK))) + if (!page && + ((alloc_flags & ALLOC_OOM) || + (alloc_flags & ALLOC_MASK_ATOMIC) == ALLOC_MASK_ATOMIC)) page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); if (!page) { -- 2.53.0