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=1796379339; b=sFQ1B+jYVfg9JtKb0p4zyaPnfWIH9KQeVw95yA/5fCkRKhJy1BoqL2VqmS0jHeBLcN7s DaiZLOzpFCmibC1uY15po01PvSZd3B6VUOtv27rcyRzQbrCHMvpSPTwu0OhLrvXlOkdNr FVfmcEOFYgLx/5b+L5eUo1Hv7Tb/lgYCqm7vQIA+IIw1G6xuCE10XBzqx19F2iS78joNC lD6VZA6rKkVZ2wuIgWpIwRoYHEaFbGSrrZzgT2x4LfZW+sYwcof0zcnuMhHGpib9GCzto r0OCi8boca4Z6QewKxPRQUASpfBMax0uxH9U9dWDFhHtNTdK9yM6iVIcyHdVc62Ru9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379339; 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=nvYRsPk+OUjWJJbi7+sK00OLLXO84NWrc/jTk0Y58bE=; b=HxBj1q3C0g4U6yCAJ+LB+CbuCpLkVUhu1Bf9NDAwIxxHDBc/nbNO0PulMCzWTU9r2T9h UThA9KI+exBT0TsKc8sT/PHYFjMI5YTAHeALVcZNsgV3Q1o688Qnhh7uMoDOq/vbV3C9V swxxNN9BjU8+7A7m+q3ftnbuEN0Gzvs03FqYvsE+JKwDbRFJZ3mIVjiXRbS/iJbPJbIai CwbFN7dVvtpl6AVopLlPeUvu38ax88VFfJudDz7UU1XUG71hOV9jGg2Xn2JXsvzCG7iZ/ 4bk+fsEQCGnDCMU+mx6y5lPwmFv63r93zJeJCToim7wXCQ2PEzM96QcqLC+wsBdk/Vg== 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=bQHEtOIK; 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 974F3606A330; Fri, 4 Dec 2026 10:15:39 +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=bQHEtOIK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 179581F000C2; Fri, 4 Dec 2026 10:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379339; bh=nvYRsPk+OUjWJJbi7+sK00OLLXO84NWrc/jTk0Y58bE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bQHEtOIKlxEbEfwqKBNCJqnx3UaFDMrWLbS4G8iLQ1kI00CzTJ2Ri4FBki/CUIFtM zKzmvay479liFuu3e3Yp4V1QHPMWTs2lDgusDydlYA0rgC2PPP2IJTiz7OSEGS8e2H OWprR8qcnVkheuy44D9QIeGuycrLQcxGLhH21/lw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhiguo Jiang , Frank van der Linden , "Vlastimil Babka (SUSE)" , Brendan Jackman , Johannes Weiner , Michal Hocko , Suren Baghdasaryan , Zi Yan , Andrew Morton , Sasha Levin Subject: [PATCH 6.18 019/703] mm/page_alloc: dont increase highatomic reserve after pcp alloc Date: Fri, 4 Dec 2026 18:58:38 +0900 Message-ID: <20261204100628.067168505@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Frank van der Linden [ Upstream commit b480cbb071020bd590a0dc0166635b448e9fc46b ] Higher order GFP_ATOMIC allocations can be served through a PCP list with ALLOC_HIGHATOMIC set. Such an allocation can e.g. happen if a zone is between the low and min watermarks, and get_page_from_freelist is retried after the alloc_flags are relaxed. The call to reserve_highatomic_pageblock() after such a PCP allocation will result in an increase every single time: the page from the (unmovable) PCP list will never have migrate type MIGRATE_HIGHATOMIC, since MIGRATE_HIGHATOMIC pages do not appear on the unmovable PCP list. So a new pageblock is converted to MIGRATE_HIGHATOMIC. Eventually that leads to the maximum of 1% of the zone being used up by (often mostly free) MIGRATE_HIGHATOMIC pageblocks, for no good reason. Since this space is not available for normal allocations, this wastes memory and will push things in to reclaim too soon. This was observed on a system that ran a test with bursts of memory activity, paired with GFP_ATOMIC SLUB activity. These would lead to a new slab being allocated with GFP_ATOMIC, sometimes hitting the get_page_from_freelist retry path by being below the low watermark. While the frequency of those allocations was low, it kept adding up over time, and the number of MIGRATE_ATOMIC pageblocks kept increasing. If a higher order atomic allocation can be served by the unmovable PCP list, there is probably no need yet to extend the reserves. So, move the check and possible extension of the highatomic reserves to the buddy case only, and do not refill the PCP list for ALLOC_HIGHATOMIC if it's empty. This way, the PCP list is tried for ALLOC_HIGHATOMIC for a fast atomic allocation. But it will immediately fall back to rmqueue_buddy() if it's empty. In rmqueue_buddy(), the MIGRATE_HIGHATOMIC buddy lists are tried first (as before), and the reserves are extended only if that fails. With this change, the test was stable. Highatomic reserves were built up, but to a normal level. No highatomic failures were seen. This is similar to the patch proposed in [1] by Zhiguo Jiang, but re-arranged a bit. Link: https://lkml.kernel.org/r/20260320173426.1831267-1-fvdl@google.com Link: https://lore.kernel.org/all/20231122013925.1507-1-justinjiang@vivo.com/ [1] Fixes: 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") Signed-off-by: Zhiguo Jiang Signed-off-by: Frank van der Linden Reviewed-by: Vlastimil Babka (SUSE) Cc: Brendan Jackman Cc: Johannes Weiner Cc: Michal Hocko Cc: Suren Baghdasaryan Cc: Zhiguo Jiang Cc: Zi Yan Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/page_alloc.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 074178f4d7a07..6b4a1dd7253e8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -244,6 +244,8 @@ unsigned int pageblock_order __read_mostly; static void __free_pages_ok(struct page *page, unsigned int order, fpi_t fpi_flags); +static void reserve_highatomic_pageblock(struct page *page, int order, + struct zone *zone); /* * results with 256, 32 in the lowmem_reserve sysctl: @@ -3256,6 +3258,13 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, spin_unlock_irqrestore(&zone->lock, flags); } 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 + */ + if (unlikely(alloc_flags & ALLOC_HIGHATOMIC)) + reserve_highatomic_pageblock(page, order, zone); + __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); zone_statistics(preferred_zone, zone, 1); @@ -3327,6 +3336,20 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, int batch = nr_pcp_alloc(pcp, zone, order); int alloced; + /* + * Don't refill the list for a higher order atomic + * allocation under memory pressure, as this would + * not build up any HIGHATOMIC reserves, which + * might be needed soon. + * + * Instead, direct it towards the reserves by + * returning NULL, which will make the caller fall + * back to rmqueue_buddy. This will try to use the + * reserves first and grow them if needed. + */ + if (alloc_flags & ALLOC_HIGHATOMIC) + return NULL; + alloced = rmqueue_bulk(zone, order, batch, list, migratetype, alloc_flags); @@ -3955,13 +3978,6 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, if (page) { prep_new_page(page, order, gfp_mask, alloc_flags); - /* - * If this is a high-order atomic allocation then check - * if the pageblock should be reserved for the future - */ - if (unlikely(alloc_flags & ALLOC_HIGHATOMIC)) - reserve_highatomic_pageblock(page, order, zone); - return page; } else { if (cond_accept_memory(zone, order, alloc_flags)) -- 2.53.0