From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796379807; b=JzoBokvSpnbiDUMJd3/1BO5qdJHDvmI7c946hlaXzuIyk7QvaBHj52nsdDaF/rlK0951 EgePGv5PAJqoV8YGgsbbRrzI8j+JzVBqFb6MidnHveFMTX47+WUgOu7kQUd+rUC7gBhx9 QWJj0xoknfMNsLmN1bE1qL8/4FN6hjPwYtnJYUko0Ub+jl1kQ57hv51HP+EeTOCUfWKCT yrkJa1KvkHMbyTBvgT2O5zfaO+J+8vFK3DwZm23wWo+pBPKWRA2n4TAiJlndotKDRdb98 romynwcI6CWmwNoTaeuJ7hHV7p3DXgJy5nkyUHGW0ZgvM7BSAfocCA4J2t+PMhPAtfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379807; 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=MpnZzrFHuIxDX15pUJToRPJKaNfJgEpRjG/HwX8e0TU=; b=DxYlBy/QwxB14XqDuiDUOF7k9bhY/dPC2YU0qrxzQF4SSATNP0oRa+BYMYRONjkh1v/i 3CsG+Qp6IoA0Fai0OFgrb0SazhOv2VqRoukH+VpJKTend6umJDzsAJT+zU5f8XKTBfgil g+MzresHYLrYmzt8ejGMTSIB1hP5MsGY9PhENUROUEI0PBNI6wx3O8QjVvjvM1pymOQOr WmnH+AxnK8VVMWzchQCWNl5HDYEthkJkLhXEP4SjlHFirIZLJhiyCwlnz/aQKIuyFMLst rx7ywK1hyVsCWJoR75VJ8bACLsvOdYX9gv3lA6C9siePtIcyMWKexlXCZ8b7g6VjTIg== 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=HEgbRjE1; 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 29FB4606A322; Fri, 4 Dec 2026 10:23:27 +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=HEgbRjE1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 708C51F000C2; Fri, 4 Dec 2026 10:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379807; bh=MpnZzrFHuIxDX15pUJToRPJKaNfJgEpRjG/HwX8e0TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HEgbRjE1V4tMnBCHpshw+2ajasuNg1rgD4J7uOJIB2k3Cap7xVK+zMRKdiRRsItRQ 6SeJ9UdAYUFazClvwGJOLRKWk7pM0BC47Ti+fxCYNELwmtbbuhNR4B95kflUHc5uIC I5w1OgxLn/dSBlKAYvK4f8FwP9NZSdkpInFe/Jbc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, JP Kobryn , "Vlastimil Babka (SUSE)" , Johannes Weiner , Shakeel Butt , Brendan Jackman , David Hildenbrand , Frank van der Linden , "Liam R. Howlett" , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , Suren Baghdasaryan , Zi Yan , Andrew Morton , Sasha Levin Subject: [PATCH 6.12 043/555] mm/page_alloc: use existing highatomic reserves on the buddy fastpath Date: Fri, 4 Dec 2026 19:01:26 +0900 Message-ID: <20261204100607.636984649@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: JP Kobryn [ Upstream commit 9f2fd03c9bde366c928c9242fc9b2e2c5111a134 ] ALLOC_HIGHATOMIC currently provides both access to MIGRATE_HIGHATOMIC free pages and permission to create new highatomic pageblock reserves. This makes it unsuitable for the fastpath. However, the fastpath can reach rmqueue_buddy() while MIGRATE_HIGHATOMIC reserves have free pages available. In this situation, the allocation can fall back to other migratetypes without trying those reserves first. Allow high-priority non-blocking allocations to use existing MIGRATE_HIGHATOMIC reserves on the buddy fastpath without growing them. First tighten the criteria for reserving pageblocks so that growth may only occur in the slowpath. Then allow fastpath usage by enabling ALLOC_HIGHATOMIC when the GFP mask describes a non-blocking high-priority allocation. This logic has been factored out from gfp_to_alloc_flags() to a new function gfp_to_alloc_flags_nonblocking(). A UDP receive workload was run with free MIGRATE_HIGHATOMIC pageblocks available in the target zone. Before this patch, the workload did not consume these blocks. With this patch, eligible order-1 allocations reaching the buddy path consumed existing MIGRATE_HIGHATOMIC pageblocks, with no highatomic misses observed. The workload did not grow highatomic reserves and NAPI page-frag allocations remained healthy with no failures or order-0 fallbacks. Link: https://lore.kernel.org/20260623004600.113347-1-jp.kobryn@linux.dev Signed-off-by: JP Kobryn Reviewed-by: Vlastimil Babka (SUSE) Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt Cc: Brendan Jackman Cc: David Hildenbrand Cc: Frank van der Linden Cc: Liam R. Howlett Cc: Lorenzo Stoakes Cc: Michal Hocko Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Zi Yan Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/page_alloc.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a3d0281897035..c34ec6a7ded68 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3017,10 +3017,11 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, } while (check_new_pages(page, order)); /* - * If this is a high-order atomic allocation then check - * if the pageblock should be reserved for the future + * Slowpath (precarious) high-atomic allocations may reserve + * a pageblock for future use. */ - if (unlikely(alloc_flags & ALLOC_HIGHATOMIC)) + if (unlikely((alloc_flags & ALLOC_HIGHATOMIC) && + ((alloc_flags & ALLOC_WMARK_MASK) == ALLOC_WMARK_MIN))) reserve_highatomic_pageblock(page, order, zone); __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); @@ -4101,6 +4102,29 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, } } +static inline unsigned int +gfp_to_alloc_flags_nonblocking(gfp_t gfp_mask, unsigned int order) +{ + unsigned int alloc_flags = 0; + + if (gfp_mask & __GFP_DIRECT_RECLAIM) + return 0; + + /* + * Not worth trying to allocate harder for __GFP_NOMEMALLOC even + * if it can't schedule. + */ + if (gfp_mask & __GFP_NOMEMALLOC) + return 0; + + alloc_flags |= ALLOC_NON_BLOCK; + + if (order > 0 && (gfp_mask & __GFP_HIGH)) + alloc_flags |= ALLOC_HIGHATOMIC; + + return alloc_flags; +} + static inline unsigned int gfp_to_alloc_flags(gfp_t gfp_mask, unsigned int order) { @@ -4123,18 +4147,9 @@ gfp_to_alloc_flags(gfp_t gfp_mask, unsigned int order) alloc_flags |= (__force int) (gfp_mask & (__GFP_HIGH | __GFP_KSWAPD_RECLAIM)); - if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) { - /* - * Not worth trying to allocate harder for __GFP_NOMEMALLOC even - * if it can't schedule. - */ - if (!(gfp_mask & __GFP_NOMEMALLOC)) { - alloc_flags |= ALLOC_NON_BLOCK; - - if (order > 0 && (alloc_flags & ALLOC_MIN_RESERVE)) - alloc_flags |= ALLOC_HIGHATOMIC; - } + alloc_flags |= gfp_to_alloc_flags_nonblocking(gfp_mask, order); + if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) { /* * Ignore cpuset mems for non-blocking __GFP_HIGH (probably * GFP_ATOMIC) rather than fail, see the comment for @@ -4899,6 +4914,7 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, * memory until all local zones are considered. */ alloc_flags |= alloc_flags_nofragment(zonelist_zone(ac.preferred_zoneref), gfp); + alloc_flags |= gfp_to_alloc_flags_nonblocking(gfp, order) & ALLOC_HIGHATOMIC; /* First allocation attempt */ page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac); -- 2.53.0