Re: [PATCH -v2] freezer: check OOM kill while being frozen

From: Oleg Nesterov
Date: Fri Oct 17 2014 - 12:13:42 EST


On 10/17, Michal Hocko wrote:
>
> I think we should rather get back to __thaw_task here.

Yes, agreed.

> Andrew could you replace the previous version by this one, please?

Yes, that patch should be dropped...


And can't resist... please look at
http://marc.info/?l=linux-kernel&m=138427535430827 ;)

> --- a/kernel/freezer.c
> +++ b/kernel/freezer.c
> @@ -45,13 +45,28 @@ bool freezing_slow_path(struct task_struct *p)
> if (pm_nosig_freezing || cgroup_freezing(p))
> return true;
>
> - if (pm_freezing && !(p->flags & PF_KTHREAD))
> + if (!(p->flags & PF_KTHREAD))

Why? Doesn't this mean that try_to_freeze() can race with thaw_processes()
and then this task can be frozen for no reazon?

> +static bool should_thaw_current(bool check_kthr_stop)
> +{
> + if (!freezing(current))
> + return true;
> +
> + if (check_kthr_stop && kthread_should_stop())
> + return true;
> +
> + /* It might not be safe to check TIF_MEMDIE for pm freeze. */
> + if (cgroup_freezing(current) && test_thread_flag(TIF_MEMDIE))

I still think that the comment should tell more to explain why this
is not safe.

And if this is not safe, it is not clear how/why cgroup_freezing() can
save us, both pm_freezing and CGROUP_FREEZING can be true?

And I think that this TIF_MEMDIE should go into freezing_slow_path(),
so we do not even need should_thaw_current().

This also looks more safe to me. Suppose that a task does

while (try_to_freeze())
;

Yes, this is pointless but correct. And in fact I think this pattern
is possible. If this task is killed by OOM, it will spin forever.

Oleg.

--
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/