linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Palmer <daniel@thingy.jp>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Daniel Palmer <daniel@thingy.jp>
Subject: [RFC PATCH] mm/page_alloc: ?nommu? Deadlock in drain_pages_zone()?
Date: Thu, 11 Dec 2025 19:26:07 +0900	[thread overview]
Message-ID: <20251211102607.2538595-1-daniel@thingy.jp> (raw)

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.

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---

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(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 822e05f1a964..83c9ce6f93ad 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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;
-- 
2.51.0



                 reply	other threads:[~2025-12-11 10:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20251211102607.2538595-1-daniel@thingy.jp \
    --to=daniel@thingy.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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