Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/20210809141744.1203023-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
edb0872f 1008162b

+58 -63
+2 -2
block/bfq-iosched.c
··· 5266 5266 switch (ioprio_class) { 5267 5267 default: 5268 5268 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); 5271 5271 fallthrough; 5272 5272 case IOPRIO_CLASS_NONE: 5273 5273 /*
+3 -4
block/blk-cgroup.c
··· 489 489 490 490 const char *blkg_dev_name(struct blkcg_gq *blkg) 491 491 { 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); 496 495 } 497 496 498 497 /**
+3 -10
block/blk-core.c
··· 14 14 */ 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 - #include <linux/backing-dev.h> 18 17 #include <linux/bio.h> 19 18 #include <linux/blkdev.h> 20 19 #include <linux/blk-mq.h> ··· 530 531 if (ret) 531 532 goto fail_id; 532 533 533 - q->backing_dev_info = bdi_alloc(node_id); 534 - if (!q->backing_dev_info) 535 - goto fail_split; 536 - 537 534 q->stats = blk_alloc_queue_stats(); 538 535 if (!q->stats) 539 - goto fail_stats; 536 + goto fail_split; 540 537 541 538 q->node = node_id; 542 539 ··· 562 567 if (percpu_ref_init(&q->q_usage_counter, 563 568 blk_queue_usage_counter_release, 564 569 PERCPU_REF_INIT_ATOMIC, GFP_KERNEL)) 565 - goto fail_bdi; 570 + goto fail_stats; 566 571 567 572 if (blkcg_init_queue(q)) 568 573 goto fail_ref; ··· 575 580 576 581 fail_ref: 577 582 percpu_ref_exit(&q->q_usage_counter); 578 - fail_bdi: 579 - blk_free_queue_stats(q->stats); 580 583 fail_stats: 581 - bdi_put(q->backing_dev_info); 584 + blk_free_queue_stats(q->stats); 582 585 fail_split: 583 586 bioset_exit(&q->bio_split); 584 587 fail_id:
+1 -1
block/blk-mq.c
··· 525 525 __blk_mq_dec_active_requests(hctx); 526 526 527 527 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); 529 529 530 530 rq_qos_done(q, rq); 531 531
+9 -5
block/blk-settings.c
··· 8 8 #include <linux/bio.h> 9 9 #include <linux/blkdev.h> 10 10 #include <linux/pagemap.h> 11 + #include <linux/backing-dev-defs.h> 11 12 #include <linux/gcd.h> 12 13 #include <linux/lcm.h> 13 14 #include <linux/jiffies.h> ··· 141 140 limits->logical_block_size >> SECTOR_SHIFT); 142 141 limits->max_sectors = max_sectors; 143 142 144 - q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9); 143 + if (!queue_has_disk(q)) 144 + return; 145 + queue_to_disk(q)->bdi->io_pages = max_sectors >> (PAGE_SHIFT - 9); 145 146 } 146 147 EXPORT_SYMBOL(blk_queue_max_hw_sectors); 147 148 ··· 391 388 * For read-ahead of large files to be effective, we need to read ahead 392 389 * at least twice the optimal I/O size. 393 390 */ 394 - q->backing_dev_info->ra_pages = 391 + disk->bdi->ra_pages = 395 392 max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES); 396 - q->backing_dev_info->io_pages = 397 - queue_max_sectors(q) >> (PAGE_SHIFT - 9); 393 + disk->bdi->io_pages = queue_max_sectors(q) >> (PAGE_SHIFT - 9); 398 394 } 399 395 EXPORT_SYMBOL_GPL(disk_update_readahead); 400 396 ··· 475 473 void blk_queue_io_opt(struct request_queue *q, unsigned int opt) 476 474 { 477 475 blk_limits_io_opt(&q->limits, opt); 478 - q->backing_dev_info->ra_pages = 476 + if (!queue_has_disk(q)) 477 + return; 478 + queue_to_disk(q)->bdi->ra_pages = 479 479 max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES); 480 480 } 481 481 EXPORT_SYMBOL(blk_queue_io_opt);
+12 -14
block/blk-sysfs.c
··· 88 88 89 89 static ssize_t queue_ra_show(struct request_queue *q, char *page) 90 90 { 91 - unsigned long ra_kb = q->backing_dev_info->ra_pages << 92 - (PAGE_SHIFT - 10); 91 + unsigned long ra_kb; 93 92 93 + if (!queue_has_disk(q)) 94 + return -EINVAL; 95 + ra_kb = queue_to_disk(q)->bdi->ra_pages << (PAGE_SHIFT - 10); 94 96 return queue_var_show(ra_kb, page); 95 97 } 96 98 ··· 100 98 queue_ra_store(struct request_queue *q, const char *page, size_t count) 101 99 { 102 100 unsigned long ra_kb; 103 - ssize_t ret = queue_var_store(&ra_kb, page, count); 101 + ssize_t ret; 104 102 103 + if (!queue_has_disk(q)) 104 + return -EINVAL; 105 + ret = queue_var_store(&ra_kb, page, count); 105 106 if (ret < 0) 106 107 return ret; 107 - 108 - q->backing_dev_info->ra_pages = ra_kb >> (PAGE_SHIFT - 10); 109 - 108 + queue_to_disk(q)->bdi->ra_pages = ra_kb >> (PAGE_SHIFT - 10); 110 109 return ret; 111 110 } 112 111 ··· 254 251 255 252 spin_lock_irq(&q->queue_lock); 256 253 q->limits.max_sectors = max_sectors_kb << 1; 257 - q->backing_dev_info->io_pages = max_sectors_kb >> (PAGE_SHIFT - 10); 254 + if (queue_has_disk(q)) 255 + queue_to_disk(q)->bdi->io_pages = 256 + max_sectors_kb >> (PAGE_SHIFT - 10); 258 257 spin_unlock_irq(&q->queue_lock); 259 258 260 259 return ret; ··· 771 766 * e.g. blkcg_print_blkgs() to crash. 772 767 */ 773 768 blkcg_exit_queue(q); 774 - 775 - /* 776 - * Since the cgroup code may dereference the @q->backing_dev_info 777 - * pointer, only decrease its reference count after having removed the 778 - * association with the block cgroup controller. 779 - */ 780 - bdi_put(q->backing_dev_info); 781 769 } 782 770 783 771 /**
+5 -5
block/blk-wbt.c
··· 97 97 */ 98 98 static bool wb_recent_wait(struct rq_wb *rwb) 99 99 { 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; 101 101 102 102 return time_before(jiffies, wb->dirty_sleep + HZ); 103 103 } ··· 234 234 235 235 static int latency_exceeded(struct rq_wb *rwb, struct blk_rq_stat *stat) 236 236 { 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; 238 238 struct rq_depth *rqd = &rwb->rq_depth; 239 239 u64 thislat; 240 240 ··· 287 287 288 288 static void rwb_trace_step(struct rq_wb *rwb, const char *msg) 289 289 { 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; 291 291 struct rq_depth *rqd = &rwb->rq_depth; 292 292 293 293 trace_wbt_step(bdi, msg, rqd->scale_step, rwb->cur_win_nsec, ··· 359 359 360 360 status = latency_exceeded(rwb, cb->stat); 361 361 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); 364 364 365 365 /* 366 366 * If we exceeded the latency target, step down. If we did not,
+14 -9
block/genhd.c
··· 466 466 dev_set_uevent_suppress(ddev, 0); 467 467 disk_uevent(disk, KOBJ_ADD); 468 468 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"); 473 472 WARN_ON(err); 474 473 } 475 474 } ··· 539 540 disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; 540 541 disk->flags |= GENHD_FL_NO_PART_SCAN; 541 542 } else { 542 - struct backing_dev_info *bdi = disk->queue->backing_dev_info; 543 543 struct device *dev = disk_to_dev(disk); 544 544 545 545 /* Register BDI before referencing it from bdev */ 546 546 dev->devt = MKDEV(disk->major, disk->first_minor); 547 - ret = bdi_register(bdi, "%u:%u", 547 + ret = bdi_register(disk->bdi, "%u:%u", 548 548 disk->major, disk->first_minor); 549 549 WARN_ON(ret); 550 - bdi_set_owner(bdi, dev); 550 + bdi_set_owner(disk->bdi, dev); 551 551 bdev_add(disk->part0, dev->devt); 552 552 } 553 553 register_disk(parent, disk, groups); ··· 613 615 * Unregister bdi before releasing device numbers (as they can 614 616 * get reused and we'd get clashes in sysfs). 615 617 */ 616 - bdi_unregister(disk->queue->backing_dev_info); 618 + bdi_unregister(disk->bdi); 617 619 } 618 620 619 621 blk_unregister_queue(disk); ··· 1086 1088 1087 1089 might_sleep(); 1088 1090 1091 + bdi_put(disk->bdi); 1089 1092 if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR) 1090 1093 blk_free_ext_minor(MINOR(dev->devt)); 1091 1094 disk_release_events(disk); ··· 1267 1268 if (!disk) 1268 1269 return NULL; 1269 1270 1271 + disk->bdi = bdi_alloc(node_id); 1272 + if (!disk->bdi) 1273 + goto out_free_disk; 1274 + 1270 1275 disk->part0 = bdev_alloc(disk, 0); 1271 1276 if (!disk->part0) 1272 - goto out_free_disk; 1277 + goto out_free_bdi; 1273 1278 1274 1279 disk->node_id = node_id; 1275 1280 mutex_init(&disk->open_mutex); ··· 1295 1292 out_destroy_part_tbl: 1296 1293 xa_destroy(&disk->part_tbl); 1297 1294 iput(disk->part0->bd_inode); 1295 + out_free_bdi: 1296 + bdi_put(disk->bdi); 1298 1297 out_free_disk: 1299 1298 kfree(disk); 1300 1299 return NULL;
+2 -3
drivers/block/drbd/drbd_req.c
··· 905 905 static bool remote_due_to_read_balancing(struct drbd_device *device, sector_t sector, 906 906 enum drbd_read_balancing rbm) 907 907 { 908 - struct backing_dev_info *bdi; 909 908 int stripe_shift; 910 909 911 910 switch (rbm) { 912 911 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); 915 914 case RB_LEAST_PENDING: 916 915 return atomic_read(&device->local_cnt) > 917 916 atomic_read(&device->ap_pending_cnt) + atomic_read(&device->rs_pending_cnt);
+3 -5
drivers/block/pktcdvd.c
··· 1183 1183 wakeup = (pd->write_congestion_on > 0 1184 1184 && pd->bio_queue_size <= pd->write_congestion_off); 1185 1185 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); 1190 1188 1191 1189 pkt->sleep_time = max(PACKET_WAIT_TIME, 1); 1192 1190 pkt_set_state(pkt, PACKET_WAITING_STATE); ··· 2364 2366 spin_lock(&pd->lock); 2365 2367 if (pd->write_congestion_on > 0 2366 2368 && pd->bio_queue_size >= pd->write_congestion_on) { 2367 - set_bdi_congested(q->backing_dev_info, BLK_RW_ASYNC); 2369 + set_bdi_congested(bio->bi_bdev->bd_disk->bdi, BLK_RW_ASYNC); 2368 2370 do { 2369 2371 spin_unlock(&pd->lock); 2370 2372 congestion_wait(BLK_RW_ASYNC, HZ);
+2 -2
fs/block_dev.c
··· 1087 1087 if (!bdev->bd_openers) { 1088 1088 set_init_blocksize(bdev); 1089 1089 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); 1091 1091 } 1092 1092 if (test_bit(GD_NEED_PART_SCAN, &disk->state)) 1093 1093 bdev_disk_changed(disk, false); ··· 1122 1122 disk->open_partitions++; 1123 1123 set_init_blocksize(part); 1124 1124 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); 1126 1126 done: 1127 1127 part->bd_openers++; 1128 1128 return 0;
+1
fs/fat/fatent.c
··· 5 5 6 6 #include <linux/blkdev.h> 7 7 #include <linux/sched/signal.h> 8 + #include <linux/backing-dev-defs.h> 8 9 #include "fat.h" 9 10 10 11 struct fatent_operations {
-3
include/linux/blkdev.h
··· 11 11 #include <linux/minmax.h> 12 12 #include <linux/timer.h> 13 13 #include <linux/workqueue.h> 14 - #include <linux/backing-dev-defs.h> 15 14 #include <linux/wait.h> 16 15 #include <linux/mempool.h> 17 16 #include <linux/pfn.h> ··· 396 397 /* hw dispatch queues */ 397 398 struct blk_mq_hw_ctx **queue_hw_ctx; 398 399 unsigned int nr_hw_queues; 399 - 400 - struct backing_dev_info *backing_dev_info; 401 400 402 401 /* 403 402 * The queue owner gets to use this for whatever they like.
+1
include/linux/genhd.h
··· 158 158 struct mutex open_mutex; /* open/close mutex */ 159 159 unsigned open_partitions; /* number of open partitions */ 160 160 161 + struct backing_dev_info *bdi; 161 162 struct kobject *slave_dir; 162 163 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED 163 164 struct list_head slave_bdevs;