Skip to contentSkip to conversation

mm/page_alloc: ?nommu? Deadlock in drain_pages_zone()?

RFC PATCH New Daniel Palmer 1 participant 1 message Dec 11, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 mm/page_alloc: ?nommu? Deadlock in drain_pages_zone()?

per_cpu_pages_init() sets pcp->batch to 1 (BOOT_PAGESET_BATCH) at boot, then later it is set to 0 (from zone_batchsize()) via the following path:

init_per_zone_wmark_min()
->setup_per_zone_wmarks()
->zone_pcp_update()

     ->zone_set_pageset_high_and_batch()

Once this happens if an OOM happens drain_pages_zone() will never return because count never gets to zero.

---

Background: I am running a nommu kernel on 68000 with 8MB of RAM, I messed up my userland config and the resulting binaries became too big to fit in to the free blocks of memory, OOM should have happened and I should have seen the kernel trying to free memory but instead it dead locked. Since this is nommu I thought maybe I am corrupting memory but I checked with gdb and it doesn't seem like it. I have some local patches to make this weird setup work too but I don't think its anything to do with that either.

This change stops the dead lock and I see OOM messages instead as expected. I have no idea if it is correct. Patch is simply to show what I am seeing.

 mm/page_alloc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mm/page_alloc.c +5 -2
index 822e05f1a964..83c9ce6f93ad 100644
@@ -2618,8 +2618,11 @@ static void drain_pages_zone(unsigned int cpu, struct zone *zone)
 		spin_lock(&pcp->lock);
 		count = pcp->count;
 		if (count) {
-			int to_drain = min(count,
-				pcp->batch << CONFIG_PCP_BATCH_SCALE_MAX);
+			int to_drain = count;
+
+			/* if pcp->batch is zero this loop will never exit, on nommu pcp->batch is always 0 */
+			if (likely(pcp->batch))
+				to_drain = min(count, pcp->batch << CONFIG_PCP_BATCH_SCALE_MAX);
 
 			free_pcppages_bulk(zone, to_drain, pcp, 0);
 			count -= to_drain;
Signature · 1 line
2.51.0