backend: check if we need to update rusage stats, if stat_mutex is busy
authorJens Axboe <axboe@fb.com>
Fri, 26 Aug 2016 20:39:30 +0000 (14:39 -0600)
committerJens Axboe <axboe@fb.com>
Fri, 26 Aug 2016 20:39:30 +0000 (14:39 -0600)
commit39d13e67ef1f4b327c68431f8daf033a03920117
tree9485bdf2e6e7e1fb98655c75c5e769c645a9f63f
parent747b310559e6611dfaa5ff13cf43538043f91323
backend: check if we need to update rusage stats, if stat_mutex is busy

Even with the fix to check if we need to update rusage happening
right before the stat_mutex lock, we can still deadlock. This
looks something like the below:

helper_thread                   job

lock(stat_mutex);
                                lock(stat_mutex);
down(td->rusage_sem);

And now are both effectively locked in an ABBA deadlock. The helper
thread is waiting for the job to update it's rusage, but the job
is stuck waiting for the stat_mutex.

Fix this by doing a trylock on the stat_mutex, and if it fails,
ensure that we update rusage.

Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c