Skip to content

Commit a8b456d

Browse files
Christoph Hellwigaxboe
authored andcommitted
bdi: remove BDI_CAP_SYNCHRONOUS_IO
BDI_CAP_SYNCHRONOUS_IO is only checked in the swap code, and used to decided if ->rw_page can be used on a block device. Just check up for the method instead. The only complication is that zram needs a second set of block_device_operations as it can switch between modes that actually support ->rw_page and those who don't. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ed7b6b4 commit a8b456d

6 files changed

Lines changed: 14 additions & 20 deletions

File tree

‎drivers/block/brd.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ static struct brd_device *brd_alloc(int i)
403403
disk->flags = GENHD_FL_EXT_DEVT;
404404
sprintf(disk->disk_name, "ram%d", i);
405405
set_capacity(disk, rd_size * 2);
406-
brd->brd_queue->backing_dev_info->capabilities |= BDI_CAP_SYNCHRONOUS_IO;
407406

408407
/* Tell the block layer that this is not a rotational device */
409408
blk_queue_flag_set(QUEUE_FLAG_NONROT, brd->brd_queue);

‎drivers/block/zram/zram_drv.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ static unsigned int num_devices = 1;
5252
*/
5353
static size_t huge_class_size;
5454

55+
static const struct block_device_operations zram_devops;
56+
static const struct block_device_operations zram_wb_devops;
57+
5558
static void zram_free_page(struct zram *zram, size_t index);
5659
static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
5760
u32 index, int offset, struct bio *bio);
@@ -408,8 +411,7 @@ static void reset_bdev(struct zram *zram)
408411
zram->backing_dev = NULL;
409412
zram->old_block_size = 0;
410413
zram->bdev = NULL;
411-
zram->disk->queue->backing_dev_info->capabilities |=
412-
BDI_CAP_SYNCHRONOUS_IO;
414+
zram->disk->fops = &zram_devops;
413415
kvfree(zram->bitmap);
414416
zram->bitmap = NULL;
415417
}
@@ -529,8 +531,7 @@ static ssize_t backing_dev_store(struct device *dev,
529531
* freely but in fact, IO is going on so finally could cause
530532
* use-after-free when the IO is really done.
531533
*/
532-
zram->disk->queue->backing_dev_info->capabilities &=
533-
~BDI_CAP_SYNCHRONOUS_IO;
534+
zram->disk->fops = &zram_wb_devops;
534535
up_write(&zram->init_lock);
535536

536537
pr_info("setup backing device %s\n", file_name);
@@ -1820,6 +1821,13 @@ static const struct block_device_operations zram_devops = {
18201821
.owner = THIS_MODULE
18211822
};
18221823

1824+
static const struct block_device_operations zram_wb_devops = {
1825+
.open = zram_open,
1826+
.submit_bio = zram_submit_bio,
1827+
.swap_slot_free_notify = zram_slot_free_notify,
1828+
.owner = THIS_MODULE
1829+
};
1830+
18231831
static DEVICE_ATTR_WO(compact);
18241832
static DEVICE_ATTR_RW(disksize);
18251833
static DEVICE_ATTR_RO(initstate);
@@ -1947,8 +1955,7 @@ static int zram_add(void)
19471955
if (ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE)
19481956
blk_queue_max_write_zeroes_sectors(zram->disk->queue, UINT_MAX);
19491957

1950-
zram->disk->queue->backing_dev_info->capabilities |=
1951-
(BDI_CAP_STABLE_WRITES | BDI_CAP_SYNCHRONOUS_IO);
1958+
zram->disk->queue->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES;
19521959
device_add_disk(NULL, zram->disk, zram_disk_attr_groups);
19531960

19541961
strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));

‎drivers/nvdimm/btt.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,6 @@ static int btt_blk_init(struct btt *btt)
15371537
btt->btt_disk->private_data = btt;
15381538
btt->btt_disk->queue = btt->btt_queue;
15391539
btt->btt_disk->flags = GENHD_FL_EXT_DEVT;
1540-
btt->btt_disk->queue->backing_dev_info->capabilities |=
1541-
BDI_CAP_SYNCHRONOUS_IO;
15421540

15431541
blk_queue_logical_block_size(btt->btt_queue, btt->sector_size);
15441542
blk_queue_max_hw_sectors(btt->btt_queue, UINT_MAX);

‎drivers/nvdimm/pmem.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ static int pmem_attach_disk(struct device *dev,
475475
disk->queue = q;
476476
disk->flags = GENHD_FL_EXT_DEVT;
477477
disk->private_data = pmem;
478-
disk->queue->backing_dev_info->capabilities |= BDI_CAP_SYNCHRONOUS_IO;
479478
nvdimm_namespace_disk_name(ndns, disk->disk_name);
480479
set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)
481480
/ 512);

‎include/linux/backing-dev.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,13 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
122122
* BDI_CAP_NO_WRITEBACK: Don't write pages back
123123
* BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages
124124
* BDI_CAP_STRICTLIMIT: Keep number of dirty pages below bdi threshold.
125-
*
126-
* BDI_CAP_SYNCHRONOUS_IO: Device is so fast that asynchronous IO would be
127-
* inefficient.
128125
*/
129126
#define BDI_CAP_NO_ACCT_DIRTY 0x00000001
130127
#define BDI_CAP_NO_WRITEBACK 0x00000002
131128
#define BDI_CAP_NO_ACCT_WB 0x00000004
132129
#define BDI_CAP_STABLE_WRITES 0x00000008
133130
#define BDI_CAP_STRICTLIMIT 0x00000010
134131
#define BDI_CAP_CGROUP_WRITEBACK 0x00000020
135-
#define BDI_CAP_SYNCHRONOUS_IO 0x00000040
136132

137133
#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
138134
(BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)
@@ -174,11 +170,6 @@ static inline int wb_congested(struct bdi_writeback *wb, int cong_bits)
174170
long congestion_wait(int sync, long timeout);
175171
long wait_iff_congested(int sync, long timeout);
176172

177-
static inline bool bdi_cap_synchronous_io(struct backing_dev_info *bdi)
178-
{
179-
return bdi->capabilities & BDI_CAP_SYNCHRONOUS_IO;
180-
}
181-
182173
static inline bool bdi_cap_stable_pages_required(struct backing_dev_info *bdi)
183174
{
184175
return bdi->capabilities & BDI_CAP_STABLE_WRITES;

‎mm/swapfile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
32403240
if (bdi_cap_stable_pages_required(inode_to_bdi(inode)))
32413241
p->flags |= SWP_STABLE_WRITES;
32423242

3243-
if (bdi_cap_synchronous_io(inode_to_bdi(inode)))
3243+
if (p->bdev && p->bdev->bd_disk->fops->rw_page)
32443244
p->flags |= SWP_SYNCHRONOUS_IO;
32453245

32463246
if (p->bdev && blk_queue_nonrot(bdev_get_queue(p->bdev))) {

0 commit comments

Comments
 (0)