io_uring/io-wq: reduce frequency of acct->lock acquisitions
authorJens Axboe <axboe@kernel.dk>
Wed, 9 Aug 2023 18:59:40 +0000 (12:59 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 9 Aug 2023 19:34:43 +0000 (13:34 -0600)
commit47f9ee73a406b194678b3cd604553e1ef7f66a3f
treea70a46aed3c65bd372a3e09769ffe6b28ecbfc99
parent2e324b0fd27589a7733606c90cffa38c202cdcd7
io_uring/io-wq: reduce frequency of acct->lock acquisitions

When we check if we have work to run, we grab the acct lock, check,
drop it, and then return the result. If we do have work to run, then
running the work will again grab acct->lock and get the work item.

This causes us to grab acct->lock more frequently than we need to.
If we have work to do, have io_acct_run_queue() return with the acct
lock still acquired. io_worker_handle_work() is then always invoked
with the acct lock already held.

In a simple test cases that stats files (IORING_OP_STATX always hits
io-wq), we see a nice reduction in locking overhead with this change:

19.32%   -12.55%  [kernel.kallsyms]      [k] __cmpwait_case_32
20.90%   -12.07%  [kernel.kallsyms]      [k] queued_spin_lock_slowpath

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io-wq.c