Skip to content

Commit

Permalink
block: move blk_mq_sched_assign_ioc to blk-ioc.c
Browse files Browse the repository at this point in the history
Move blk_mq_sched_assign_ioc so that many interfaces from the file can
be marked static.  Rename the function to ioc_find_get_icq as well and
return the icq to simplify the interface.

Signed-off-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Nov 29, 2021
1 parent 3304742 commit 87dd1d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion block/bfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -6666,7 +6666,7 @@ static struct bfq_queue *bfq_get_bfqq_handle_split(struct bfq_data *bfqd,
*/
static void bfq_prepare_request(struct request *rq)
{
blk_mq_sched_assign_ioc(rq);
rq->elv.icq = ioc_find_get_icq(rq->q);

/*
* Regardless of whether we have an icq attached, we have to
Expand Down
39 changes: 35 additions & 4 deletions block/blk-ioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static struct kmem_cache *iocontext_cachep;
*
* Increment reference count to @ioc.
*/
void get_io_context(struct io_context *ioc)
static void get_io_context(struct io_context *ioc)
{
BUG_ON(atomic_long_read(&ioc->refcount) <= 0);
atomic_long_inc(&ioc->refcount);
Expand Down Expand Up @@ -248,7 +248,8 @@ void ioc_clear_queue(struct request_queue *q)
__ioc_clear_queue(&icq_list);
}

int create_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node)
static int create_task_io_context(struct task_struct *task, gfp_t gfp_flags,
int node)
{
struct io_context *ioc;
int ret;
Expand Down Expand Up @@ -397,8 +398,8 @@ EXPORT_SYMBOL(ioc_lookup_icq);
* The caller is responsible for ensuring @ioc won't go away and @q is
* alive and will stay alive until this function returns.
*/
struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q,
gfp_t gfp_mask)
static struct io_cq *ioc_create_icq(struct io_context *ioc,
struct request_queue *q, gfp_t gfp_mask)
{
struct elevator_type *et = q->elevator->type;
struct io_cq *icq;
Expand Down Expand Up @@ -441,6 +442,36 @@ struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q,
return icq;
}

struct io_cq *ioc_find_get_icq(struct request_queue *q)
{
struct io_context *ioc;
struct io_cq *icq;

/* create task io_context, if we don't have one already */
if (unlikely(!current->io_context))
create_task_io_context(current, GFP_ATOMIC, q->node);

/*
* May not have an IO context if it's a passthrough request
*/
ioc = current->io_context;
if (!ioc)
return NULL;

spin_lock_irq(&q->queue_lock);
icq = ioc_lookup_icq(ioc, q);
spin_unlock_irq(&q->queue_lock);

if (!icq) {
icq = ioc_create_icq(ioc, q, GFP_ATOMIC);
if (!icq)
return NULL;
}
get_io_context(icq->ioc);
return icq;
}
EXPORT_SYMBOL_GPL(ioc_find_get_icq);

static int __init blk_ioc_init(void)
{
iocontext_cachep = kmem_cache_create("blkdev_ioc",
Expand Down
31 changes: 0 additions & 31 deletions block/blk-mq-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,6 @@
#include "blk-mq-tag.h"
#include "blk-wbt.h"

void blk_mq_sched_assign_ioc(struct request *rq)
{
struct request_queue *q = rq->q;
struct io_context *ioc;
struct io_cq *icq;

/* create task io_context, if we don't have one already */
if (unlikely(!current->io_context))
create_task_io_context(current, GFP_ATOMIC, q->node);

/*
* May not have an IO context if it's a passthrough request
*/
ioc = current->io_context;
if (!ioc)
return;

spin_lock_irq(&q->queue_lock);
icq = ioc_lookup_icq(ioc, q);
spin_unlock_irq(&q->queue_lock);

if (!icq) {
icq = ioc_create_icq(ioc, q, GFP_ATOMIC);
if (!icq)
return;
}
get_io_context(icq->ioc);
rq->elv.icq = icq;
}
EXPORT_SYMBOL_GPL(blk_mq_sched_assign_ioc);

/*
* Mark a hardware queue as needing a restart. For shared queues, maintain
* a count of how many hardware queues are marked for restart.
Expand Down
2 changes: 0 additions & 2 deletions block/blk-mq-sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ)

void blk_mq_sched_assign_ioc(struct request *rq);

bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
unsigned int nr_segs, struct request **merged_request);
bool blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio,
Expand Down
6 changes: 1 addition & 5 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,10 @@ static inline unsigned int bio_aligned_discard_max_sectors(
/*
* Internal io_context interface
*/
void get_io_context(struct io_context *ioc);
struct io_cq *ioc_find_get_icq(struct request_queue *q);
struct io_cq *ioc_lookup_icq(struct io_context *ioc, struct request_queue *q);
struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q,
gfp_t gfp_mask);
void ioc_clear_queue(struct request_queue *q);

int create_task_io_context(struct task_struct *task, gfp_t gfp_mask, int node);

#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
extern ssize_t blk_throtl_sample_time_show(struct request_queue *q, char *page);
extern ssize_t blk_throtl_sample_time_store(struct request_queue *q,
Expand Down

0 comments on commit 87dd1d6

Please sign in to comment.