Skip to content

Commit

Permalink
block: move blk_mq_tag_to_rq() inline
Browse files Browse the repository at this point in the history
This is in the fast path of driver issue or completion, and it's a single
array index operation. Move it inline to avoid a function call for it.

This does mean making struct blk_mq_tags block layer public, but there's
not really much in there.

Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Oct 19, 2021
1 parent df87eb0 commit e028f16
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
23 changes: 0 additions & 23 deletions block/blk-mq-tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@

struct blk_mq_alloc_data;

/*
* Tag address space map.
*/
struct blk_mq_tags {
unsigned int nr_tags;
unsigned int nr_reserved_tags;

atomic_t active_queues;

struct sbitmap_queue bitmap_tags;
struct sbitmap_queue breserved_tags;

struct request **rqs;
struct request **static_rqs;
struct list_head page_list;

/*
* used to clear request reference in rqs[] before freeing one
* request pool
*/
spinlock_t lock;
};

extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags,
unsigned int reserved_tags,
int node, int alloc_policy);
Expand Down
11 changes: 0 additions & 11 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,17 +1120,6 @@ void blk_mq_delay_kick_requeue_list(struct request_queue *q,
}
EXPORT_SYMBOL(blk_mq_delay_kick_requeue_list);

struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag)
{
if (tag < tags->nr_tags) {
prefetch(tags->rqs[tag]);
return tags->rqs[tag];
}

return NULL;
}
EXPORT_SYMBOL(blk_mq_tag_to_rq);

static bool blk_mq_rq_inflight(struct blk_mq_hw_ctx *hctx, struct request *rq,
void *priv, bool reserved)
{
Expand Down
36 changes: 35 additions & 1 deletion include/linux/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/srcu.h>
#include <linux/lockdep.h>
#include <linux/scatterlist.h>
#include <linux/prefetch.h>

struct blk_mq_tags;
struct blk_flush_queue;
Expand Down Expand Up @@ -675,7 +676,40 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
unsigned int op, blk_mq_req_flags_t flags,
unsigned int hctx_idx);
struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);

/*
* Tag address space map.
*/
struct blk_mq_tags {
unsigned int nr_tags;
unsigned int nr_reserved_tags;

atomic_t active_queues;

struct sbitmap_queue bitmap_tags;
struct sbitmap_queue breserved_tags;

struct request **rqs;
struct request **static_rqs;
struct list_head page_list;

/*
* used to clear request reference in rqs[] before freeing one
* request pool
*/
spinlock_t lock;
};

static inline struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags,
unsigned int tag)
{
if (tag < tags->nr_tags) {
prefetch(tags->rqs[tag]);
return tags->rqs[tag];
}

return NULL;
}

enum {
BLK_MQ_UNIQUE_TAG_BITS = 16,
Expand Down

0 comments on commit e028f16

Please sign in to comment.