OOM killer is a mechanism that selects and kills processes when the system
runs out of memory to reclaim resources and keep the system stable.
However, the oom victim cannot terminate on its own when it is frozen,
because __thaw_task() only thaws one thread of the victim, while
the other threads remain in the frozen state.
This change will thaw the entire victim process when OOM occurs,
ensuring that the oom victim can terminate on its own.
Signed-off-by: zhongjinji <zhongjinji@honor.com>
---
mm/oom_kill.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 25923cfec9c6..3caaafc896d4 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -747,6 +747,19 @@ static inline void queue_oom_reaper(struct task_struct *tsk)
}
#endif /* CONFIG_MMU */
+static void thaw_oom_process(struct task_struct *tsk)
+{
+ struct task_struct *t;
+
+ /* protects against __exit_signal() */
+ read_lock(&tasklist_lock);
+ for_each_thread(tsk, t) {
+ set_tsk_thread_flag(t, TIF_MEMDIE);
+ __thaw_task(t);
+ }
+ read_unlock(&tasklist_lock);
+}
+
/**
* mark_oom_victim - mark the given task as OOM victim
* @tsk: task to mark
@@ -772,12 +785,12 @@ static void mark_oom_victim(struct task_struct *tsk)
mmgrab(tsk->signal->oom_mm);
/*
- * Make sure that the task is woken up from uninterruptible sleep
+ * Make sure that the process is woken up from uninterruptible sleep
* if it is frozen because OOM killer wouldn't be able to free
* any memory and livelock. freezing_slow_path will tell the freezer
- * that TIF_MEMDIE tasks should be ignored.
+ * that TIF_MEMDIE threads should be ignored.
*/
- __thaw_task(tsk);
+ thaw_oom_process(tsk);
atomic_inc(&oom_victims);
cred = get_task_cred(tsk);
trace_mark_victim(tsk, cred->uid.val);
--
2.17.1
On Wed 03-09-25 17:27:28, zhongjinji wrote: > OOM killer is a mechanism that selects and kills processes when the system > runs out of memory to reclaim resources and keep the system stable. > However, the oom victim cannot terminate on its own when it is frozen, > because __thaw_task() only thaws one thread of the victim, while > the other threads remain in the frozen state. > > This change will thaw the entire victim process when OOM occurs, > ensuring that the oom victim can terminate on its own. > > Signed-off-by: zhongjinji <zhongjinji@honor.com> > --- > mm/oom_kill.c | 19 ++++++++++++++++--- > 1 file changed, 16 insertions(+), 3 deletions(-) > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 25923cfec9c6..3caaafc896d4 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -747,6 +747,19 @@ static inline void queue_oom_reaper(struct task_struct *tsk) > } > #endif /* CONFIG_MMU */ > > +static void thaw_oom_process(struct task_struct *tsk) > +{ > + struct task_struct *t; > + > + /* protects against __exit_signal() */ > + read_lock(&tasklist_lock); > + for_each_thread(tsk, t) { > + set_tsk_thread_flag(t, TIF_MEMDIE); > + __thaw_task(t); > + } > + read_unlock(&tasklist_lock); > +} > + Sorry, I was probably not clear enough. I meant thaw_process should live in the freezer proper kernel/freezer.c and oom should be just user. Please make sure that freezer maintainers are involved and approve the change. -- Michal Hocko SUSE Labs
> > OOM killer is a mechanism that selects and kills processes when the system > > runs out of memory to reclaim resources and keep the system stable. > > However, the oom victim cannot terminate on its own when it is frozen, > > because __thaw_task() only thaws one thread of the victim, while > > the other threads remain in the frozen state. > > > > This change will thaw the entire victim process when OOM occurs, > > ensuring that the oom victim can terminate on its own. > > > > Signed-off-by: zhongjinji <zhongjinji@honor.com> > > --- > > mm/oom_kill.c | 19 ++++++++++++++++--- > > 1 file changed, 16 insertions(+), 3 deletions(-) > > > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > > index 25923cfec9c6..3caaafc896d4 100644 > > --- a/mm/oom_kill.c > > +++ b/mm/oom_kill.c > > @@ -747,6 +747,19 @@ static inline void queue_oom_reaper(struct task_struct *tsk) > > } > > #endif /* CONFIG_MMU */ > > > > +static void thaw_oom_process(struct task_struct *tsk) > > +{ > > + struct task_struct *t; > > + > > + /* protects against __exit_signal() */ > > + read_lock(&tasklist_lock); > > + for_each_thread(tsk, t) { > > + set_tsk_thread_flag(t, TIF_MEMDIE); > > + __thaw_task(t); > > + } > > + read_unlock(&tasklist_lock); > > +} > > + > > Sorry, I was probably not clear enough. I meant thaw_process should live > in the freezer proper kernel/freezer.c and oom should be just user. > Please make sure that freezer maintainers are involved and approve the > change. Thank you, I got it, It would indeed be better to have thaw_process in kernel/freezer.c. Let me CC the freezer maintainers before updating with the new changes; maybe they will have other suggestions as well. > > -- > Michal Hocko > SUSE Labs
© 2016 - 2025 Red Hat, Inc.