Skip to content

Commit a73f730

Browse files
htejunaxboe
authored andcommitted
block, cfq: move cfqd->cic_index to q->id
cfq allocates per-queue id using ida and uses it to index cic radix tree from io_context. Move it to q->id and allocate on queue init and free on queue release. This simplifies cfq a bit and will allow for further improvements of io context life-cycle management. This patch doesn't introduce any functional difference. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8ba6143 commit a73f730

5 files changed

Lines changed: 32 additions & 55 deletions

File tree

‎block/blk-core.c‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
3939
EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
4040
EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete);
4141

42+
DEFINE_IDA(blk_queue_ida);
43+
4244
/*
4345
* For the allocated request tables
4446
*/
@@ -474,22 +476,22 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
474476
if (!q)
475477
return NULL;
476478

479+
q->id = ida_simple_get(&blk_queue_ida, 0, 0, GFP_KERNEL);
480+
if (q->id < 0)
481+
goto fail_q;
482+
477483
q->backing_dev_info.ra_pages =
478484
(VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
479485
q->backing_dev_info.state = 0;
480486
q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY;
481487
q->backing_dev_info.name = "block";
482488

483489
err = bdi_init(&q->backing_dev_info);
484-
if (err) {
485-
kmem_cache_free(blk_requestq_cachep, q);
486-
return NULL;
487-
}
490+
if (err)
491+
goto fail_id;
488492

489-
if (blk_throtl_init(q)) {
490-
kmem_cache_free(blk_requestq_cachep, q);
491-
return NULL;
492-
}
493+
if (blk_throtl_init(q))
494+
goto fail_id;
493495

494496
setup_timer(&q->backing_dev_info.laptop_mode_wb_timer,
495497
laptop_mode_timer_fn, (unsigned long) q);
@@ -512,6 +514,12 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
512514
q->queue_lock = &q->__queue_lock;
513515

514516
return q;
517+
518+
fail_id:
519+
ida_simple_remove(&blk_queue_ida, q->id);
520+
fail_q:
521+
kmem_cache_free(blk_requestq_cachep, q);
522+
return NULL;
515523
}
516524
EXPORT_SYMBOL(blk_alloc_queue_node);
517525

‎block/blk-sysfs.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ static void blk_release_queue(struct kobject *kobj)
494494
blk_trace_shutdown(q);
495495

496496
bdi_destroy(&q->backing_dev_info);
497+
498+
ida_simple_remove(&blk_queue_ida, q->id);
497499
kmem_cache_free(blk_requestq_cachep, q);
498500
}
499501

‎block/blk.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef BLK_INTERNAL_H
22
#define BLK_INTERNAL_H
33

4+
#include <linux/idr.h>
5+
46
/* Amount of time in which a process may batch requests */
57
#define BLK_BATCH_TIME (HZ/50UL)
68

@@ -9,6 +11,7 @@
911

1012
extern struct kmem_cache *blk_requestq_cachep;
1113
extern struct kobj_type blk_queue_ktype;
14+
extern struct ida blk_queue_ida;
1215

1316
void init_request_from_bio(struct request *req, struct bio *bio);
1417
void blk_rq_bio_prep(struct request_queue *q, struct request *rq,

‎block/cfq-iosched.c‎

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ static DEFINE_PER_CPU(unsigned long, cfq_ioc_count);
6565
static struct completion *ioc_gone;
6666
static DEFINE_SPINLOCK(ioc_gone_lock);
6767

68-
static DEFINE_SPINLOCK(cic_index_lock);
69-
static DEFINE_IDA(cic_index_ida);
70-
7168
#define CFQ_PRIO_LISTS IOPRIO_BE_NR
7269
#define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
7370
#define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT)
@@ -290,7 +287,6 @@ struct cfq_data {
290287
unsigned int cfq_group_idle;
291288
unsigned int cfq_latency;
292289

293-
unsigned int cic_index;
294290
struct list_head cic_list;
295291

296292
/*
@@ -484,7 +480,7 @@ static inline void cic_set_cfqq(struct cfq_io_context *cic,
484480

485481
static inline void *cfqd_dead_key(struct cfq_data *cfqd)
486482
{
487-
return (void *)(cfqd->cic_index << CIC_DEAD_INDEX_SHIFT | CIC_DEAD_KEY);
483+
return (void *)(cfqd->queue->id << CIC_DEAD_INDEX_SHIFT | CIC_DEAD_KEY);
488484
}
489485

490486
static inline struct cfq_data *cic_to_cfqd(struct cfq_io_context *cic)
@@ -3105,7 +3101,7 @@ cfq_drop_dead_cic(struct cfq_data *cfqd, struct io_context *ioc,
31053101
BUG_ON(rcu_dereference_check(ioc->ioc_data,
31063102
lockdep_is_held(&ioc->lock)) == cic);
31073103

3108-
radix_tree_delete(&ioc->radix_root, cfqd->cic_index);
3104+
radix_tree_delete(&ioc->radix_root, cfqd->queue->id);
31093105
hlist_del_rcu(&cic->cic_list);
31103106
spin_unlock_irqrestore(&ioc->lock, flags);
31113107

@@ -3133,7 +3129,7 @@ cfq_cic_lookup(struct cfq_data *cfqd, struct io_context *ioc)
31333129
}
31343130

31353131
do {
3136-
cic = radix_tree_lookup(&ioc->radix_root, cfqd->cic_index);
3132+
cic = radix_tree_lookup(&ioc->radix_root, cfqd->queue->id);
31373133
rcu_read_unlock();
31383134
if (!cic)
31393135
break;
@@ -3169,8 +3165,7 @@ static int cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc,
31693165
cic->key = cfqd;
31703166

31713167
spin_lock_irqsave(&ioc->lock, flags);
3172-
ret = radix_tree_insert(&ioc->radix_root,
3173-
cfqd->cic_index, cic);
3168+
ret = radix_tree_insert(&ioc->radix_root, cfqd->queue->id, cic);
31743169
if (!ret)
31753170
hlist_add_head_rcu(&cic->cic_list, &ioc->cic_list);
31763171
spin_unlock_irqrestore(&ioc->lock, flags);
@@ -3944,10 +3939,6 @@ static void cfq_exit_queue(struct elevator_queue *e)
39443939

39453940
cfq_shutdown_timer_wq(cfqd);
39463941

3947-
spin_lock(&cic_index_lock);
3948-
ida_remove(&cic_index_ida, cfqd->cic_index);
3949-
spin_unlock(&cic_index_lock);
3950-
39513942
/*
39523943
* Wait for cfqg->blkg->key accessors to exit their grace periods.
39533944
* Do this wait only if there are other unlinked groups out
@@ -3969,48 +3960,16 @@ static void cfq_exit_queue(struct elevator_queue *e)
39693960
kfree(cfqd);
39703961
}
39713962

3972-
static int cfq_alloc_cic_index(void)
3973-
{
3974-
int index, error;
3975-
3976-
do {
3977-
if (!ida_pre_get(&cic_index_ida, GFP_KERNEL))
3978-
return -ENOMEM;
3979-
3980-
spin_lock(&cic_index_lock);
3981-
error = ida_get_new(&cic_index_ida, &index);
3982-
spin_unlock(&cic_index_lock);
3983-
if (error && error != -EAGAIN)
3984-
return error;
3985-
} while (error);
3986-
3987-
return index;
3988-
}
3989-
39903963
static void *cfq_init_queue(struct request_queue *q)
39913964
{
39923965
struct cfq_data *cfqd;
39933966
int i, j;
39943967
struct cfq_group *cfqg;
39953968
struct cfq_rb_root *st;
39963969

3997-
i = cfq_alloc_cic_index();
3998-
if (i < 0)
3999-
return NULL;
4000-
40013970
cfqd = kmalloc_node(sizeof(*cfqd), GFP_KERNEL | __GFP_ZERO, q->node);
4002-
if (!cfqd) {
4003-
spin_lock(&cic_index_lock);
4004-
ida_remove(&cic_index_ida, i);
4005-
spin_unlock(&cic_index_lock);
3971+
if (!cfqd)
40063972
return NULL;
4007-
}
4008-
4009-
/*
4010-
* Don't need take queue_lock in the routine, since we are
4011-
* initializing the ioscheduler, and nobody is using cfqd
4012-
*/
4013-
cfqd->cic_index = i;
40143973

40153974
/* Init root service tree */
40163975
cfqd->grp_service_tree = CFQ_RB_ROOT;
@@ -4294,7 +4253,6 @@ static void __exit cfq_exit(void)
42944253
*/
42954254
if (elv_ioc_count_read(cfq_ioc_count))
42964255
wait_for_completion(&all_gone);
4297-
ida_destroy(&cic_index_ida);
42984256
cfq_slab_kill();
42994257
}
43004258

‎include/linux/blkdev.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ struct request_queue {
310310
*/
311311
unsigned long queue_flags;
312312

313+
/*
314+
* ida allocated id for this queue. Used to index queues from
315+
* ioctx.
316+
*/
317+
int id;
318+
313319
/*
314320
* queue needs bounce pages for pages above this limit
315321
*/

0 commit comments

Comments
 (0)