Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Zhiguo Jiang <justinjiang@vivo.com>,
	Frank van der Linden <fvdl@google.com>,
	"Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>, Zi Yan <ziy@nvidia.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.12 042/555] mm/page_alloc: dont increase highatomic reserve after pcp alloc
Date: Fri,  4 Dec 2026 19:01:25 +0900	[thread overview]
Message-ID: <20261204100607.572350472@linuxfoundation.org> (raw)
In-Reply-To: <20261204100603.988357525@linuxfoundation.org>

6.12-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Frank van der Linden <fvdl@google.com>

[ 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 <justinjiang@vivo.com>
Signed-off-by: Frank van der Linden <fvdl@google.com>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Zhiguo Jiang <justinjiang@vivo.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 dc4b0d58c4d0d..a3d0281897035 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -241,6 +241,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:
@@ -3014,6 +3016,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);
 
@@ -3085,6 +3094,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);
@@ -3569,13 +3592,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))
-- 
2.53.0




  parent reply	other threads:[~2026-12-04 10:23 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 10:00 [PATCH 6.12 000/555] 6.12.121-rc1 review Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 001/555] net: ipv6: keep room for the mac header in dst_dev_overhead() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 002/555] virtgpu: dont reset on shutdown Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 003/555] virtio: add virtio_device_shutdown() helper Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 004/555] virtio_balloon: factor out virtballoon_quiesce() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 005/555] virtio_balloon: quiesce balloon work before device shutdown Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 006/555] mm/page_alloc: snapshot the preferred zone against shrink rebuilds Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 007/555] pidfd: restrict task access ioctls to the callers pid namespace Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 008/555] net/smc: fix link group ownership in handshake abort Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 009/555] net/mlx5e: Fix queue stats access to queues without stats Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 010/555] tcp: do not coalesce segments after FIN Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 011/555] tcp: fastopen: note that a child socket was created Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 012/555] tcp: fix request_sock use-after-free during Fast Open accept() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 013/555] net: gro: invalidate frag0 after a pull Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 014/555] wifi: mac80211: fix use-after-free on TTLM disconnect Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 015/555] dm: fix infinite loop in dm_blk_do_report_zones() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 016/555] iio: common: scmi_sensors: fix truncating 64-bit divisions Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 017/555] iio: proximity: sx9500: ignore event config writes that dont change state Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 018/555] iio: imu: inv_mpu6050: fix swapped accel and gyro startup times Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 019/555] mmc: jz4740: Remove the host before resetting the controller Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 020/555] ALSA: hda: Fix [codec] ID matching in patch files for IDs with bit 31 set Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 021/555] kprobes: Adopt guard() and scoped_guard() Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 022/555] mmc: omap: synchronize clock timer before disabling fclk Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 023/555] mmc: sunxi: Use devm_mmc_alloc_host() helper Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 024/555] mmc: sunxi: fix clock and runtime PM leaks on probe failure Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 025/555] errseq: eliminate special limitation for macro MAX_ERRNO Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 026/555] errseq: dont let errseq_check_and_advance() hide later errors Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 027/555] xsk: defer software checksum until the skb is complete Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 028/555] cpufreq: Improve suspend-resume synchronization Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 029/555] tpm: flush timeout work outside buffer_mutex to avoid deadlock Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 030/555] spi: tegra210-quad: Track DMA mapping state Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 031/555] watchdog: npcm: Remove unnecessary NULL check before clk_prepare_enable/clk_disable_unprepare Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 032/555] watchdog: npcm: fix clock prepare leak when setting timeout on a running watchdog Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 033/555] tracing/probes: Enable newly appended probe when target event is enabled Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 034/555] tracing/probes: Fix missing BTF kind checks in char pointer/array helpers Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 035/555] xfrm: Dont clobber inner headers when already set Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 036/555] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 037/555] mtd: core: avoid double-free of OTP NVMEM device Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 038/555] bpf: Introduce jit_required flag and remove bpf_prog_has_kfunc_call() Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 039/555] bpf: Reject programs with inlined helpers if JIT is not available Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 040/555] bpf: Disallow interpreter fallback for arena-related insns Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 041/555] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Greg Kroah-Hartman
2026-12-04 10:01 ` Greg Kroah-Hartman [this message]
2026-12-04 10:01 ` [PATCH 6.12 043/555] mm/page_alloc: use existing highatomic reserves on the buddy fastpath Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 044/555] xprtrdma: serialize unmap_sync with xprt_disconnect Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 045/555] gve: Fix race between stats query and queue reconfig Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 046/555] gve: Block invalid ring sizes when device options are 0 Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 047/555] net: wait for in-flight device unregistrations before netns dismantle Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 048/555] ksmbd: pin parent dentries in SMB2 CREATE ACL path Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 049/555] ksmbd: refuse to read a handle that is not open for reading Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 050/555] tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 051/555] comedi: comedi_bond: Fix leak of opened device references Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 052/555] Bluetooth: btusb: fix use-after-free in force_poll_sync Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 053/555] tools/bootconfig: Close only opened braces in compact output Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 054/555] ipv6: Remove IPV6_ADDRFORM Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 055/555] iio: proximity: sx9360: fix sampling frequency write and available range Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 056/555] KEYS: Expand key->{datalen,quotalen} to unsigned int Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 057/555] keys: keyctl_pkey: replace BUG with return -EOPNOTSUPP Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 058/555] KEYS: Protect pkey method checks against type removal Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 059/555] tcp: move __reqsk_free() out of line Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 060/555] tcp: free saved_syn after an RCU grace period Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 061/555] cgroup/cpuset: Correctly set isolated_cpus when switching partition state Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 062/555] arm64: suspend: rely on daif helpers to handle PMR Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 063/555] arm64: suspend: Only track cpuidle context for idle tasks Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 064/555] pNFS: avoid repeatedly cancelling I/O for the same lseg Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 065/555] watchdog: rz: Discard pm_runtime_put() return values Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 066/555] watchdog: rzv2h: Use pm_runtime_put_sync() Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 067/555] hwmon: (nct6775) Handle dual use registers Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204100607.572350472@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=fvdl@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=justinjiang@vivo.com \
    --cc=mhocko@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox