Commit 3de738cd authored by Minchan Kim's avatar Minchan Kim Committed by Greg Kroah-Hartman

zram: give up lazy initialization of zram metadata

1) User of zram normally do mkfs.xxx or mkswap before using
   the zram block device(ex, normally, do it at booting time)
   It ends up allocating such metadata of zram before real usage so
   benefit of lazy initialzation would be mitigated.

2) Some user want to use zram when memory pressure is high.(ie, load zram
   dynamically, NOT booting time). It does make sense because people don't
   want to waste memory until memory pressure is high(ie, where zram is really
   helpful time). In this case, lazy initialzation could be failed easily
   because we will use GFP_NOIO instead of GFP_KERNEL for avoiding deadlock.
   So the benefit of lazy initialzation would be mitigated, too.

3) Metadata overhead is not critical and Nitin has a plan to diet it.
   4K : 12 byte(64bit machine) -> 64G : 192M so 0.3% isn't big overhead
   If insane user use such big zram device up to 20, it could consume 6% of ram
   but efficieny of zram will cover the waste.

So this patch gives up lazy initialization and instead we initialize metadata
at disksize setting time.
Acked-by: default avatarJerome Marchand <jmarchand@redhat.com>
Acked-by: default avatarNitin Gupta <ngupta@vflare.org>
Signed-off-by: default avatarMinchan Kim <minchan@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0231c403
...@@ -442,16 +442,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) ...@@ -442,16 +442,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
{ {
struct zram *zram = queue->queuedata; struct zram *zram = queue->queuedata;
if (unlikely(!zram->init_done) && zram_init_device(zram))
goto error;
down_read(&zram->init_lock); down_read(&zram->init_lock);
if (unlikely(!zram->init_done)) if (unlikely(!zram->init_done))
goto error_unlock; goto error;
if (!valid_io_request(zram, bio)) { if (!valid_io_request(zram, bio)) {
zram_stat64_inc(zram, &zram->stats.invalid_io); zram_stat64_inc(zram, &zram->stats.invalid_io);
goto error_unlock; goto error;
} }
__zram_make_request(zram, bio, bio_data_dir(bio)); __zram_make_request(zram, bio, bio_data_dir(bio));
...@@ -459,9 +456,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) ...@@ -459,9 +456,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
return; return;
error_unlock:
up_read(&zram->init_lock);
error: error:
up_read(&zram->init_lock);
bio_io_error(bio); bio_io_error(bio);
} }
...@@ -510,18 +506,12 @@ void zram_reset_device(struct zram *zram) ...@@ -510,18 +506,12 @@ void zram_reset_device(struct zram *zram)
up_write(&zram->init_lock); up_write(&zram->init_lock);
} }
/* zram->init_lock should be held */
int zram_init_device(struct zram *zram) int zram_init_device(struct zram *zram)
{ {
int ret; int ret;
size_t num_pages; size_t num_pages;
down_write(&zram->init_lock);
if (zram->init_done) {
up_write(&zram->init_lock);
return 0;
}
if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) { if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) {
pr_info( pr_info(
"There is little point creating a zram of greater than " "There is little point creating a zram of greater than "
...@@ -570,7 +560,6 @@ int zram_init_device(struct zram *zram) ...@@ -570,7 +560,6 @@ int zram_init_device(struct zram *zram)
} }
zram->init_done = 1; zram->init_done = 1;
up_write(&zram->init_lock);
pr_debug("Initialization done!\n"); pr_debug("Initialization done!\n");
return 0; return 0;
...@@ -580,7 +569,6 @@ int zram_init_device(struct zram *zram) ...@@ -580,7 +569,6 @@ int zram_init_device(struct zram *zram)
zram->disksize = 0; zram->disksize = 0;
fail: fail:
__zram_reset_device(zram); __zram_reset_device(zram);
up_write(&zram->init_lock);
pr_err("Initialization failed: err=%d\n", ret); pr_err("Initialization failed: err=%d\n", ret);
return ret; return ret;
} }
......
...@@ -71,6 +71,7 @@ static ssize_t disksize_store(struct device *dev, ...@@ -71,6 +71,7 @@ static ssize_t disksize_store(struct device *dev,
zram->disksize = PAGE_ALIGN(disksize); zram->disksize = PAGE_ALIGN(disksize);
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
zram_init_device(zram);
up_write(&zram->init_lock); up_write(&zram->init_lock);
return len; return len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment