block: restructure elevator switch path and fix a lockdep splat
v2 cover block: restructure elevator switch path and fix a lockdep splat
Hi,
This patchset reorganizes the elevator switch path used during both nr_hw_queues update and elv_iosched_store() operations to address a recently reported lockdep splat [1].
The warning highlights a locking dependency between ->freeze_lock and ->elevator_lock on pcpu_alloc_mutex, triggered when the Kyber scheduler dynamically allocates its private scheduling data. The fix is to ensure that such allocations occur outside the locked sections, thus eliminating the dependency chain.
While working on this, it also became evident that the nr_hw_queue update code maintains two disjoint xarrays—one for elevator tags and another for elevator type—both serving the same purpose. Unifying these into a single elv_change_ctx structure improves clarity and maintainability.
This series therefore implements four patches:
The first perparatory patch unifies elevator tags and type xarrays. It combines both xarrays into a single struct elv_change_ctx, simplifying per-queue elevator state management.
The second patch is aimed to group together all elevator-related resources that share the same lifetime and as a first step we move the elevator tags pointer from struct elv_change_ctx into the newly inroduced struct elevator_resources. The subsequent patch extends the struct elevator_resources to include other elevator-related data.
The third patch introduce ->alloc_sched_data and ->free_sched_data elevator ops to safely allocate and free scheduler data before acquiring ->freeze_lock and ->elevator_lock, preventing the dependency on pcpu_ alloc_mutex. In this patch we add elevator-data into the struct elevator_resources, which is introduced in the previous patch.
The fourth patch converts Kyber scheduler to use the new methods inroduced in the previous patch. It hooks Kyber’s scheduler data allocation and teardown logic from ->init_sched and ->exit_sched into the new methods, ensuring memory operations are performed outside locked sections.
Together, these changes simplify the elevator switch logic and prevent the reported lockdep splat.
As always, feedback and suggestions are very welcome!
[1] https://lore.kernel.org/all/CAGVVp+VNW4M-5DZMNoADp6o2VKFhi7KxWpTDkcnVyjO0=-D5+A@mail.gmail.com/
Thanks,
--Nilay
changes from v1:
- Keep blk_mq_free_sched_ctx_batch() and blk_mq_alloc_sched_ctx_batch() together in the same file (Ming Lei)
- Since the ctx pointer is stored in xarray after it's dynamically allocated, if blk_mq_alloc_sched_ctx_batch() fails to allocate or insert ctx pointer in xarray then unwinding the allocation is not necessary. Instead looping over the xarray to retrieve the inserted ctx pointer and freeing it should be sufficibet. So invoke blk_mq_ free_sched_ctx_batch() from the blk_mq_alloc_sched_ctx_batch() callsite on failure (Ming Lei)
- As both elevator tags and elevator data shares the same lifetime and allocation constraints, abstract both into a new structure (Ming Lei)
Link to v1: https://lore.kernel.org/all/[email protected]/
Nilay Shroff (4):
block: unify elevator tags and type xarrays into struct elv_change_ctx
block: move elevator tags into struct elevator_resources
block: introduce alloc_sched_data and free_sched_data elevator methods
block: define alloc_sched_data and free_sched_data methods for kyber
block/blk-mq-sched.c | 122 ++++++++++++++++++++++++++++++++++++++---- block/blk-mq-sched.h | 26 ++++++++- block/blk-mq.c | 55 +++++++++++-------- block/blk.h | 7 ++- block/elevator.c | 81 +++++++++++++++------------- block/elevator.h | 28 +++++++++- block/kyber-iosched.c | 30 ++++++++--- 7 files changed, 269 insertions(+), 80 deletions(-)
Signature · 1 line
2.51.0
PATCH v2 1/4 block: unify elevator tags and type xarrays into struct elv_change_ctx
Currently, the nr_hw_queues update path manages two disjoint xarrays — one for elevator tags and another for elevator type — both used during elevator switching. Maintaining these two parallel structures for the same purpose adds unnecessary complexity and potential for mismatched state.
This patch unifies both xarrays into a single structure, struct elv_change_ctx, which holds all per-queue elevator change context. A single xarray, named elv_tbl, now maps each queue (q->id) in a tagset to its corresponding elv_change_ctx entry, encapsulating the elevator tags, type and name references.
This unification simplifies the code, improves maintainability, and clarifies ownership of per-queue elevator state.
--- block/blk-mq-sched.c | 54 ++++++++++++++++++++++++++++++++++++++------ block/blk-mq-sched.h | 3 +++ block/blk-mq.c | 50 +++++++++++++++++++++++----------------- block/blk.h | 7 +++--- block/elevator.c | 31 ++++++------------------- block/elevator.h | 15 ++++++++++++ 6 files changed, 104 insertions(+), 56 deletions(-)
block/blk-mq-sched.c +47 -7
@@ -453,6 +453,38 @@ void blk_mq_free_sched_tags_batch(struct xarray *et_table, } } +void blk_mq_free_sched_ctx_batch (struct xarray *elv_tbl) +{ +unsigned long i; +struct elv_change_ctx *ctx; + +xa_for_each (elv_tbl, i, ctx) { +xa_erase (elv_tbl, i); +kfree (ctx); + } +} + +int blk_mq_alloc_sched_ctx_batch (struct xarray *elv_tbl, +struct blk_mq_tag_set *set) +{ +struct request_queue *q; +struct elv_change_ctx *ctx; + +lockdep_assert_held_write (&set->update_nr_hwq_lock); + +list_for_each_entry (q, &set->tag_list, tag_set_list) { + ctx =kzalloc (sizeof (struct elv_change_ctx ),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + +if (xa_insert (elv_tbl, q->id, ctx,GFP_KERNEL )) { +kfree (ctx); +return -ENOMEM ; + } + } +return 0 ; +} +struct elevator_tags *blk_mq_alloc_sched_tags (struct blk_mq_tag_set *set,unsigned int nr_hw_queues,unsigned int nr_requests) {
@@ -498,12 +530,13 @@ struct elevator_tags *blk_mq_alloc_sched_tags(struct blk_mq_tag_set *set,return NULL ; } -int blk_mq_alloc_sched_tags_batch (struct xarray *et_table, +int blk_mq_alloc_sched_tags_batch (struct xarray *elv_tbl,struct blk_mq_tag_set *set,unsigned int nr_hw_queues) { +struct elv_change_ctx *ctx;struct request_queue *q;struct elevator_tags *et; -gfp_t gfp =GFP_NOIO | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY; +int ret = -ENOMEM ;lockdep_assert_held_write (&set->update_nr_hwq_lock);
@@ -520,8 +553,13 @@ int blk_mq_alloc_sched_tags_batch(struct xarray *et_table, blk_mq_default_nr_requests(set));if (!et) goto out_unwind; -if (xa_insert (et_table, q->id, et, gfp)) + + ctx =xa_load (elv_tbl, q->id); +if (WARN_ON_ONCE (!ctx)) { + ret = -ENOENT ; goto out_free_tags; + } + ctx->et = et; } }return 0 ;
@@ -530,12 +568,14 @@ int blk_mq_alloc_sched_tags_batch(struct xarray *et_table, out_unwind:list_for_each_entry_continue_reverse (q, &set->tag_list, tag_set_list) {if (q->elevator) { - et =xa_load (et_table, q->id); -if (et) -blk_mq_free_sched_tags (et, set); + ctx =xa_load (elv_tbl, q->id); +if (ctx && ctx->et) { +blk_mq_free_sched_tags (ctx->et, set); + ctx->et =NULL ; + } } } -return -ENOMEM ; +return ret; }/* caller must have a reference to @e, will grab another one if successful */
block/blk-mq-sched.h +3 -0
@@ -27,6 +27,9 @@ struct elevator_tags *blk_mq_alloc_sched_tags(struct blk_mq_tag_set *set, unsigned int nr_hw_queues, unsigned int nr_requests);int blk_mq_alloc_sched_tags_batch (struct xarray *et_table,struct blk_mq_tag_set *set,unsigned int nr_hw_queues); +int blk_mq_alloc_sched_ctx_batch (struct xarray *elv_tbl, +struct blk_mq_tag_set *set); +void blk_mq_free_sched_ctx_batch (struct xarray *elv_tbl);void blk_mq_free_sched_tags (struct elevator_tags *et,struct blk_mq_tag_set *set); void blk_mq_free_sched_tags_batch(struct xarray *et_table,
block/blk-mq.c +29 -21
109 lines not on this page · raw message
block/blk.h +3 -4
@@ -11,8 +11,7 @@#include <xen/xen.h> #include "blk-crypto-internal.h" -struct elevator_type ; -struct elevator_tags ; +struct elv_change_ctx ;/* * Default upper limit for the software max_sectors limit used for regular I/Os.
@@ -333,8 +332,8 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,bool blk_insert_flush (struct request *rq); -void elv_update_nr_hw_queues (struct request_queue *q,struct elevator_type *e, -struct elevator_tags *t); +void elv_update_nr_hw_queues (struct request_queue *q, +struct elv_change_ctx *ctx);void elevator_set_default (struct request_queue *q);void elevator_set_none (struct request_queue *q);
block/elevator.c +7 -24
@@ -45,19 +45,6 @@#include "blk-wbt.h" #include "blk-cgroup.h" -/* Holding context data for changing elevator */ -struct elv_change_ctx { -const char *name; -bool no_uevent; - -/* for unregistering old elevator */ -struct elevator_queue *old; -/* for registering new elevator */ -struct elevator_queue *new; -/* holds sched tags data */ -struct elevator_tags *et; -}; -static DEFINE_SPINLOCK (elv_list_lock);static LIST_HEAD (elv_list);
@@ -706,32 +693,28 @@ static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)* The I/O scheduler depends on the number of hardware queues, this forces a * reattachment when nr_hw_queues changes. */ -void elv_update_nr_hw_queues (struct request_queue *q,struct elevator_type *e, -struct elevator_tags *t) +void elv_update_nr_hw_queues (struct request_queue *q, +struct elv_change_ctx *ctx) {struct blk_mq_tag_set *set = q->tag_set; -struct elv_change_ctx ctx = {};int ret = -ENODEV ;WARN_ON_ONCE (q->mq_freeze_depth ==0 ); -if (e && !blk_queue_dying (q) &&blk_queue_registered (q)) { - ctx.name = e->elevator_name; - ctx.et = t; - +if (ctx->type && !blk_queue_dying (q) &&blk_queue_registered (q)) {mutex_lock (&q->elevator_lock);/* force to reattach elevator after nr_hw_queue is updated */ - ret =elevator_switch (q, &ctx); + ret =elevator_switch (q, ctx);mutex_unlock (&q->elevator_lock); }blk_mq_unfreeze_queue_nomemrestore (q);if (!ret) -WARN_ON_ONCE (elevator_change_done (q, &ctx)); +WARN_ON_ONCE (elevator_change_done (q, ctx));/* * Free sched tags if it's allocated but we couldn't switch elevator. */ -if (t && !ctx.new) -blk_mq_free_sched_tags (t, set); +if (ctx->et && !ctx->new) +blk_mq_free_sched_tags (ctx->et, set); }/*
block/elevator.h +15 -0
@@ -32,6 +32,21 @@ struct elevator_tags {struct blk_mq_tags *tags[]; }; +/* Holding context data for changing elevator */ +struct elv_change_ctx { +const char *name; +bool no_uevent; + +/* for unregistering old elevator */ +struct elevator_queue *old; +/* for registering new elevator */ +struct elevator_queue *new; +/* store elevator type */ +struct elevator_type *type; +/* holds sched tags data */ +struct elevator_tags *et; +}; +struct elevator_mq_ops {int (*init_sched)(struct request_queue *,struct elevator_queue *);void (*exit_sched)(struct elevator_queue *);
Signature · 1 line
2.51.0
PATCH v2 2/4 block: move elevator tags into struct elevator_resources
In reply to Nilay ShroffThis patch introduces a new structure, struct elevator_resources, to group together all elevator-related resources that share the same lifetime. As a first step, this change moves the elevator tag pointer from struct elv_change_ctx into the new struct elevator_resources.
This refactoring improves encapsulation and prepares the code for future extensions, where additional elevator-specific data or resources can be added to struct elevator_resources without cluttering struct elv_change_ ctx.
Subsequent patches will extend struct elevator_resources to include other elevator-related data.
--- block/blk-mq-sched.c | 8 ++++---- block/elevator.c | 14 +++++++------- block/elevator.h | 9 +++++++-- 3 files changed, 18 insertions(+), 13 deletions(-)
block/blk-mq-sched.c +4 -4
@@ -559,7 +559,7 @@ int blk_mq_alloc_sched_tags_batch(struct xarray *elv_tbl, ret = -ENOENT ; goto out_free_tags; } - ctx->et = et; + ctx->res.et = et; } }return 0 ;
@@ -569,9 +569,9 @@ int blk_mq_alloc_sched_tags_batch(struct xarray *elv_tbl,list_for_each_entry_continue_reverse (q, &set->tag_list, tag_set_list) {if (q->elevator) { ctx =xa_load (elv_tbl, q->id); -if (ctx && ctx->et) { -blk_mq_free_sched_tags (ctx->et, set); - ctx->et =NULL ; +if (ctx && ctx->res.et) { +blk_mq_free_sched_tags (ctx->res.et, set); + ctx->res.et =NULL ; } } }
block/elevator.c +7 -7
@@ -580,7 +580,7 @@ static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx) }if (new_e) { - ret =blk_mq_init_sched (q, new_e, ctx->et); + ret =blk_mq_init_sched (q, new_e, ctx->res.et);if (ret) goto out_unfreeze; ctx->new = q->elevator;
@@ -656,9 +656,9 @@ static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)lockdep_assert_held (&set->update_nr_hwq_lock);if (strncmp (ctx->name,"none" ,4 )) { - ctx->et =blk_mq_alloc_sched_tags (set, set->nr_hw_queues, + ctx->res.et =blk_mq_alloc_sched_tags (set, set->nr_hw_queues,blk_mq_default_nr_requests (set)); -if (!ctx->et) +if (!ctx->res.et)return -ENOMEM ; }
@@ -683,8 +683,8 @@ static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)/* * Free sched tags if it's allocated but we couldn't switch elevator. */ -if (ctx->et && !ctx->new) -blk_mq_free_sched_tags (ctx->et, set); +if (ctx->res.et && !ctx->new) +blk_mq_free_sched_tags (ctx->res.et, set);return ret; }
@@ -713,8 +713,8 @@ void elv_update_nr_hw_queues(struct request_queue *q,/* * Free sched tags if it's allocated but we couldn't switch elevator. */ -if (ctx->et && !ctx->new) -blk_mq_free_sched_tags (ctx->et, set); +if (ctx->res.et && !ctx->new) +blk_mq_free_sched_tags (ctx->res.et, set); }/*
block/elevator.h +7 -2
@@ -32,6 +32,11 @@ struct elevator_tags {struct blk_mq_tags *tags[]; }; +struct elevator_resources { +/* holds elevator tags */ +struct elevator_tags *et; +}; +/* Holding context data for changing elevator */ struct elv_change_ctx {const char *name;
@@ -43,8 +48,8 @@ struct elv_change_ctx {struct elevator_queue *new;/* store elevator type */ struct elevator_type *type; -/* holds sched tags data */ -struct elevator_tags *et; +/* store elevator resources */ +struct elevator_resources res; };struct elevator_mq_ops {
Signature · 1 line
2.51.0
PATCH v2 3/4 block: introduce alloc_sched_data and free_sched_data elevator methods
In reply to Nilay ShroffThe recent lockdep splat [1] highlights a potential deadlock risk involving ->elevator_lock and ->freeze_lock dependencies on -pcpu_alloc_ mutex. The trace shows that the issue occurs when the Kyber scheduler allocates dynamic memory for its elevator data during initialization.
To address this, introduce two new elevator operation callbacks:
->alloc_sched_data and ->free_sched_data.
When an elevator implements these methods, they are invoked during scheduler switch before acquiring ->freeze_lock and ->elevator_lock. This allows safe allocation and deallocation of per-elevator data without holding locks that could depend on pcpu_alloc_mutex, effectively breaking the lock dependency chain and avoiding the reported deadlock scenario.
[1] https://lore.kernel.org/all/CAGVVp+VNW4M-5DZMNoADp6o2VKFhi7KxWpTDkcnVyjO0=-D5+A@mail.gmail.com/
--- block/blk-mq-sched.c | 68 ++++++++++++++++++++++++++++++++++++++++++-- block/blk-mq-sched.h | 23 ++++++++++++++- block/blk-mq.c | 7 ++++- block/elevator.c | 46 +++++++++++++++++++++++------- block/elevator.h | 8 +++++- 5 files changed, 137 insertions(+), 15 deletions(-)
block/blk-mq-sched.c +66 -2
@@ -464,6 +464,70 @@ void blk_mq_free_sched_ctx_batch(struct xarray *elv_tbl) } } +void blk_mq_free_sched_data_batch (struct xarray *elv_tbl, +struct blk_mq_tag_set *set) +{ +struct request_queue *q; +struct elv_change_ctx *ctx; + +lockdep_assert_held_write (&set->update_nr_hwq_lock); + +list_for_each_entry (q, &set->tag_list, tag_set_list) { +if (q->elevator) { + ctx =xa_load (elv_tbl, q->id); +if (WARN_ON_ONCE (!ctx)) +continue ; +if (ctx->res.data) +blk_mq_free_sched_data (q->elevator->type, + ctx->res.data); + } + } +} + +int blk_mq_alloc_sched_data_batch (struct xarray *elv_tbl, +struct blk_mq_tag_set *set) +{ +struct request_queue *q; +struct elv_change_ctx *ctx; +int ret =0 ; + +lockdep_assert_held_write (&set->update_nr_hwq_lock); + +list_for_each_entry (q, &set->tag_list, tag_set_list) { +/* +* Accessing q->elevator without holding q->elevator_lock is +* safe because we're holding here set->update_nr_hwq_lock in +* the writer context. So, scheduler update/switch code (which +* acquires the same lock but in the reader context) can't run +* concurrently. +*/ +if (q->elevator) { + ctx =xa_load (elv_tbl, q->id); +if (WARN_ON_ONCE (!ctx)) +return -ENOENT ; + + ret =blk_mq_alloc_sched_data (q, q->elevator->type, + &ctx->res.data); +if (ret) + goto out_unwind; + } + } +return ret; + +out_unwind: +list_for_each_entry_continue_reverse (q, &set->tag_list, tag_set_list) { +if (q->elevator) { + ctx =xa_load (elv_tbl, q->id); +if (WARN_ON_ONCE (!ctx)) +continue ; +if (ctx->res.data) +blk_mq_free_sched_data (q->elevator->type, + ctx->res.data); + } + } +return ret; +} +int blk_mq_alloc_sched_ctx_batch (struct xarray *elv_tbl,struct blk_mq_tag_set *set) {
@@ -580,7 +644,7 @@ int blk_mq_alloc_sched_tags_batch(struct xarray *elv_tbl,/* caller must have a reference to @e, will grab another one if successful */ int blk_mq_init_sched (struct request_queue *q,struct elevator_type *e, -struct elevator_tags *et) +struct elevator_tags *et,void *data) {unsigned int flags = q->tag_set->flags;struct blk_mq_hw_ctx *hctx;
@@ -588,7 +652,7 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e,unsigned long i;int ret; - eq =elevator_alloc (q, e, et); + eq =elevator_alloc (q, e, et, data);if (!eq)return -ENOMEM ;
block/blk-mq-sched.h +22 -1
@@ -19,7 +19,7 @@ void __blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx);void blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx);int blk_mq_init_sched (struct request_queue *q,struct elevator_type *e, -struct elevator_tags *et); +struct elevator_tags *et,void *data);void blk_mq_exit_sched (struct request_queue *q,struct elevator_queue *e);void blk_mq_sched_free_rqs (struct request_queue *q);
@@ -29,11 +29,32 @@ int blk_mq_alloc_sched_tags_batch(struct xarray *et_table, struct blk_mq_tag_set *set, unsigned int nr_hw_queues);int blk_mq_alloc_sched_ctx_batch (struct xarray *elv_tbl,struct blk_mq_tag_set *set); +int blk_mq_alloc_sched_data_batch (struct xarray *elv_tbl, +struct blk_mq_tag_set *set);void blk_mq_free_sched_ctx_batch (struct xarray *elv_tbl);void blk_mq_free_sched_tags (struct elevator_tags *et,struct blk_mq_tag_set *set);void blk_mq_free_sched_tags_batch (struct xarray *et_table,struct blk_mq_tag_set *set); +void blk_mq_free_sched_data_batch (struct xarray *elv_tbl, +struct blk_mq_tag_set *set); + +static inline int blk_mq_alloc_sched_data (struct request_queue *q, +struct elevator_type *e,void **data) +{ +if (e && e->ops.alloc_sched_data) { + *data = e->ops.alloc_sched_data (q); +if (!*data) +return -ENOMEM ; + } +return 0 ; +} + +static inline void blk_mq_free_sched_data (struct elevator_type *e,void *data) +{ +if (e && e->ops.free_sched_data) + e->ops.free_sched_data (data); +}static inline void blk_mq_sched_restart (struct blk_mq_hw_ctx *hctx) {
block/blk-mq.c +6 -1
@@ -5066,9 +5066,14 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,if (blk_mq_alloc_sched_ctx_batch (&elv_tbl, set) <0 ) goto out_free_ctx; -if (blk_mq_alloc_sched_tags_batch (&elv_tbl, set, nr_hw_queues) <0 ) +if (blk_mq_alloc_sched_data_batch (&elv_tbl, set) <0 ) goto out_free_ctx; +if (blk_mq_alloc_sched_tags_batch (&elv_tbl, set, nr_hw_queues) <0 ) { +blk_mq_free_sched_data_batch (&elv_tbl, set); + goto out_free_ctx; + } +list_for_each_entry (q, &set->tag_list, tag_set_list) {blk_mq_debugfs_unregister_hctxs (q);blk_mq_sysfs_unregister_hctxs (q);
block/elevator.c +36 -10
129 lines not on this page · raw message
block/elevator.h +7 -1
@@ -33,6 +33,8 @@ struct elevator_tags { };struct elevator_resources { +/* holds elevator data */ +void *data;/* holds elevator tags */ struct elevator_tags *et; };
@@ -58,6 +60,8 @@ struct elevator_mq_ops {int (*init_hctx)(struct blk_mq_hw_ctx *,unsigned int );void (*exit_hctx)(struct blk_mq_hw_ctx *,unsigned int );void (*depth_updated)(struct request_queue *); +void *(*alloc_sched_data)(struct request_queue *); +void (*free_sched_data)(void *);bool (*allow_merge)(struct request_queue *,struct request *,struct bio *);bool (*bio_merge)(struct request_queue *,struct bio *,unsigned int );
@@ -183,7 +187,9 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *page, size_t count);extern bool elv_bio_merge_ok (struct request *,struct bio *);struct elevator_queue *elevator_alloc (struct request_queue *, -struct elevator_type *,struct elevator_tags *); +struct elevator_type *, +struct elevator_tags *, +void *);/* * Helper functions.
Signature · 1 line
2.51.0
PATCH v2 4/4 block: define alloc_sched_data and free_sched_data methods for kyber
In reply to Nilay ShroffCurrently, the Kyber elevator allocates its private data dynamically in ->init_sched and frees it in ->exit_sched. However, since ->init_sched is invoked during elevator switch after acquiring both ->freeze_lock and ->elevator_lock, it may trigger the lockdep splat [1] due to dependency on pcpu_alloc_mutex.
To resolve this, move the elevator data allocation and deallocation logic from ->init_sched and ->exit_sched into the newly introduced ->alloc_sched_data and ->free_sched_data methods. These callbacks are invoked before acquiring ->freeze_lock and ->elevator_lock, ensuring that memory allocation happens safely without introducing additional locking dependencies.
This change breaks the dependency chain involving pcpu_alloc_mutex and prevents the reported lockdep warning.
[1] https://lore.kernel.org/all/CAGVVp+VNW4M-5DZMNoADp6o2VKFhi7KxWpTDkcnVyjO0=-D5+A@mail.gmail.com/
--- block/kyber-iosched.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
block/kyber-iosched.c +22 -8
@@ -409,30 +409,42 @@ static void kyber_depth_updated(struct request_queue *q)static int kyber_init_sched (struct request_queue *q,struct elevator_queue *eq) { -struct kyber_queue_data *kqd; - - kqd =kyber_queue_data_alloc (q); -if (IS_ERR (kqd)) -return PTR_ERR (kqd); -blk_stat_enable_accounting (q);blk_queue_flag_clear (QUEUE_FLAG_SQ_SCHED , q); - eq->elevator_data = kqd; q->elevator = eq;kyber_depth_updated (q);return 0 ; } +static void *kyber_alloc_sched_data (struct request_queue *q) +{ +struct kyber_queue_data *kqd; + + kqd =kyber_queue_data_alloc (q); +if (IS_ERR (kqd)) +return NULL ; + +return kqd; +} +static void kyber_exit_sched (struct elevator_queue *e) {struct kyber_queue_data *kqd = e->elevator_data; -int i;timer_shutdown_sync (&kqd->timer);blk_stat_disable_accounting (kqd->q); +} + +static void kyber_free_sched_data (void *elv_data) +{ +struct kyber_queue_data *kqd = elv_data; +int i; + +if (!kqd) +return ;for (i =0 ; i <KYBER_NUM_DOMAINS ; i++)sbitmap_queue_free (&kqd->domain_tokens[i]);
@@ -1004,6 +1016,8 @@ static struct elevator_type kyber_sched = { .exit_sched = kyber_exit_sched, .init_hctx = kyber_init_hctx, .exit_hctx = kyber_exit_hctx, + .alloc_sched_data = kyber_alloc_sched_data, + .free_sched_data = kyber_free_sched_data, .limit_depth = kyber_limit_depth, .bio_merge = kyber_bio_merge, .prepare_request = kyber_prepare_request,
Signature · 1 line
2.51.0