Re: [PATCH 1/2] mm, oom: introduce oom reaper

From: Michal Hocko
Date: Thu Jan 07 2016 - 07:31:04 EST


On Thu 07-01-16 20:23:04, Tetsuo Handa wrote:
[...]
> According to commit a2b829d95958da20 ("mm/oom_kill.c: avoid attempting
> to kill init sharing same memory"), below patch is needed for avoid
> killing init process with SIGSEGV.
>
> ----------
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 9548dce..9832f3f 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -784,9 +784,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
> continue;
> if (same_thread_group(p, victim))
> continue;
> - if (is_global_init(p))
> - continue;
> - if (unlikely(p->flags & PF_KTHREAD) ||
> + if (unlikely(p->flags & PF_KTHREAD) || is_global_init(p) ||
> p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) {
> /*
> * We cannot use oom_reaper for the mm shared by this
[...]
> [ 3.132836] [ pid ] uid tgid total_vm rss nr_ptes nr_pmds swapents oom_score_adj name
> [ 3.137232] [ 98] 0 98 279607 244400 489 5 0 0 init
> [ 3.141664] Out of memory: Kill process 98 (init) score 940 or sacrifice child
> [ 3.145346] Killed process 98 (init) total-vm:1118428kB, anon-rss:977464kB, file-rss:136kB, shmem-rss:0kB
> [ 3.416105] init[1]: segfault at 0 ip (null) sp 00007ffd484cf5f0 error 14 in init[400000+1000]
> [ 3.439074] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> [ 3.439074]
> [ 3.450193] Kernel Offset: disabled
> [ 3.456259] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> [ 3.456259]

Ouch. You are right. The reaper will tear down the shared mm and the
global init will blow up. Very well spotted! The system will blow up
later, I would guess, because killing the victim wouldn't release a lot
of memory which will be pinned by the global init. So a panic sounds
unevitable. The scenario is really insane but what you are proposing is
correct.

Updated patch below.
---