Re: [patch 4/5] sched: Delay task stack freeing on RT

From: Thomas Gleixner
Date: Fri Oct 01 2021 - 13:24:50 EST


On Fri, Oct 01 2021 at 09:12, Andy Lutomirski wrote:
> On Wed, Sep 29, 2021 at 4:54 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>> Having this logic split across two files seems unfortunate and prone to
>> 'accidents'. Is there a real down-side to unconditionally doing it in
>> delayed_put_task_struct() ?
>>
>> /me goes out for lunch... meanwhile tglx points at: 68f24b08ee89.
>>
>> Bah.. Andy?
>
> Could we make whatever we do here unconditional?

Sure. I just was unsure about your reasoning in 68f24b08ee89.

> And what actually causes the latency? If it's vfree, shouldn't the
> existing use of vfree_atomic() in free_thread_stack() handle it? Or
> is it the accounting?

The accounting muck because it can go into the allocator and sleep in
the worst case, which is nasty even on !RT kernels.

But thinking some more, there is actually a way nastier issue on RT in
the following case:

CPU 0 CPU 1
T1
spin_lock(L1)
rt_mutex_lock()
schedule()

T2
do_exit()
do_task_dead() spin_unlock(L1)
wake(T1)
__schedule()
switch_to(T1)
finish_task_switch()
put_task_stack()
account()
....
spin_lock(L2)

So if L1 == L2 or L1 and L2 have a reverse dependency then this can just
deadlock.

We've never observed that, but the above case is obviously hard to
hit. Nevertheless it's there.

Thanks,

tglx