blk-mq: implement new and more efficient tagging scheme
authorJens Axboe <axboe@fb.com>
Fri, 9 May 2014 15:36:49 +0000 (09:36 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 30 Mar 2015 18:54:47 +0000 (12:54 -0600)
commit5dfd2f01050d86a38dccb4f0ab3ddc04f108bb67
tree4eeed4fd25b2cbab8c9bf63975a3986192530ab9
parent5324eaebf09a252fa17d0df844fdd88318a96c6a
blk-mq: implement new and more efficient tagging scheme

blk-mq currently uses percpu_ida for tag allocation. But that only
works well if the ratio between tag space and number of CPUs is
sufficiently high. For most devices and systems, that is not the
case. The end result if that we either only utilize the tag space
partially, or we end up attempting to fully exhaust it and run
into lots of lock contention with stealing between CPUs. This is
not optimal.

This new tagging scheme is a hybrid bitmap allocator. It uses
two tricks to both be SMP friendly and allow full exhaustion
of the space:

1) We cache the last allocated (or freed) tag on a per blk-mq
   software context basis. This allows us to limit the space
   we have to search. The key element here is not caching it
   in the shared tag structure, otherwise we end up dirtying
   more shared cache lines on each allocate/free operation.

2) The tag space is split into cache line sized groups, and
   each context will start off randomly in that space. Even up
   to full utilization of the space, this divides the tag users
   efficiently into cache line groups, avoiding dirtying the same
   one both between allocators and between allocator and freeer.

This scheme shows drastically better behaviour, both on small
tag spaces but on large ones as well. It has been tested extensively
to show better performance for all the cases blk-mq cares about.

Signed-off-by: Jens Axboe <axboe@fb.com>
block/blk-mq-tag.c
block/blk-mq-tag.h
block/blk-mq.c
block/blk-mq.h
include/linux/blk-mq.h