Re: [PATCH -next] locking/percpu-rwsem: fix a task_struct refcount

From: Qian Cai
Date: Fri Mar 27 2020 - 06:19:42 EST




> On Mar 27, 2020, at 5:37 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> If the trylock fails, someone else got the lock and we remain on the
> waitqueue. It seems like a very bad idea to put the task while it
> remains on the waitqueue, no?

Interesting, I thought this was more straightforward to see, but I may be wrong as always. At the beginning of percpu_rwsem_wake_function() it calls get_task_struct(), but if the trylock failed, it will remain in the waitqueue. However, it will run percpu_rwsem_wake_function() again with get_task_struct() to increase the refcount. Can you enlighten me where it will call put_task_struct() in waitqueue or elsewhere to balance the refcount in this case?