From nobody Sat Apr 4 04:33:35 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2528528000F for ; Fri, 20 Mar 2026 17:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774028079; cv=none; b=cbTerCDnyPpAUxCIrhIju9CVC1FpPW6Bdk9pFc7H5pDfWKg2lguqa3uSvExoxPaOQ+E0W6L8Q7ZazsT5evFD1Aw3q3InXlU0BFrYCQZO5kQJkLldbDw75/l8A2OYqpT8alrK61QVHV+Xz9oDAlNIx8WCC5B3NSqPgfscPRep9UM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774028079; c=relaxed/simple; bh=GOC2uw0tpNffCy4UGuhstDVhZndL3sxQecpFzGJskCQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=UA/kaXh3tLq894eiYfKrK8Qs+JVm9Xy+bHv13gj+4ChrYwPsb4HIlR81pLvmzY6MPfFju6TqkeuB50sxEwZmdKtzbsCxeBmAvCv/MT5io2HkRdvy/IhAfMq9hb7kKiSsWJqYdLc/Vpq3FaDq6kvcw4/3iZZA/M5w2ZZwH4rzcJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--fvdl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Lnib6W6T; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--fvdl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Lnib6W6T" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-35a0337930eso2270992a91.3 for ; Fri, 20 Mar 2026 10:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774028077; x=1774632877; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bonijrsn1OMkw59Rfu4OJ4lbGEhyXMY7KnXznrPdFI8=; b=Lnib6W6TPJyaO+Q75Whakjz4pm8JOrwLvctLLkgBtzyWl+lcdWaRShrFRJ9m60QbJh o+9yY/QvKkZe4OHzcsr2M5FWBFrI+xnud5PTDZzpTy2Ka+9ePpKxq0IDZ2D3ClSm+N+E dxxchP/6LO7WHlxgw4mbD85bHhwJvkIEtDxmG9ZInd4guA8K9h6UChN6PZOiAKLcZALH k7SW1mZhI+pwoLEmCq2vTqk7na42ZdcSfwHL4oYjLHWJ7dKLxRT2qUbXUJuInw19I3RA pCq+1oD1/Aj/E+to7rE6cU73UizlFjMKCXZ+Q0Z4OapaCF0TTsn+/KfJ6gQtQeNMEJFd /QYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774028077; x=1774632877; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bonijrsn1OMkw59Rfu4OJ4lbGEhyXMY7KnXznrPdFI8=; b=nfjdfvWFK86hHxMMZenKPRKpprRxINfOJPuz5fkBmMh4g8a45OTPhHyjfMZQ6xVZ34 0PiVIyhHWkWiZZYEABzBYkIiyT8/FOgBC+iKXFA/kEqrp+R9ZVRbaSwjZjvHftRj2mNe sPVREWLJnUQMFwU3BysQH9zJ6t5fyEH9fB6ybQW11XRMnXajmH+B1ZmkCFi4DkCh2JMH pbm77LKQozgLWdRa1wZku98B96mm5i5G/VnhVoS0fTuefrtAelmkmcZT8A+PGh8veMjH uyr1QUj7kF2g+V00rj1DQSqvMEmuUtyLebyBrIN8Jw6Iw6lPqJ0CYzOPvI9cXdHvvtyx W1IQ== X-Forwarded-Encrypted: i=1; AJvYcCUtwakjUg4ZpyCKwc/LueQntBbNqqZuXxytm2CNpmZhv43BCbFQqhirrW5Q1n6HM/JUOl483f9ZK2DUTJs=@vger.kernel.org X-Gm-Message-State: AOJu0YzGDN9Mf0CPg9T9xhWoOCyQ+HXp8FFoJQ3aJ15qxUGrnsOKOQix 20PLwTyov0S98uUTM7xxGUvHeOCKuOdytATF5bNJu9H+X+O6zNki6VvUzpTYY7Doehlm+0rSVg= = X-Received: from pgac4.prod.google.com ([2002:a05:6a02:2944:b0:c73:7879:4c1b]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e7d1:b0:35b:90e7:c458 with SMTP id 98e67ed59e1d1-35bd2bba0admr3287761a91.3.1774028077229; Fri, 20 Mar 2026 10:34:37 -0700 (PDT) Date: Fri, 20 Mar 2026 17:34:25 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.959.g497ff81fa9-goog Message-ID: <20260320173426.1831267-1-fvdl@google.com> Subject: [PATCH] mm/page_alloc: don't increase highatomic reserve after pcp alloc From: Frank van der Linden To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Vlastimil Babka , Michal Hocko , Johannes Weiner , Frank van der Linden , Zhiguo Jiang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, pared 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. Signed-off-by: Zhiguo Jiang Signed-off-by: Frank van der Linden Link: https://lore.kernel.org/all/20231122013925.1507-1-justinjiang@vivo.co= m/ [1] Fixes: 44042b4498728 ("mm/page_alloc: allow high-order pages to be stored o= n the per-cpu lists") Reviewed-by: Vlastimil Babka (SUSE) --- 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 2d4b6f1a554e..57e17a15dae5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -243,6 +243,8 @@ unsigned int pageblock_order __read_mostly; =20 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); =20 /* * results with 256, 32 in the lowmem_reserve sysctl: @@ -3275,6 +3277,13 @@ struct page *rmqueue_buddy(struct zone *preferred_zo= ne, struct zone *zone, spin_unlock_irqrestore(&zone->lock, flags); } while (check_new_pages(page, order)); =20 + /* + * 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); =20 @@ -3346,6 +3355,20 @@ struct page *__rmqueue_pcplist(struct zone *zone, un= signed int order, int batch =3D nr_pcp_alloc(pcp, zone, order); int alloced; =20 + /* + * 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 =3D rmqueue_bulk(zone, order, batch, list, migratetype, alloc_flags); @@ -3961,13 +3984,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); =20 - /* - * 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)) --=20 2.53.0.959.g497ff81fa9-goog