From: zhongjinji <zhongjinji@honor.com>
To: <mhocko@suse.com>
Cc: <rientjes@google.com>, <shakeel.butt@linux.dev>,
<akpm@linux-foundation.org>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, <tglx@linutronix.de>,
<liam.howlett@oracle.com>, <lorenzo.stoakes@oracle.com>,
<liulu.liu@honor.com>, <feng.han@honor.com>,
<zhongjinji@honor.com>
Subject: [PATCH v5 1/2] mm/oom_kill: Do not delay oom reaper when the victim is frozen
Date: Mon, 25 Aug 2025 21:38:54 +0800 [thread overview]
Message-ID: <20250825133855.30229-2-zhongjinji@honor.com> (raw)
In-Reply-To: <20250825133855.30229-1-zhongjinji@honor.com>
The OOM reaper can quickly reap a process's memory when the system
encounters OOM, helping the system recover. If the victim process is
frozen and cannot be unfrozen in time, the reaper delayed by two seconds
will cause the system to fail to recover quickly from the OOM state.
When an OOM occurs, if the victim is not unfrozen, delaying the OOM reaper
will keep the system in a bad state for two seconds. Before scheduling the
oom_reaper task, check whether the victim is in a frozen state. If the
victim is frozen, do not delay the OOM reaper.
Signed-off-by: zhongjinji <zhongjinji@honor.com>
---
mm/oom_kill.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 25923cfec9c6..4b4d73b1e00d 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -683,6 +683,41 @@ static void wake_oom_reaper(struct timer_list *timer)
wake_up(&oom_reaper_wait);
}
+/*
+ * When the victim is frozen, the OOM reaper should not be delayed, because
+ * if the victim cannot be unfrozen promptly, it may block the system from
+ * quickly recovering from the OOM state.
+ */
+static bool should_delay_oom_reap(struct task_struct *tsk)
+{
+ struct mm_struct *mm = tsk->mm;
+ struct task_struct *p;
+ bool ret;
+
+ if (!mm)
+ return true;
+
+ if (!frozen(tsk))
+ return true;
+
+ if (atomic_read(&mm->mm_users) <= 1)
+ return false;
+
+ rcu_read_lock();
+ for_each_process(p) {
+ if (!process_shares_mm(p, mm))
+ continue;
+ if (same_thread_group(tsk, p))
+ continue;
+ ret = !frozen(p);
+ if (ret)
+ break;
+ }
+ rcu_read_unlock();
+
+ return ret;
+}
+
/*
* Give the OOM victim time to exit naturally before invoking the oom_reaping.
* The timers timeout is arbitrary... the longer it is, the longer the worst
@@ -694,13 +729,16 @@ static void wake_oom_reaper(struct timer_list *timer)
#define OOM_REAPER_DELAY (2*HZ)
static void queue_oom_reaper(struct task_struct *tsk)
{
+ bool delay;
+
/* mm is already queued? */
if (test_and_set_bit(MMF_OOM_REAP_QUEUED, &tsk->signal->oom_mm->flags))
return;
get_task_struct(tsk);
+ delay = should_delay_oom_reap(tsk);
timer_setup(&tsk->oom_reaper_timer, wake_oom_reaper, 0);
- tsk->oom_reaper_timer.expires = jiffies + OOM_REAPER_DELAY;
+ tsk->oom_reaper_timer.expires = jiffies + (delay ? OOM_REAPER_DELAY : 0);
add_timer(&tsk->oom_reaper_timer);
}
--
2.17.1
next prev parent reply other threads:[~2025-08-25 13:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-25 13:38 [PATCH v5 0/2] " zhongjinji
2025-08-25 13:38 ` zhongjinji [this message]
2025-08-25 19:41 ` [PATCH v5 1/2] mm/oom_kill: " Shakeel Butt
2025-08-26 13:01 ` zhongjinji
2025-08-26 12:43 ` Lorenzo Stoakes
2025-08-27 12:08 ` Michal Hocko
2025-08-27 12:14 ` zhongjinji
2025-08-25 13:38 ` [PATCH v5 2/2] mm/oom_kill: Have the OOM reaper and exit_mmap() traverse the maple tree in opposite order zhongjinji
2025-08-26 12:53 ` Lorenzo Stoakes
2025-08-26 13:37 ` Liam R. Howlett
2025-08-26 13:50 ` Lorenzo Stoakes
2025-08-26 15:21 ` Liam R. Howlett
2025-08-26 22:26 ` Shakeel Butt
2025-08-27 4:12 ` Liam R. Howlett
2025-08-27 4:25 ` Liam R. Howlett
2025-08-27 9:55 ` zhongjinji
2025-08-27 15:57 ` Suren Baghdasaryan
2025-08-28 0:38 ` Liam R. Howlett
2025-08-29 7:11 ` Michal Hocko
2025-08-29 7:14 ` Michal Hocko
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=20250825133855.30229-2-zhongjinji@honor.com \
--to=zhongjinji@honor.com \
--cc=akpm@linux-foundation.org \
--cc=feng.han@honor.com \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liulu.liu@honor.com \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=shakeel.butt@linux.dev \
--cc=tglx@linutronix.de \
/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