linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yang Xin <yx.0xffff@gmail.com>
To: akpm@linux-foundation.org, mhocko@suse.com, rientjes@google.com,
	shakeel.butt@linux.dev
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Yang Xin <redleaf@linux.alibaba.com>
Subject: [PATCH] mm/oom_kill: add sysctl_oom_dump_stack to control kernel stack dumping on OOM
Date: Fri, 12 Dec 2025 04:24:33 +0800	[thread overview]
Message-ID: <20251211202433.4495-1-redleaf@linux.alibaba.com> (raw)

    Most OOM kills triggered by user-space processes produce kernel stack
    traces that are not helpful for diagnosing the root cause. These traces
    usually just show the page fault handler or system call entry.

    Furthermore, dump_stack() can be expensive. It often runs with
    interrupts disabled or holds the console lock for a long time,
    potentially causing system latencies and preventing the system from
    responding to other events.

    This patch adds a new sysctl vm.oom_dump_stack to control this
    behavior. Writing '0' to /proc/sys/vm/oom_dump_stack suppresses the
    kernel stack dump during OOM kills, while '1' (the default) preserves
    the existing behavior.

Signed-off-by: Yang Xin <redleaf@linux.alibaba.com>
---
 mm/oom_kill.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 5eb11fbba704..a51dbd2e6912 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -56,6 +56,7 @@
 static int sysctl_panic_on_oom;
 static int sysctl_oom_kill_allocating_task;
 static int sysctl_oom_dump_tasks = 1;
+static int sysctl_oom_dump_stack = 1;
 
 /*
  * Serializes oom killer invocations (out_of_memory()) from all contexts to
@@ -464,7 +465,9 @@ static void dump_header(struct oom_control *oc)
 	if (!IS_ENABLED(CONFIG_COMPACTION) && oc->order)
 		pr_warn("COMPACTION is disabled!!!\n");
 
-	dump_stack();
+	if (sysctl_oom_dump_stack)
+		dump_stack();
+
 	if (is_memcg_oom(oc))
 		mem_cgroup_print_oom_meminfo(oc->memcg);
 	else {
@@ -736,6 +739,13 @@ static const struct ctl_table vm_oom_kill_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 	},
+	{
+                .procname       = "oom_dump_stack",
+                .data           = &sysctl_oom_dump_stack,
+                .maxlen         = sizeof(sysctl_oom_dump_stack),
+                .mode           = 0644,
+                .proc_handler   = proc_dointvec,
+        },
 };
 #endif
 
-- 
2.30.2



             reply	other threads:[~2025-12-11 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 20:24 Yang Xin [this message]
2025-12-11 20:34 ` Michal Hocko
2025-12-14  1:55   ` David Rientjes

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=20251211202433.4495-1-redleaf@linux.alibaba.com \
    --to=yx.0xffff@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=redleaf@linux.alibaba.com \
    --cc=rientjes@google.com \
    --cc=shakeel.butt@linux.dev \
    /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