Skip to content

Commit edb0872

Browse files
Christoph Hellwigaxboe
Christoph Hellwig
authored andcommitted
block: move the bdi from the request_queue to the gendisk
The backing device information only makes sense for file system I/O, and thus belongs into the gendisk and not the lower level request_queue structure. Move it there. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1008162 commit edb0872

File tree

14 files changed

+58
-63
lines changed

14 files changed

+58
-63
lines changed

block/bfq-iosched.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,8 +5266,8 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic)
52665266
switch (ioprio_class) {
52675267
default:
52685268
pr_err("bdi %s: bfq: bad prio class %d\n",
5269-
bdi_dev_name(bfqq->bfqd->queue->backing_dev_info),
5270-
ioprio_class);
5269+
bdi_dev_name(queue_to_disk(bfqq->bfqd->queue)->bdi),
5270+
ioprio_class);
52715271
fallthrough;
52725272
case IOPRIO_CLASS_NONE:
52735273
/*

block/blk-cgroup.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,9 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
489489

490490
const char *blkg_dev_name(struct blkcg_gq *blkg)
491491
{
492-
/* some drivers (floppy) instantiate a queue w/o disk registered */
493-
if (blkg->q->backing_dev_info->dev)
494-
return bdi_dev_name(blkg->q->backing_dev_info);
495-
return NULL;
492+
if (!queue_has_disk(blkg->q) || !queue_to_disk(blkg->q)->bdi->dev)
493+
return NULL;
494+
return bdi_dev_name(queue_to_disk(blkg->q)->bdi);
496495
}
497496

498497
/**

block/blk-core.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
#include <linux/kernel.h>
1616
#include <linux/module.h>
17-
#include <linux/backing-dev.h>
1817
#include <linux/bio.h>
1918
#include <linux/blkdev.h>
2019
#include <linux/blk-mq.h>
@@ -531,13 +530,9 @@ struct request_queue *blk_alloc_queue(int node_id)
531530
if (ret)
532531
goto fail_id;
533532

534-
q->backing_dev_info = bdi_alloc(node_id);
535-
if (!q->backing_dev_info)
536-
goto fail_split;
537-
538533
q->stats = blk_alloc_queue_stats();
539534
if (!q->stats)
540-
goto fail_stats;
535+
goto fail_split;
541536

542537
q->node = node_id;
543538

@@ -567,7 +562,7 @@ struct request_queue *blk_alloc_queue(int node_id)
567562
if (percpu_ref_init(&q->q_usage_counter,
568563
blk_queue_usage_counter_release,
569564
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL))
570-
goto fail_bdi;
565+
goto fail_stats;
571566

572567
if (blkcg_init_queue(q))
573568
goto fail_ref;
@@ -580,10 +575,8 @@ struct request_queue *blk_alloc_queue(int node_id)
580575

581576
fail_ref:
582577
percpu_ref_exit(&q->q_usage_counter);
583-
fail_bdi:
584-
blk_free_queue_stats(q->stats);
585578
fail_stats:
586-
bdi_put(q->backing_dev_info);
579+
blk_free_queue_stats(q->stats);
587580
fail_split:
588581
bioset_exit(&q->bio_split);
589582
fail_id:

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ void blk_mq_free_request(struct request *rq)
525525
__blk_mq_dec_active_requests(hctx);
526526

527527
if (unlikely(laptop_mode && !blk_rq_is_passthrough(rq)))
528-
laptop_io_completion(q->backing_dev_info);
528+
laptop_io_completion(queue_to_disk(q)->bdi);
529529

530530
rq_qos_done(q, rq);
531531

block/blk-settings.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/bio.h>
99
#include <linux/blkdev.h>
1010
#include <linux/pagemap.h>
11+
#include <linux/backing-dev-defs.h>
1112
#include <linux/gcd.h>
1213
#include <linux/lcm.h>
1314
#include <linux/jiffies.h>
@@ -140,7 +141,9 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto
140141
limits->logical_block_size >> SECTOR_SHIFT);
141142
limits->max_sectors = max_sectors;
142143

143-
q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9);
144+
if (!queue_has_disk(q))
145+
return;
146+
queue_to_disk(q)->bdi->io_pages = max_sectors >> (PAGE_SHIFT - 9);
144147
}
145148
EXPORT_SYMBOL(blk_queue_max_hw_sectors);
146149

@@ -388,10 +391,9 @@ void disk_update_readahead(struct gendisk *disk)
388391
* For read-ahead of large files to be effective, we need to read ahead
389392
* at least twice the optimal I/O size.
390393
*/
391-
q->backing_dev_info->ra_pages =
394+
disk->bdi->ra_pages =
392395
max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
393-
q->backing_dev_info->io_pages =
394-
queue_max_sectors(q) >> (PAGE_SHIFT - 9);
396+
disk->bdi->io_pages = queue_max_sectors(q) >> (PAGE_SHIFT - 9);
395397
}
396398
EXPORT_SYMBOL_GPL(disk_update_readahead);
397399

@@ -473,7 +475,9 @@ EXPORT_SYMBOL(blk_limits_io_opt);
473475
void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
474476
{
475477
blk_limits_io_opt(&q->limits, opt);
476-
q->backing_dev_info->ra_pages =
478+
if (!queue_has_disk(q))
479+
return;
480+
queue_to_disk(q)->bdi->ra_pages =
477481
max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
478482
}
479483
EXPORT_SYMBOL(blk_queue_io_opt);

block/blk-sysfs.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,26 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
8888

8989
static ssize_t queue_ra_show(struct request_queue *q, char *page)
9090
{
91-
unsigned long ra_kb = q->backing_dev_info->ra_pages <<
92-
(PAGE_SHIFT - 10);
91+
unsigned long ra_kb;
9392

93+
if (!queue_has_disk(q))
94+
return -EINVAL;
95+
ra_kb = queue_to_disk(q)->bdi->ra_pages << (PAGE_SHIFT - 10);
9496
return queue_var_show(ra_kb, page);
9597
}
9698

9799
static ssize_t
98100
queue_ra_store(struct request_queue *q, const char *page, size_t count)
99101
{
100102
unsigned long ra_kb;
101-
ssize_t ret = queue_var_store(&ra_kb, page, count);
103+
ssize_t ret;
102104

105+
if (!queue_has_disk(q))
106+
return -EINVAL;
107+
ret = queue_var_store(&ra_kb, page, count);
103108
if (ret < 0)
104109
return ret;
105-
106-
q->backing_dev_info->ra_pages = ra_kb >> (PAGE_SHIFT - 10);
107-
110+
queue_to_disk(q)->bdi->ra_pages = ra_kb >> (PAGE_SHIFT - 10);
108111
return ret;
109112
}
110113

@@ -251,7 +254,9 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
251254

252255
spin_lock_irq(&q->queue_lock);
253256
q->limits.max_sectors = max_sectors_kb << 1;
254-
q->backing_dev_info->io_pages = max_sectors_kb >> (PAGE_SHIFT - 10);
257+
if (queue_has_disk(q))
258+
queue_to_disk(q)->bdi->io_pages =
259+
max_sectors_kb >> (PAGE_SHIFT - 10);
255260
spin_unlock_irq(&q->queue_lock);
256261

257262
return ret;
@@ -766,13 +771,6 @@ static void blk_exit_queue(struct request_queue *q)
766771
* e.g. blkcg_print_blkgs() to crash.
767772
*/
768773
blkcg_exit_queue(q);
769-
770-
/*
771-
* Since the cgroup code may dereference the @q->backing_dev_info
772-
* pointer, only decrease its reference count after having removed the
773-
* association with the block cgroup controller.
774-
*/
775-
bdi_put(q->backing_dev_info);
776774
}
777775

778776
/**

block/blk-wbt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void wb_timestamp(struct rq_wb *rwb, unsigned long *var)
9797
*/
9898
static bool wb_recent_wait(struct rq_wb *rwb)
9999
{
100-
struct bdi_writeback *wb = &rwb->rqos.q->backing_dev_info->wb;
100+
struct bdi_writeback *wb = &queue_to_disk(rwb->rqos.q)->bdi->wb;
101101

102102
return time_before(jiffies, wb->dirty_sleep + HZ);
103103
}
@@ -234,7 +234,7 @@ enum {
234234

235235
static int latency_exceeded(struct rq_wb *rwb, struct blk_rq_stat *stat)
236236
{
237-
struct backing_dev_info *bdi = rwb->rqos.q->backing_dev_info;
237+
struct backing_dev_info *bdi = queue_to_disk(rwb->rqos.q)->bdi;
238238
struct rq_depth *rqd = &rwb->rq_depth;
239239
u64 thislat;
240240

@@ -287,7 +287,7 @@ static int latency_exceeded(struct rq_wb *rwb, struct blk_rq_stat *stat)
287287

288288
static void rwb_trace_step(struct rq_wb *rwb, const char *msg)
289289
{
290-
struct backing_dev_info *bdi = rwb->rqos.q->backing_dev_info;
290+
struct backing_dev_info *bdi = queue_to_disk(rwb->rqos.q)->bdi;
291291
struct rq_depth *rqd = &rwb->rq_depth;
292292

293293
trace_wbt_step(bdi, msg, rqd->scale_step, rwb->cur_win_nsec,
@@ -359,8 +359,8 @@ static void wb_timer_fn(struct blk_stat_callback *cb)
359359

360360
status = latency_exceeded(rwb, cb->stat);
361361

362-
trace_wbt_timer(rwb->rqos.q->backing_dev_info, status, rqd->scale_step,
363-
inflight);
362+
trace_wbt_timer(queue_to_disk(rwb->rqos.q)->bdi, status,
363+
rqd->scale_step, inflight);
364364

365365
/*
366366
* If we exceeded the latency target, step down. If we did not,

block/genhd.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,9 @@ static void register_disk(struct device *parent, struct gendisk *disk,
466466
dev_set_uevent_suppress(ddev, 0);
467467
disk_uevent(disk, KOBJ_ADD);
468468

469-
if (disk->queue->backing_dev_info->dev) {
470-
err = sysfs_create_link(&ddev->kobj,
471-
&disk->queue->backing_dev_info->dev->kobj,
472-
"bdi");
469+
if (disk->bdi->dev) {
470+
err = sysfs_create_link(&ddev->kobj, &disk->bdi->dev->kobj,
471+
"bdi");
473472
WARN_ON(err);
474473
}
475474
}
@@ -540,15 +539,14 @@ void device_add_disk(struct device *parent, struct gendisk *disk,
540539
disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
541540
disk->flags |= GENHD_FL_NO_PART_SCAN;
542541
} else {
543-
struct backing_dev_info *bdi = disk->queue->backing_dev_info;
544542
struct device *dev = disk_to_dev(disk);
545543

546544
/* Register BDI before referencing it from bdev */
547545
dev->devt = MKDEV(disk->major, disk->first_minor);
548-
ret = bdi_register(bdi, "%u:%u",
546+
ret = bdi_register(disk->bdi, "%u:%u",
549547
disk->major, disk->first_minor);
550548
WARN_ON(ret);
551-
bdi_set_owner(bdi, dev);
549+
bdi_set_owner(disk->bdi, dev);
552550
bdev_add(disk->part0, dev->devt);
553551
}
554552
register_disk(parent, disk, groups);
@@ -615,7 +613,7 @@ void del_gendisk(struct gendisk *disk)
615613
* Unregister bdi before releasing device numbers (as they can
616614
* get reused and we'd get clashes in sysfs).
617615
*/
618-
bdi_unregister(disk->queue->backing_dev_info);
616+
bdi_unregister(disk->bdi);
619617
}
620618

621619
blk_unregister_queue(disk);
@@ -1088,6 +1086,7 @@ static void disk_release(struct device *dev)
10881086

10891087
might_sleep();
10901088

1089+
bdi_put(disk->bdi);
10911090
if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR)
10921091
blk_free_ext_minor(MINOR(dev->devt));
10931092
disk_release_events(disk);
@@ -1268,9 +1267,13 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
12681267
if (!disk)
12691268
return NULL;
12701269

1270+
disk->bdi = bdi_alloc(node_id);
1271+
if (!disk->bdi)
1272+
goto out_free_disk;
1273+
12711274
disk->part0 = bdev_alloc(disk, 0);
12721275
if (!disk->part0)
1273-
goto out_free_disk;
1276+
goto out_free_bdi;
12741277

12751278
disk->node_id = node_id;
12761279
mutex_init(&disk->open_mutex);
@@ -1292,6 +1295,8 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
12921295
out_destroy_part_tbl:
12931296
xa_destroy(&disk->part_tbl);
12941297
iput(disk->part0->bd_inode);
1298+
out_free_bdi:
1299+
bdi_put(disk->bdi);
12951300
out_free_disk:
12961301
kfree(disk);
12971302
return NULL;

drivers/block/drbd/drbd_req.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,12 @@ static bool drbd_may_do_local_read(struct drbd_device *device, sector_t sector,
905905
static bool remote_due_to_read_balancing(struct drbd_device *device, sector_t sector,
906906
enum drbd_read_balancing rbm)
907907
{
908-
struct backing_dev_info *bdi;
909908
int stripe_shift;
910909

911910
switch (rbm) {
912911
case RB_CONGESTED_REMOTE:
913-
bdi = device->ldev->backing_bdev->bd_disk->queue->backing_dev_info;
914-
return bdi_read_congested(bdi);
912+
return bdi_read_congested(
913+
device->ldev->backing_bdev->bd_disk->bdi);
915914
case RB_LEAST_PENDING:
916915
return atomic_read(&device->local_cnt) >
917916
atomic_read(&device->ap_pending_cnt) + atomic_read(&device->rs_pending_cnt);

drivers/block/pktcdvd.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,8 @@ static int pkt_handle_queue(struct pktcdvd_device *pd)
11831183
wakeup = (pd->write_congestion_on > 0
11841184
&& pd->bio_queue_size <= pd->write_congestion_off);
11851185
spin_unlock(&pd->lock);
1186-
if (wakeup) {
1187-
clear_bdi_congested(pd->disk->queue->backing_dev_info,
1188-
BLK_RW_ASYNC);
1189-
}
1186+
if (wakeup)
1187+
clear_bdi_congested(pd->disk->bdi, BLK_RW_ASYNC);
11901188

11911189
pkt->sleep_time = max(PACKET_WAIT_TIME, 1);
11921190
pkt_set_state(pkt, PACKET_WAITING_STATE);
@@ -2366,7 +2364,7 @@ static void pkt_make_request_write(struct request_queue *q, struct bio *bio)
23662364
spin_lock(&pd->lock);
23672365
if (pd->write_congestion_on > 0
23682366
&& pd->bio_queue_size >= pd->write_congestion_on) {
2369-
set_bdi_congested(q->backing_dev_info, BLK_RW_ASYNC);
2367+
set_bdi_congested(bio->bi_bdev->bd_disk->bdi, BLK_RW_ASYNC);
23702368
do {
23712369
spin_unlock(&pd->lock);
23722370
congestion_wait(BLK_RW_ASYNC, HZ);

fs/block_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
10871087
if (!bdev->bd_openers) {
10881088
set_init_blocksize(bdev);
10891089
if (bdev->bd_bdi == &noop_backing_dev_info)
1090-
bdev->bd_bdi = bdi_get(disk->queue->backing_dev_info);
1090+
bdev->bd_bdi = bdi_get(disk->bdi);
10911091
}
10921092
if (test_bit(GD_NEED_PART_SCAN, &disk->state))
10931093
bdev_disk_changed(disk, false);
@@ -1122,7 +1122,7 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode)
11221122
disk->open_partitions++;
11231123
set_init_blocksize(part);
11241124
if (part->bd_bdi == &noop_backing_dev_info)
1125-
part->bd_bdi = bdi_get(disk->queue->backing_dev_info);
1125+
part->bd_bdi = bdi_get(disk->bdi);
11261126
done:
11271127
part->bd_openers++;
11281128
return 0;

fs/fat/fatent.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/blkdev.h>
77
#include <linux/sched/signal.h>
8+
#include <linux/backing-dev-defs.h>
89
#include "fat.h"
910

1011
struct fatent_operations {

include/linux/blkdev.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/minmax.h>
1212
#include <linux/timer.h>
1313
#include <linux/workqueue.h>
14-
#include <linux/backing-dev-defs.h>
1514
#include <linux/wait.h>
1615
#include <linux/mempool.h>
1716
#include <linux/pfn.h>
@@ -398,8 +397,6 @@ struct request_queue {
398397
struct blk_mq_hw_ctx **queue_hw_ctx;
399398
unsigned int nr_hw_queues;
400399

401-
struct backing_dev_info *backing_dev_info;
402-
403400
/*
404401
* The queue owner gets to use this for whatever they like.
405402
* ll_rw_blk doesn't touch it.

include/linux/genhd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct gendisk {
158158
struct mutex open_mutex; /* open/close mutex */
159159
unsigned open_partitions; /* number of open partitions */
160160

161+
struct backing_dev_info *bdi;
161162
struct kobject *slave_dir;
162163
#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
163164
struct list_head slave_bdevs;

0 commit comments

Comments
 (0)