Skip to content

Commit 3d3c237

Browse files
htejunaxboe
authored andcommitted
block, cfq: move icq cache management to block core
Let elevators set ->icq_size and ->icq_align in elevator_type and elv_register() and elv_unregister() respectively create and destroy kmem_cache for icq. * elv_register() now can return failure. All callers updated. * icq caches are automatically named "ELVNAME_io_cq". * cfq_slab_setup/kill() are collapsed into cfq_init/exit(). * While at it, minor indentation change for iosched_cfq.elevator_name for consistency. This will help moving icq management to block core. This doesn't introduce any functional change. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 47fdd4c commit 3d3c237

5 files changed

Lines changed: 62 additions & 42 deletions

File tree

‎block/cfq-iosched.c‎

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,34 +3914,6 @@ static void *cfq_init_queue(struct request_queue *q)
39143914
return cfqd;
39153915
}
39163916

3917-
static void cfq_slab_kill(void)
3918-
{
3919-
/*
3920-
* Caller already ensured that pending RCU callbacks are completed,
3921-
* so we should have no busy allocations at this point.
3922-
*/
3923-
if (cfq_pool)
3924-
kmem_cache_destroy(cfq_pool);
3925-
if (cfq_icq_pool)
3926-
kmem_cache_destroy(cfq_icq_pool);
3927-
}
3928-
3929-
static int __init cfq_slab_setup(void)
3930-
{
3931-
cfq_pool = KMEM_CACHE(cfq_queue, 0);
3932-
if (!cfq_pool)
3933-
goto fail;
3934-
3935-
cfq_icq_pool = KMEM_CACHE(cfq_io_cq, 0);
3936-
if (!cfq_icq_pool)
3937-
goto fail;
3938-
3939-
return 0;
3940-
fail:
3941-
cfq_slab_kill();
3942-
return -ENOMEM;
3943-
}
3944-
39453917
/*
39463918
* sysfs parts below -->
39473919
*/
@@ -4053,8 +4025,10 @@ static struct elevator_type iosched_cfq = {
40534025
.elevator_init_fn = cfq_init_queue,
40544026
.elevator_exit_fn = cfq_exit_queue,
40554027
},
4028+
.icq_size = sizeof(struct cfq_io_cq),
4029+
.icq_align = __alignof__(struct cfq_io_cq),
40564030
.elevator_attrs = cfq_attrs,
4057-
.elevator_name = "cfq",
4031+
.elevator_name = "cfq",
40584032
.elevator_owner = THIS_MODULE,
40594033
};
40604034

@@ -4072,6 +4046,8 @@ static struct blkio_policy_type blkio_policy_cfq;
40724046

40734047
static int __init cfq_init(void)
40744048
{
4049+
int ret;
4050+
40754051
/*
40764052
* could be 0 on HZ < 1000 setups
40774053
*/
@@ -4086,10 +4062,17 @@ static int __init cfq_init(void)
40864062
#else
40874063
cfq_group_idle = 0;
40884064
#endif
4089-
if (cfq_slab_setup())
4065+
cfq_pool = KMEM_CACHE(cfq_queue, 0);
4066+
if (!cfq_pool)
40904067
return -ENOMEM;
40914068

4092-
elv_register(&iosched_cfq);
4069+
ret = elv_register(&iosched_cfq);
4070+
if (ret) {
4071+
kmem_cache_destroy(cfq_pool);
4072+
return ret;
4073+
}
4074+
cfq_icq_pool = iosched_cfq.icq_cache;
4075+
40934076
blkio_policy_register(&blkio_policy_cfq);
40944077

40954078
return 0;
@@ -4099,8 +4082,7 @@ static void __exit cfq_exit(void)
40994082
{
41004083
blkio_policy_unregister(&blkio_policy_cfq);
41014084
elv_unregister(&iosched_cfq);
4102-
rcu_barrier(); /* make sure all cic RCU frees are complete */
4103-
cfq_slab_kill();
4085+
kmem_cache_destroy(cfq_pool);
41044086
}
41054087

41064088
module_init(cfq_init);

‎block/deadline-iosched.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ static struct elevator_type iosched_deadline = {
448448

449449
static int __init deadline_init(void)
450450
{
451-
elv_register(&iosched_deadline);
452-
453-
return 0;
451+
return elv_register(&iosched_deadline);
454452
}
455453

456454
static void __exit deadline_exit(void)

‎block/elevator.c‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,30 +886,63 @@ void elv_unregister_queue(struct request_queue *q)
886886
}
887887
EXPORT_SYMBOL(elv_unregister_queue);
888888

889-
void elv_register(struct elevator_type *e)
889+
int elv_register(struct elevator_type *e)
890890
{
891891
char *def = "";
892892

893+
/* create icq_cache if requested */
894+
if (e->icq_size) {
895+
if (WARN_ON(e->icq_size < sizeof(struct io_cq)) ||
896+
WARN_ON(e->icq_align < __alignof__(struct io_cq)))
897+
return -EINVAL;
898+
899+
snprintf(e->icq_cache_name, sizeof(e->icq_cache_name),
900+
"%s_io_cq", e->elevator_name);
901+
e->icq_cache = kmem_cache_create(e->icq_cache_name, e->icq_size,
902+
e->icq_align, 0, NULL);
903+
if (!e->icq_cache)
904+
return -ENOMEM;
905+
}
906+
907+
/* register, don't allow duplicate names */
893908
spin_lock(&elv_list_lock);
894-
BUG_ON(elevator_find(e->elevator_name));
909+
if (elevator_find(e->elevator_name)) {
910+
spin_unlock(&elv_list_lock);
911+
if (e->icq_cache)
912+
kmem_cache_destroy(e->icq_cache);
913+
return -EBUSY;
914+
}
895915
list_add_tail(&e->list, &elv_list);
896916
spin_unlock(&elv_list_lock);
897917

918+
/* print pretty message */
898919
if (!strcmp(e->elevator_name, chosen_elevator) ||
899920
(!*chosen_elevator &&
900921
!strcmp(e->elevator_name, CONFIG_DEFAULT_IOSCHED)))
901922
def = " (default)";
902923

903924
printk(KERN_INFO "io scheduler %s registered%s\n", e->elevator_name,
904925
def);
926+
return 0;
905927
}
906928
EXPORT_SYMBOL_GPL(elv_register);
907929

908930
void elv_unregister(struct elevator_type *e)
909931
{
932+
/* unregister */
910933
spin_lock(&elv_list_lock);
911934
list_del_init(&e->list);
912935
spin_unlock(&elv_list_lock);
936+
937+
/*
938+
* Destroy icq_cache if it exists. icq's are RCU managed. Make
939+
* sure all RCU operations are complete before proceeding.
940+
*/
941+
if (e->icq_cache) {
942+
rcu_barrier();
943+
kmem_cache_destroy(e->icq_cache);
944+
e->icq_cache = NULL;
945+
}
913946
}
914947
EXPORT_SYMBOL_GPL(elv_unregister);
915948

‎block/noop-iosched.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ static struct elevator_type elevator_noop = {
9494

9595
static int __init noop_init(void)
9696
{
97-
elv_register(&elevator_noop);
98-
99-
return 0;
97+
return elv_register(&elevator_noop);
10098
}
10199

102100
static void __exit noop_exit(void)

‎include/linux/elevator.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,19 @@ struct elv_fs_entry {
7878
*/
7979
struct elevator_type
8080
{
81+
/* managed by elevator core */
82+
struct kmem_cache *icq_cache;
83+
84+
/* fields provided by elevator implementation */
8185
struct elevator_ops ops;
86+
size_t icq_size;
87+
size_t icq_align;
8288
struct elv_fs_entry *elevator_attrs;
8389
char elevator_name[ELV_NAME_MAX];
8490
struct module *elevator_owner;
91+
92+
/* managed by elevator core */
93+
char icq_cache_name[ELV_NAME_MAX + 5]; /* elvname + "_io_cq" */
8594
struct list_head list;
8695
};
8796

@@ -127,7 +136,7 @@ extern void elv_drain_elevator(struct request_queue *);
127136
/*
128137
* io scheduler registration
129138
*/
130-
extern void elv_register(struct elevator_type *);
139+
extern int elv_register(struct elevator_type *);
131140
extern void elv_unregister(struct elevator_type *);
132141

133142
/*

0 commit comments

Comments
 (0)