From: Minchan Kim <minchan@kernel.org> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nitin Gupta <ngupta@vflare.org>, Seth Jennings <sjenning@linux.vnet.ibm.com>, Konrad Rzeszutek Wilk <konrad@darnok.org>, Dan Magenheimer <dan.magenheimer@oracle.com>, Pekka Enberg <penberg@cs.helsinki.fi>, jmarchan@redhat.com, Minchan Kim <minchan@kernel.org> Subject: [PATCH v3 2/4] zram: give up lazy initialization of zram metadata Date: Mon, 21 Jan 2013 14:21:29 +0900 [thread overview] Message-ID: <1358745691-4556-2-git-send-email-minchan@kernel.org> (raw) In-Reply-To: <1358745691-4556-1-git-send-email-minchan@kernel.org> 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. Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Minchan Kim <minchan@kernel.org> --- drivers/staging/zram/zram_drv.c | 20 ++++---------------- drivers/staging/zram/zram_sysfs.c | 1 + 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 1d45401..e95e37c 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -440,16 +440,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) { struct zram *zram = queue->queuedata; - if (unlikely(!zram->init_done) && zram_init_device(zram)) - goto error; - down_read(&zram->init_lock); if (unlikely(!zram->init_done)) - goto error_unlock; + goto error; if (!valid_io_request(zram, bio)) { zram_stat64_inc(zram, &zram->stats.invalid_io); - goto error_unlock; + goto error; } __zram_make_request(zram, bio, bio_data_dir(bio)); @@ -457,9 +454,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) return; -error_unlock: - up_read(&zram->init_lock); error: + up_read(&zram->init_lock); bio_io_error(bio); } @@ -509,18 +505,12 @@ void zram_reset_device(struct zram *zram) up_write(&zram->init_lock); } +/* zram->init_lock should be held */ int zram_init_device(struct zram *zram) { int ret; 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)) { pr_info( "There is little point creating a zram of greater than " @@ -569,7 +559,6 @@ int zram_init_device(struct zram *zram) } zram->init_done = 1; - up_write(&zram->init_lock); pr_debug("Initialization done!\n"); return 0; @@ -579,7 +568,6 @@ fail_no_table: zram->disksize = 0; fail: __zram_reset_device(zram); - up_write(&zram->init_lock); pr_err("Initialization failed: err=%d\n", ret); return ret; } diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index 4143af9..369db12 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -71,6 +71,7 @@ static ssize_t disksize_store(struct device *dev, zram->disksize = PAGE_ALIGN(disksize); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); + zram_init_device(zram); up_write(&zram->init_lock); return len; -- 1.7.9.5
WARNING: multiple messages have this Message-ID (diff)
From: Minchan Kim <minchan@kernel.org> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nitin Gupta <ngupta@vflare.org>, Seth Jennings <sjenning@linux.vnet.ibm.com>, Konrad Rzeszutek Wilk <konrad@darnok.org>, Dan Magenheimer <dan.magenheimer@oracle.com>, Pekka Enberg <penberg@cs.helsinki.fi>, jmarchan@redhat.com, Minchan Kim <minchan@kernel.org> Subject: [PATCH v3 2/4] zram: give up lazy initialization of zram metadata Date: Mon, 21 Jan 2013 14:21:29 +0900 [thread overview] Message-ID: <1358745691-4556-2-git-send-email-minchan@kernel.org> (raw) In-Reply-To: <1358745691-4556-1-git-send-email-minchan@kernel.org> 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. Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Minchan Kim <minchan@kernel.org> --- drivers/staging/zram/zram_drv.c | 20 ++++---------------- drivers/staging/zram/zram_sysfs.c | 1 + 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 1d45401..e95e37c 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -440,16 +440,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) { struct zram *zram = queue->queuedata; - if (unlikely(!zram->init_done) && zram_init_device(zram)) - goto error; - down_read(&zram->init_lock); if (unlikely(!zram->init_done)) - goto error_unlock; + goto error; if (!valid_io_request(zram, bio)) { zram_stat64_inc(zram, &zram->stats.invalid_io); - goto error_unlock; + goto error; } __zram_make_request(zram, bio, bio_data_dir(bio)); @@ -457,9 +454,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) return; -error_unlock: - up_read(&zram->init_lock); error: + up_read(&zram->init_lock); bio_io_error(bio); } @@ -509,18 +505,12 @@ void zram_reset_device(struct zram *zram) up_write(&zram->init_lock); } +/* zram->init_lock should be held */ int zram_init_device(struct zram *zram) { int ret; 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)) { pr_info( "There is little point creating a zram of greater than " @@ -569,7 +559,6 @@ int zram_init_device(struct zram *zram) } zram->init_done = 1; - up_write(&zram->init_lock); pr_debug("Initialization done!\n"); return 0; @@ -579,7 +568,6 @@ fail_no_table: zram->disksize = 0; fail: __zram_reset_device(zram); - up_write(&zram->init_lock); pr_err("Initialization failed: err=%d\n", ret); return ret; } diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index 4143af9..369db12 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -71,6 +71,7 @@ static ssize_t disksize_store(struct device *dev, zram->disksize = PAGE_ALIGN(disksize); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); + zram_init_device(zram); up_write(&zram->init_lock); return len; -- 1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-01-21 5:21 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-21 5:21 [PATCH v3 1/4] zram: force disksize setting before using zram Minchan Kim 2013-01-21 5:21 ` Minchan Kim 2013-01-21 5:21 ` Minchan Kim [this message] 2013-01-21 5:21 ` [PATCH v3 2/4] zram: give up lazy initialization of zram metadata Minchan Kim 2013-01-21 5:21 ` [PATCH v3 3/4] zram: get rid of lockdep warning Minchan Kim 2013-01-21 5:21 ` Minchan Kim 2013-01-21 19:47 ` Jerome Marchand 2013-01-21 19:47 ` Jerome Marchand 2013-01-21 23:29 ` Minchan Kim 2013-01-21 23:29 ` Minchan Kim 2013-01-21 5:21 ` [PATCH v3 4/4] zram: Fix deadlock bug in partial write Minchan Kim 2013-01-21 5:21 ` Minchan Kim 2013-01-21 19:39 ` [PATCH v3 1/4] zram: force disksize setting before using zram Jerome Marchand 2013-01-21 19:39 ` Jerome Marchand 2013-01-21 23:23 ` Minchan Kim 2013-01-21 23:23 ` Minchan Kim
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1358745691-4556-2-git-send-email-minchan@kernel.org \ --to=minchan@kernel.org \ --cc=dan.magenheimer@oracle.com \ --cc=gregkh@linuxfoundation.org \ --cc=jmarchan@redhat.com \ --cc=konrad@darnok.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=ngupta@vflare.org \ --cc=penberg@cs.helsinki.fi \ --cc=sjenning@linux.vnet.ibm.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.