Re: [Patch] freezer: check OOM kill signal while being frozen

From: Michal Hocko
Date: Mon Aug 11 2014 - 09:18:36 EST


On Fri 08-08-14 17:46:38, Cong Wang wrote:
> There is a race condition between OOM killer and freezer when
> they try to operate on the same process, something like below:
>
> Process A Process B Process C
> trigger oom
> B=oom_scan_process_thread()
> cgroup_freezer_freeze(B)
> ...
> try_to_freeze()
> stay in D state
> oom_kill_process(B)
>
> In this case, process A triggers OOM and kernel selects process B
> as the victim, right before being killed process B was frozen by
> process C therefore went to D state, then kernel sent SIGKILL but
> it is already too late as process B will never care about pending
> signals any more.

OK, so the system/memcg is still OOM and a new allocation/charge
would trigger killer again, right? Then oom_scan_process_thread sees
TIF_MEMDIE frozen task and thaw it so it can go away and die. So this
shouldn't be a permanent state. Or am I missing something?

> Fix this straightly by checking fatal pending signal
> from OOM killer, so that the frozen process will recover itself
> and then be killed finally.
>
> Cc: David Rientjes <rientjes@xxxxxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxx>
> Cc: "Rafael J. Wysocki" <rjw@xxxxxxxxxxxxx>
> Cc: Tejun Heo <tj@xxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Cong Wang <xiyou.wangcong@xxxxxxxxx>
> ---
> diff --git a/kernel/freezer.c b/kernel/freezer.c
> index aa6a8aa..c6d189d 100644
> --- a/kernel/freezer.c
> +++ b/kernel/freezer.c
> @@ -68,7 +68,9 @@ bool __refrigerator(bool check_kthr_stop)
> spin_lock_irq(&freezer_lock);
> current->flags |= PF_FROZEN;
> if (!freezing(current) ||
> - (check_kthr_stop && kthread_should_stop()))
> + (check_kthr_stop && kthread_should_stop()) ||
> + (test_tsk_thread_flag(current, TIF_MEMDIE) &&
> + fatal_signal_pending(current)))
> current->flags &= ~PF_FROZEN;
> spin_unlock_irq(&freezer_lock);
>

--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/