Skip to content

Commit 3c899fa

Browse files
YuKuai-huaweikawasaki
authored andcommitted
block, bfq: switch to use elevator lock
Replace the internal spinlock bfqd->lock with the new spinlock in elevator_queue. There are no functional changes. Signed-off-by: Yu Kuai <[email protected]>
1 parent d333f57 commit 3c899fa

4 files changed

Lines changed: 28 additions & 31 deletions

File tree

block/bfq-cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ static void bfq_pd_offline(struct blkg_policy_data *pd)
878878
unsigned long flags;
879879
int i;
880880

881-
spin_lock_irqsave(&bfqd->lock, flags);
881+
spin_lock_irqsave(bfqd->lock, flags);
882882

883883
if (!entity) /* root group */
884884
goto put_async_queues;
@@ -923,7 +923,7 @@ static void bfq_pd_offline(struct blkg_policy_data *pd)
923923
put_async_queues:
924924
bfq_put_async_queues(bfqd, bfqg);
925925

926-
spin_unlock_irqrestore(&bfqd->lock, flags);
926+
spin_unlock_irqrestore(bfqd->lock, flags);
927927
/*
928928
* @blkg is going offline and will be ignored by
929929
* blkg_[rw]stat_recursive_sum(). Transfer stats to the parent so

block/bfq-iosched.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ static struct bfq_io_cq *bfq_bic_lookup(struct request_queue *q)
466466
*/
467467
void bfq_schedule_dispatch(struct bfq_data *bfqd)
468468
{
469-
lockdep_assert_held(&bfqd->lock);
469+
lockdep_assert_held(bfqd->lock);
470470

471471
if (bfqd->queued != 0) {
472472
bfq_log(bfqd, "schedule dispatch");
@@ -591,7 +591,7 @@ static bool bfqq_request_over_limit(struct bfq_data *bfqd,
591591
int level;
592592

593593
retry:
594-
spin_lock_irq(&bfqd->lock);
594+
spin_lock_irq(bfqd->lock);
595595
bfqq = bic_to_bfqq(bic, op_is_sync(opf), act_idx);
596596
if (!bfqq)
597597
goto out;
@@ -603,7 +603,7 @@ static bool bfqq_request_over_limit(struct bfq_data *bfqd,
603603
/* +1 for bfqq entity, root cgroup not included */
604604
depth = bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css.cgroup->level + 1;
605605
if (depth > alloc_depth) {
606-
spin_unlock_irq(&bfqd->lock);
606+
spin_unlock_irq(bfqd->lock);
607607
if (entities != inline_entities)
608608
kfree(entities);
609609
entities = kmalloc_array(depth, sizeof(*entities), GFP_NOIO);
@@ -661,7 +661,7 @@ static bool bfqq_request_over_limit(struct bfq_data *bfqd,
661661
}
662662
}
663663
out:
664-
spin_unlock_irq(&bfqd->lock);
664+
spin_unlock_irq(bfqd->lock);
665665
if (entities != inline_entities)
666666
kfree(entities);
667667
return ret;
@@ -2454,7 +2454,7 @@ static bool bfq_bio_merge(struct request_queue *q, struct bio *bio,
24542454
struct request *free = NULL;
24552455
bool ret;
24562456

2457-
spin_lock_irq(&bfqd->lock);
2457+
spin_lock_irq(bfqd->lock);
24582458

24592459
if (bic) {
24602460
/*
@@ -2472,7 +2472,7 @@ static bool bfq_bio_merge(struct request_queue *q, struct bio *bio,
24722472

24732473
ret = blk_mq_sched_try_merge(q, bio, nr_segs, &free);
24742474

2475-
spin_unlock_irq(&bfqd->lock);
2475+
spin_unlock_irq(bfqd->lock);
24762476
if (free)
24772477
blk_mq_free_request(free);
24782478

@@ -2647,7 +2647,7 @@ static void bfq_end_wr(struct bfq_data *bfqd)
26472647
struct bfq_queue *bfqq;
26482648
int i;
26492649

2650-
spin_lock_irq(&bfqd->lock);
2650+
spin_lock_irq(bfqd->lock);
26512651

26522652
for (i = 0; i < bfqd->num_actuators; i++) {
26532653
list_for_each_entry(bfqq, &bfqd->active_list[i], bfqq_list)
@@ -2657,7 +2657,7 @@ static void bfq_end_wr(struct bfq_data *bfqd)
26572657
bfq_bfqq_end_wr(bfqq);
26582658
bfq_end_wr_async(bfqd);
26592659

2660-
spin_unlock_irq(&bfqd->lock);
2660+
spin_unlock_irq(bfqd->lock);
26612661
}
26622662

26632663
static sector_t bfq_io_struct_pos(void *io_struct, bool request)
@@ -5303,8 +5303,6 @@ static struct request *bfq_dispatch_request(struct blk_mq_hw_ctx *hctx)
53035303
struct bfq_queue *in_serv_queue;
53045304
bool waiting_rq, idle_timer_disabled = false;
53055305

5306-
spin_lock_irq(&bfqd->lock);
5307-
53085306
in_serv_queue = bfqd->in_service_queue;
53095307
waiting_rq = in_serv_queue && bfq_bfqq_wait_request(in_serv_queue);
53105308

@@ -5314,7 +5312,6 @@ static struct request *bfq_dispatch_request(struct blk_mq_hw_ctx *hctx)
53145312
waiting_rq && !bfq_bfqq_wait_request(in_serv_queue);
53155313
}
53165314

5317-
spin_unlock_irq(&bfqd->lock);
53185315
bfq_update_dispatch_stats(hctx->queue, rq,
53195316
idle_timer_disabled ? in_serv_queue : NULL,
53205317
idle_timer_disabled);
@@ -5492,9 +5489,9 @@ static void bfq_exit_icq(struct io_cq *icq)
54925489
* this is the last time these queues are accessed.
54935490
*/
54945491
if (bfqd) {
5495-
spin_lock_irqsave(&bfqd->lock, flags);
5492+
spin_lock_irqsave(bfqd->lock, flags);
54965493
_bfq_exit_icq(bic, bfqd->num_actuators);
5497-
spin_unlock_irqrestore(&bfqd->lock, flags);
5494+
spin_unlock_irqrestore(bfqd->lock, flags);
54985495
} else {
54995496
_bfq_exit_icq(bic, BFQ_MAX_ACTUATORS);
55005497
}
@@ -6250,10 +6247,10 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
62506247
if (!cgroup_subsys_on_dfl(io_cgrp_subsys) && rq->bio)
62516248
bfqg_stats_update_legacy_io(q, rq);
62526249
#endif
6253-
spin_lock_irq(&bfqd->lock);
6250+
spin_lock_irq(bfqd->lock);
62546251
bfqq = bfq_init_rq(rq);
62556252
if (blk_mq_sched_try_insert_merge(q, rq, &free)) {
6256-
spin_unlock_irq(&bfqd->lock);
6253+
spin_unlock_irq(bfqd->lock);
62576254
blk_mq_free_requests(&free);
62586255
return;
62596256
}
@@ -6286,7 +6283,7 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
62866283
* merge).
62876284
*/
62886285
cmd_flags = rq->cmd_flags;
6289-
spin_unlock_irq(&bfqd->lock);
6286+
spin_unlock_irq(bfqd->lock);
62906287

62916288
bfq_update_insert_stats(q, bfqq, idle_timer_disabled,
62926289
cmd_flags);
@@ -6667,7 +6664,7 @@ static void bfq_finish_requeue_request(struct request *rq)
66676664
rq->io_start_time_ns,
66686665
rq->cmd_flags);
66696666

6670-
spin_lock_irqsave(&bfqd->lock, flags);
6667+
spin_lock_irqsave(bfqd->lock, flags);
66716668
if (likely(rq->rq_flags & RQF_STARTED)) {
66726669
if (rq == bfqd->waited_rq)
66736670
bfq_update_inject_limit(bfqd, bfqq);
@@ -6677,7 +6674,7 @@ static void bfq_finish_requeue_request(struct request *rq)
66776674
bfqq_request_freed(bfqq);
66786675
bfq_put_queue(bfqq);
66796676
RQ_BIC(rq)->requests--;
6680-
spin_unlock_irqrestore(&bfqd->lock, flags);
6677+
spin_unlock_irqrestore(bfqd->lock, flags);
66816678

66826679
/*
66836680
* Reset private fields. In case of a requeue, this allows
@@ -7008,7 +7005,7 @@ bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq)
70087005
enum bfqq_expiration reason;
70097006
unsigned long flags;
70107007

7011-
spin_lock_irqsave(&bfqd->lock, flags);
7008+
spin_lock_irqsave(bfqd->lock, flags);
70127009

70137010
/*
70147011
* Considering that bfqq may be in race, we should firstly check
@@ -7018,7 +7015,7 @@ bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq)
70187015
* been cleared in __bfq_bfqd_reset_in_service func.
70197016
*/
70207017
if (bfqq != bfqd->in_service_queue) {
7021-
spin_unlock_irqrestore(&bfqd->lock, flags);
7018+
spin_unlock_irqrestore(bfqd->lock, flags);
70227019
return;
70237020
}
70247021

@@ -7046,7 +7043,7 @@ bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq)
70467043

70477044
schedule_dispatch:
70487045
bfq_schedule_dispatch(bfqd);
7049-
spin_unlock_irqrestore(&bfqd->lock, flags);
7046+
spin_unlock_irqrestore(bfqd->lock, flags);
70507047
}
70517048

70527049
/*
@@ -7172,10 +7169,10 @@ static void bfq_exit_queue(struct elevator_queue *e)
71727169

71737170
hrtimer_cancel(&bfqd->idle_slice_timer);
71747171

7175-
spin_lock_irq(&bfqd->lock);
7172+
spin_lock_irq(bfqd->lock);
71767173
list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list)
71777174
bfq_deactivate_bfqq(bfqd, bfqq, false, false);
7178-
spin_unlock_irq(&bfqd->lock);
7175+
spin_unlock_irq(bfqd->lock);
71797176

71807177
for (actuator = 0; actuator < bfqd->num_actuators; actuator++)
71817178
WARN_ON_ONCE(bfqd->rq_in_driver[actuator]);
@@ -7189,10 +7186,10 @@ static void bfq_exit_queue(struct elevator_queue *e)
71897186
#ifdef CONFIG_BFQ_GROUP_IOSCHED
71907187
blkcg_deactivate_policy(bfqd->queue->disk, &blkcg_policy_bfq);
71917188
#else
7192-
spin_lock_irq(&bfqd->lock);
7189+
spin_lock_irq(bfqd->lock);
71937190
bfq_put_async_queues(bfqd, bfqd->root_group);
71947191
kfree(bfqd->root_group);
7195-
spin_unlock_irq(&bfqd->lock);
7192+
spin_unlock_irq(bfqd->lock);
71967193
#endif
71977194

71987195
blk_stat_disable_accounting(bfqd->queue);
@@ -7351,7 +7348,7 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_queue *eq)
73517348
/* see comments on the definition of next field inside bfq_data */
73527349
bfqd->actuator_load_threshold = 4;
73537350

7354-
spin_lock_init(&bfqd->lock);
7351+
bfqd->lock = &eq->lock;
73557352

73567353
/*
73577354
* The invocation of the next bfq_create_group_hierarchy

block/bfq-iosched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ struct bfq_data {
795795
/* fallback dummy bfqq for extreme OOM conditions */
796796
struct bfq_queue oom_bfqq;
797797

798-
spinlock_t lock;
798+
spinlock_t *lock;
799799

800800
/*
801801
* bic associated with the task issuing current bio for

block/blk-mq-sched.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ static int __blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
115115
break;
116116

117117
if (sq_sched)
118-
spin_lock(&e->lock);
118+
spin_lock_irq(&e->lock);
119119
rq = e->type->ops.dispatch_request(hctx);
120120
if (sq_sched)
121-
spin_unlock(&e->lock);
121+
spin_unlock_irq(&e->lock);
122122

123123
if (!rq) {
124124
blk_mq_put_dispatch_budget(q, budget_token);

0 commit comments

Comments
 (0)