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. Since __thaw_task did not fully thaw the OOM victim for self-termination, introduce thaw_oom_process() to properly thaw OOM victims. Signed-off-by: zhongjinji --- include/linux/freezer.h | 2 ++ kernel/freezer.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/freezer.h b/include/linux/freezer.h index b303472255be..19a4b57950cd 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -47,6 +47,7 @@ extern int freeze_processes(void); extern int freeze_kernel_threads(void); extern void thaw_processes(void); extern void thaw_kernel_threads(void); +extern void thaw_oom_process(struct task_struct *p); static inline bool try_to_freeze(void) { @@ -80,6 +81,7 @@ static inline int freeze_processes(void) { return -ENOSYS; } static inline int freeze_kernel_threads(void) { return -ENOSYS; } static inline void thaw_processes(void) {} static inline void thaw_kernel_threads(void) {} +static inline void thaw_oom_process(struct task_struct *p) {} static inline bool try_to_freeze(void) { return false; } diff --git a/kernel/freezer.c b/kernel/freezer.c index 6a96149aede9..17970e0be8a7 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -206,6 +206,25 @@ void __thaw_task(struct task_struct *p) wake_up_state(p, TASK_FROZEN); } +/* + * thaw_oom_process - thaw the OOM victim process + * @p: process to be thawed + * + * Sets TIF_MEMDIE for all threads in the process group and thaws them. + * Threads with TIF_MEMDIE are ignored by the freezer. + */ +void thaw_oom_process(struct task_struct *p) +{ + struct task_struct *t; + + rcu_read_lock(); + for_each_thread(p, t) { + set_tsk_thread_flag(t, TIF_MEMDIE); + __thaw_task(t); + } + rcu_read_unlock(); +} + /** * set_freezable - make %current freezable * -- 2.17.1