]> git.baikalelectronics.ru Git - kernel.git/commit
blk-mq: use percpu_ref for mq usage count
authorTejun Heo <tj@kernel.org>
Tue, 1 Jul 2014 16:34:38 +0000 (10:34 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 1 Jul 2014 16:34:38 +0000 (10:34 -0600)
commitcf1153e33d16dd008b5954a6da78cbe0334a4f69
tree905e2f2f3a7753536a83f9c4b047e44f039a4bfe
parent6456c243e9017384b28780ed8b3c32eb53624d0f
blk-mq: use percpu_ref for mq usage count

Currently, blk-mq uses a percpu_counter to keep track of how many
usages are in flight.  The percpu_counter is drained while freezing to
ensure that no usage is left in-flight after freezing is complete.
blk_mq_queue_enter/exit() and blk_mq_[un]freeze_queue() implement this
per-cpu gating mechanism.

This type of code has relatively high chance of subtle bugs which are
extremely difficult to trigger and it's way too hairy to be open coded
in blk-mq.  percpu_ref can serve the same purpose after the recent
changes.  This patch replaces the open-coded per-cpu usage counting
and draining mechanism with percpu_ref.

blk_mq_queue_enter() performs tryget_live on the ref and exit()
performs put.  blk_mq_freeze_queue() kills the ref and waits until the
reference count reaches zero.  blk_mq_unfreeze_queue() revives the ref
and wakes up the waiters.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Kent Overstreet <kmo@daterainc.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
block/blk-mq.c
include/linux/blkdev.h