Skip to content

Commit 94541bc

Browse files
bgaffakpm00
authored andcommitted
zram: always expose rw_page
Currently zram will adjust its fops to a version which does not contain rw_page when a backing device has been assigned. This is done to prevent upper layers from assuming a synchronous operation when a page may have been written back. This forces every operation through bio which has overhead associated with bio_alloc/frees. The code can be simplified to always expose an rw_page method and only in the rare event that a page is written back we instead will return -EOPNOTSUPP forcing the upper layer to fallback to bio. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Brian Geffon <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nitin Gupta <[email protected]> Cc: Rom Lemarchand <[email protected]> Cc: Suleiman Souhlal <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 14c2ac3 commit 94541bc

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

drivers/block/zram/zram_drv.c

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

5454
static const struct block_device_operations zram_devops;
55-
#ifdef CONFIG_ZRAM_WRITEBACK
56-
static const struct block_device_operations zram_wb_devops;
57-
#endif
5855

5956
static void zram_free_page(struct zram *zram, size_t index);
6057
static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
@@ -546,17 +543,6 @@ static ssize_t backing_dev_store(struct device *dev,
546543
zram->backing_dev = backing_dev;
547544
zram->bitmap = bitmap;
548545
zram->nr_pages = nr_pages;
549-
/*
550-
* With writeback feature, zram does asynchronous IO so it's no longer
551-
* synchronous device so let's remove synchronous io flag. Othewise,
552-
* upper layer(e.g., swap) could wait IO completion rather than
553-
* (submit and return), which will cause system sluggish.
554-
* Furthermore, when the IO function returns(e.g., swap_readpage),
555-
* upper layer expects IO was done so it could deallocate the page
556-
* freely but in fact, IO is going on so finally could cause
557-
* use-after-free when the IO is really done.
558-
*/
559-
zram->disk->fops = &zram_wb_devops;
560546
up_write(&zram->init_lock);
561547

562548
pr_info("setup backing device %s\n", file_name);
@@ -1270,6 +1256,9 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,
12701256
struct bio_vec bvec;
12711257

12721258
zram_slot_unlock(zram, index);
1259+
/* A null bio means rw_page was used, we must fallback to bio */
1260+
if (!bio)
1261+
return -EOPNOTSUPP;
12731262

12741263
bvec.bv_page = page;
12751264
bvec.bv_len = PAGE_SIZE;
@@ -1856,15 +1845,6 @@ static const struct block_device_operations zram_devops = {
18561845
.owner = THIS_MODULE
18571846
};
18581847

1859-
#ifdef CONFIG_ZRAM_WRITEBACK
1860-
static const struct block_device_operations zram_wb_devops = {
1861-
.open = zram_open,
1862-
.submit_bio = zram_submit_bio,
1863-
.swap_slot_free_notify = zram_slot_free_notify,
1864-
.owner = THIS_MODULE
1865-
};
1866-
#endif
1867-
18681848
static DEVICE_ATTR_WO(compact);
18691849
static DEVICE_ATTR_RW(disksize);
18701850
static DEVICE_ATTR_RO(initstate);

0 commit comments

Comments
 (0)