Skip to content

Commit 0d945c1

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: remove the queue_lock indirection
With the legacy request path gone there is no good reason to keep queue_lock as a pointer, we can always use the embedded lock now. Reviewed-by: Hannes Reinecke <hare@suse.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Fixed floppy and blk-cgroup missing conversions and half done edits. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6d46964 commit 0d945c1

16 files changed

Lines changed: 92 additions & 106 deletions

‎block/bfq-cgroup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static void bfqg_stats_xfer_dead(struct bfq_group *bfqg)
334334

335335
parent = bfqg_parent(bfqg);
336336

337-
lockdep_assert_held(bfqg_to_blkg(bfqg)->q->queue_lock);
337+
lockdep_assert_held(&bfqg_to_blkg(bfqg)->q->queue_lock);
338338

339339
if (unlikely(!parent))
340340
return;

‎block/bfq-iosched.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ static struct bfq_io_cq *bfq_bic_lookup(struct bfq_data *bfqd,
399399
unsigned long flags;
400400
struct bfq_io_cq *icq;
401401

402-
spin_lock_irqsave(q->queue_lock, flags);
402+
spin_lock_irqsave(&q->queue_lock, flags);
403403
icq = icq_to_bic(ioc_lookup_icq(ioc, q));
404-
spin_unlock_irqrestore(q->queue_lock, flags);
404+
spin_unlock_irqrestore(&q->queue_lock, flags);
405405

406406
return icq;
407407
}
@@ -4034,7 +4034,7 @@ static void bfq_update_dispatch_stats(struct request_queue *q,
40344034
* In addition, the following queue lock guarantees that
40354035
* bfqq_group(bfqq) exists as well.
40364036
*/
4037-
spin_lock_irq(q->queue_lock);
4037+
spin_lock_irq(&q->queue_lock);
40384038
if (idle_timer_disabled)
40394039
/*
40404040
* Since the idle timer has been disabled,
@@ -4053,7 +4053,7 @@ static void bfq_update_dispatch_stats(struct request_queue *q,
40534053
bfqg_stats_set_start_empty_time(bfqg);
40544054
bfqg_stats_update_io_remove(bfqg, rq->cmd_flags);
40554055
}
4056-
spin_unlock_irq(q->queue_lock);
4056+
spin_unlock_irq(&q->queue_lock);
40574057
}
40584058
#else
40594059
static inline void bfq_update_dispatch_stats(struct request_queue *q,
@@ -4637,11 +4637,11 @@ static void bfq_update_insert_stats(struct request_queue *q,
46374637
* In addition, the following queue lock guarantees that
46384638
* bfqq_group(bfqq) exists as well.
46394639
*/
4640-
spin_lock_irq(q->queue_lock);
4640+
spin_lock_irq(&q->queue_lock);
46414641
bfqg_stats_update_io_add(bfqq_group(bfqq), bfqq, cmd_flags);
46424642
if (idle_timer_disabled)
46434643
bfqg_stats_update_idle_time(bfqq_group(bfqq));
4644-
spin_unlock_irq(q->queue_lock);
4644+
spin_unlock_irq(&q->queue_lock);
46454645
}
46464646
#else
46474647
static inline void bfq_update_insert_stats(struct request_queue *q,
@@ -5382,9 +5382,9 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_type *e)
53825382
}
53835383
eq->elevator_data = bfqd;
53845384

5385-
spin_lock_irq(q->queue_lock);
5385+
spin_lock_irq(&q->queue_lock);
53865386
q->elevator = eq;
5387-
spin_unlock_irq(q->queue_lock);
5387+
spin_unlock_irq(&q->queue_lock);
53885388

53895389
/*
53905390
* Our fallback bfqq if bfq_find_alloc_queue() runs into OOM issues.

‎block/blk-cgroup.c‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct blkcg_gq *blkg_lookup_slowpath(struct blkcg *blkcg,
147147
blkg = radix_tree_lookup(&blkcg->blkg_tree, q->id);
148148
if (blkg && blkg->q == q) {
149149
if (update_hint) {
150-
lockdep_assert_held(q->queue_lock);
150+
lockdep_assert_held(&q->queue_lock);
151151
rcu_assign_pointer(blkcg->blkg_hint, blkg);
152152
}
153153
return blkg;
@@ -170,7 +170,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
170170
int i, ret;
171171

172172
WARN_ON_ONCE(!rcu_read_lock_held());
173-
lockdep_assert_held(q->queue_lock);
173+
lockdep_assert_held(&q->queue_lock);
174174

175175
/* blkg holds a reference to blkcg */
176176
if (!css_tryget_online(&blkcg->css)) {
@@ -268,7 +268,7 @@ struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
268268
struct blkcg_gq *blkg;
269269

270270
WARN_ON_ONCE(!rcu_read_lock_held());
271-
lockdep_assert_held(q->queue_lock);
271+
lockdep_assert_held(&q->queue_lock);
272272

273273
blkg = __blkg_lookup(blkcg, q, true);
274274
if (blkg)
@@ -299,7 +299,7 @@ static void blkg_destroy(struct blkcg_gq *blkg)
299299
struct blkcg_gq *parent = blkg->parent;
300300
int i;
301301

302-
lockdep_assert_held(blkg->q->queue_lock);
302+
lockdep_assert_held(&blkg->q->queue_lock);
303303
lockdep_assert_held(&blkcg->lock);
304304

305305
/* Something wrong if we are trying to remove same group twice */
@@ -349,7 +349,7 @@ static void blkg_destroy_all(struct request_queue *q)
349349
{
350350
struct blkcg_gq *blkg, *n;
351351

352-
spin_lock_irq(q->queue_lock);
352+
spin_lock_irq(&q->queue_lock);
353353
list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
354354
struct blkcg *blkcg = blkg->blkcg;
355355

@@ -359,7 +359,7 @@ static void blkg_destroy_all(struct request_queue *q)
359359
}
360360

361361
q->root_blkg = NULL;
362-
spin_unlock_irq(q->queue_lock);
362+
spin_unlock_irq(&q->queue_lock);
363363
}
364364

365365
/*
@@ -454,10 +454,10 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
454454

455455
rcu_read_lock();
456456
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
457-
spin_lock_irq(blkg->q->queue_lock);
457+
spin_lock_irq(&blkg->q->queue_lock);
458458
if (blkcg_policy_enabled(blkg->q, pol))
459459
total += prfill(sf, blkg->pd[pol->plid], data);
460-
spin_unlock_irq(blkg->q->queue_lock);
460+
spin_unlock_irq(&blkg->q->queue_lock);
461461
}
462462
rcu_read_unlock();
463463

@@ -655,7 +655,7 @@ u64 blkg_stat_recursive_sum(struct blkcg_gq *blkg,
655655
struct cgroup_subsys_state *pos_css;
656656
u64 sum = 0;
657657

658-
lockdep_assert_held(blkg->q->queue_lock);
658+
lockdep_assert_held(&blkg->q->queue_lock);
659659

660660
rcu_read_lock();
661661
blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) {
@@ -698,7 +698,7 @@ struct blkg_rwstat blkg_rwstat_recursive_sum(struct blkcg_gq *blkg,
698698
struct blkg_rwstat sum = { };
699699
int i;
700700

701-
lockdep_assert_held(blkg->q->queue_lock);
701+
lockdep_assert_held(&blkg->q->queue_lock);
702702

703703
rcu_read_lock();
704704
blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) {
@@ -729,7 +729,7 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg,
729729
struct request_queue *q)
730730
{
731731
WARN_ON_ONCE(!rcu_read_lock_held());
732-
lockdep_assert_held(q->queue_lock);
732+
lockdep_assert_held(&q->queue_lock);
733733

734734
if (!blkcg_policy_enabled(q, pol))
735735
return ERR_PTR(-EOPNOTSUPP);
@@ -750,7 +750,7 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg,
750750
*/
751751
int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
752752
char *input, struct blkg_conf_ctx *ctx)
753-
__acquires(rcu) __acquires(disk->queue->queue_lock)
753+
__acquires(rcu) __acquires(&disk->queue->queue_lock)
754754
{
755755
struct gendisk *disk;
756756
struct request_queue *q;
@@ -778,7 +778,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
778778
q = disk->queue;
779779

780780
rcu_read_lock();
781-
spin_lock_irq(q->queue_lock);
781+
spin_lock_irq(&q->queue_lock);
782782

783783
blkg = blkg_lookup_check(blkcg, pol, q);
784784
if (IS_ERR(blkg)) {
@@ -805,7 +805,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
805805
}
806806

807807
/* Drop locks to do new blkg allocation with GFP_KERNEL. */
808-
spin_unlock_irq(q->queue_lock);
808+
spin_unlock_irq(&q->queue_lock);
809809
rcu_read_unlock();
810810

811811
new_blkg = blkg_alloc(pos, q, GFP_KERNEL);
@@ -815,7 +815,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
815815
}
816816

817817
rcu_read_lock();
818-
spin_lock_irq(q->queue_lock);
818+
spin_lock_irq(&q->queue_lock);
819819

820820
blkg = blkg_lookup_check(pos, pol, q);
821821
if (IS_ERR(blkg)) {
@@ -843,7 +843,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
843843
return 0;
844844

845845
fail_unlock:
846-
spin_unlock_irq(q->queue_lock);
846+
spin_unlock_irq(&q->queue_lock);
847847
rcu_read_unlock();
848848
fail:
849849
put_disk_and_module(disk);
@@ -868,9 +868,9 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
868868
* with blkg_conf_prep().
869869
*/
870870
void blkg_conf_finish(struct blkg_conf_ctx *ctx)
871-
__releases(ctx->disk->queue->queue_lock) __releases(rcu)
871+
__releases(&ctx->disk->queue->queue_lock) __releases(rcu)
872872
{
873-
spin_unlock_irq(ctx->disk->queue->queue_lock);
873+
spin_unlock_irq(&ctx->disk->queue->queue_lock);
874874
rcu_read_unlock();
875875
put_disk_and_module(ctx->disk);
876876
}
@@ -903,7 +903,7 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
903903
*/
904904
off += scnprintf(buf+off, size-off, "%s ", dname);
905905

906-
spin_lock_irq(blkg->q->queue_lock);
906+
spin_lock_irq(&blkg->q->queue_lock);
907907

908908
rwstat = blkg_rwstat_recursive_sum(blkg, NULL,
909909
offsetof(struct blkcg_gq, stat_bytes));
@@ -917,7 +917,7 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
917917
wios = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_WRITE]);
918918
dios = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_DISCARD]);
919919

920-
spin_unlock_irq(blkg->q->queue_lock);
920+
spin_unlock_irq(&blkg->q->queue_lock);
921921

922922
if (rbytes || wbytes || rios || wios) {
923923
has_stats = true;
@@ -1038,9 +1038,9 @@ void blkcg_destroy_blkgs(struct blkcg *blkcg)
10381038
struct blkcg_gq, blkcg_node);
10391039
struct request_queue *q = blkg->q;
10401040

1041-
if (spin_trylock(q->queue_lock)) {
1041+
if (spin_trylock(&q->queue_lock)) {
10421042
blkg_destroy(blkg);
1043-
spin_unlock(q->queue_lock);
1043+
spin_unlock(&q->queue_lock);
10441044
} else {
10451045
spin_unlock_irq(&blkcg->lock);
10461046
cpu_relax();
@@ -1161,12 +1161,12 @@ int blkcg_init_queue(struct request_queue *q)
11611161

11621162
/* Make sure the root blkg exists. */
11631163
rcu_read_lock();
1164-
spin_lock_irq(q->queue_lock);
1164+
spin_lock_irq(&q->queue_lock);
11651165
blkg = blkg_create(&blkcg_root, q, new_blkg);
11661166
if (IS_ERR(blkg))
11671167
goto err_unlock;
11681168
q->root_blkg = blkg;
1169-
spin_unlock_irq(q->queue_lock);
1169+
spin_unlock_irq(&q->queue_lock);
11701170
rcu_read_unlock();
11711171

11721172
if (preloaded)
@@ -1185,7 +1185,7 @@ int blkcg_init_queue(struct request_queue *q)
11851185
blkg_destroy_all(q);
11861186
return ret;
11871187
err_unlock:
1188-
spin_unlock_irq(q->queue_lock);
1188+
spin_unlock_irq(&q->queue_lock);
11891189
rcu_read_unlock();
11901190
if (preloaded)
11911191
radix_tree_preload_end();
@@ -1200,7 +1200,7 @@ int blkcg_init_queue(struct request_queue *q)
12001200
*/
12011201
void blkcg_drain_queue(struct request_queue *q)
12021202
{
1203-
lockdep_assert_held(q->queue_lock);
1203+
lockdep_assert_held(&q->queue_lock);
12041204

12051205
/*
12061206
* @q could be exiting and already have destroyed all blkgs as
@@ -1335,7 +1335,7 @@ int blkcg_activate_policy(struct request_queue *q,
13351335
}
13361336
}
13371337

1338-
spin_lock_irq(q->queue_lock);
1338+
spin_lock_irq(&q->queue_lock);
13391339

13401340
list_for_each_entry(blkg, &q->blkg_list, q_node) {
13411341
struct blkg_policy_data *pd;
@@ -1347,7 +1347,7 @@ int blkcg_activate_policy(struct request_queue *q,
13471347
if (!pd)
13481348
swap(pd, pd_prealloc);
13491349
if (!pd) {
1350-
spin_unlock_irq(q->queue_lock);
1350+
spin_unlock_irq(&q->queue_lock);
13511351
goto pd_prealloc;
13521352
}
13531353

@@ -1361,7 +1361,7 @@ int blkcg_activate_policy(struct request_queue *q,
13611361
__set_bit(pol->plid, q->blkcg_pols);
13621362
ret = 0;
13631363

1364-
spin_unlock_irq(q->queue_lock);
1364+
spin_unlock_irq(&q->queue_lock);
13651365
out_bypass_end:
13661366
if (q->mq_ops)
13671367
blk_mq_unfreeze_queue(q);
@@ -1390,7 +1390,7 @@ void blkcg_deactivate_policy(struct request_queue *q,
13901390
if (q->mq_ops)
13911391
blk_mq_freeze_queue(q);
13921392

1393-
spin_lock_irq(q->queue_lock);
1393+
spin_lock_irq(&q->queue_lock);
13941394

13951395
__clear_bit(pol->plid, q->blkcg_pols);
13961396

@@ -1403,7 +1403,7 @@ void blkcg_deactivate_policy(struct request_queue *q,
14031403
}
14041404
}
14051405

1406-
spin_unlock_irq(q->queue_lock);
1406+
spin_unlock_irq(&q->queue_lock);
14071407

14081408
if (q->mq_ops)
14091409
blk_mq_unfreeze_queue(q);

‎block/blk-core.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ void blk_exit_queue(struct request_queue *q)
327327
*/
328328
void blk_cleanup_queue(struct request_queue *q)
329329
{
330-
spinlock_t *lock = q->queue_lock;
331-
332330
/* mark @q DYING, no new request or merges will be allowed afterwards */
333331
mutex_lock(&q->sysfs_lock);
334332
blk_set_queue_dying(q);
@@ -381,11 +379,6 @@ void blk_cleanup_queue(struct request_queue *q)
381379

382380
percpu_ref_exit(&q->q_usage_counter);
383381

384-
spin_lock_irq(lock);
385-
if (q->queue_lock != &q->__queue_lock)
386-
q->queue_lock = &q->__queue_lock;
387-
spin_unlock_irq(lock);
388-
389382
/* @q is and will stay empty, shutdown and put */
390383
blk_put_queue(q);
391384
}
@@ -524,8 +517,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
524517
mutex_init(&q->blk_trace_mutex);
525518
#endif
526519
mutex_init(&q->sysfs_lock);
527-
spin_lock_init(&q->__queue_lock);
528-
q->queue_lock = &q->__queue_lock;
520+
spin_lock_init(&q->queue_lock);
529521

530522
init_waitqueue_head(&q->mq_freeze_wq);
531523

0 commit comments

Comments
 (0)