From: Seth Jennings <sjennings@variantweb.net> To: Minchan Kim <minchan@kernel.org> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Jerome Marchand <jmarchan@redhat.com>, juno.choi@lge.com, seungho1.park@lge.com, Luigi Semenzato <semenzato@google.com>, Nitin Gupta <ngupta@vflare.org> Subject: Re: [RFC 2/3] zsmalloc/zram: add zs_get_max_size_bytes and use it in zram Date: Wed, 13 Aug 2014 10:25:02 -0500 [thread overview] Message-ID: <20140813152502.GB2768@cerebellum.variantweb.net> (raw) In-Reply-To: <1407225723-23754-3-git-send-email-minchan@kernel.org> On Tue, Aug 05, 2014 at 05:02:02PM +0900, Minchan Kim wrote: > Normally, zram user can get maximum memory zsmalloc consumed via > polling mem_used_total with sysfs in userspace. > > But it has a critical problem because user can miss peak memory > usage during update interval so that gap between them could be > huge when memory pressure is really heavy. > > This patch adds new API zs_get_max_size_bytes in zsmalloc so > user(ex, zram) doesn't need to poll in short interval to get > exact value. > > User can just see max memory usage once his test workload is > done. It's pretty handy and accurate. > > Signed-off-by: Minchan Kim <minchan@kernel.org> > --- > Documentation/blockdev/zram.txt | 1 + > drivers/block/zram/zram_drv.c | 17 +++++++++++++++++ > include/linux/zsmalloc.h | 1 + > mm/zsmalloc.c | 20 ++++++++++++++++++++ > 4 files changed, 39 insertions(+) > > diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt > index 0595c3f56ccf..d24534bee763 100644 > --- a/Documentation/blockdev/zram.txt > +++ b/Documentation/blockdev/zram.txt > @@ -95,6 +95,7 @@ size of the disk when not in use so a huge zram is wasteful. > orig_data_size > compr_data_size > mem_used_total > + mem_used_max > > 7) Deactivate: > swapoff /dev/zram0 > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index 36e54be402df..a4d637b4db7d 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -109,6 +109,21 @@ static ssize_t mem_used_total_show(struct device *dev, > return scnprintf(buf, PAGE_SIZE, "%llu\n", val); > } > > +static ssize_t mem_used_max_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + u64 val = 0; > + struct zram *zram = dev_to_zram(dev); > + struct zram_meta *meta = zram->meta; > + > + down_read(&zram->init_lock); > + if (init_done(zram)) > + val = zs_get_max_size_bytes(meta->mem_pool); > + up_read(&zram->init_lock); > + > + return scnprintf(buf, PAGE_SIZE, "%llu\n", val); > +} > + > static ssize_t max_comp_streams_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > @@ -838,6 +853,7 @@ static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL); > static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store); > static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL); > static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL); > +static DEVICE_ATTR(mem_used_max, S_IRUGO, mem_used_max_show, NULL); > static DEVICE_ATTR(max_comp_streams, S_IRUGO | S_IWUSR, > max_comp_streams_show, max_comp_streams_store); > static DEVICE_ATTR(comp_algorithm, S_IRUGO | S_IWUSR, > @@ -866,6 +882,7 @@ static struct attribute *zram_disk_attrs[] = { > &dev_attr_orig_data_size.attr, > &dev_attr_compr_data_size.attr, > &dev_attr_mem_used_total.attr, > + &dev_attr_mem_used_max.attr, > &dev_attr_max_comp_streams.attr, > &dev_attr_comp_algorithm.attr, > NULL, > diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h > index e44d634e7fb7..fb087ca06a88 100644 > --- a/include/linux/zsmalloc.h > +++ b/include/linux/zsmalloc.h > @@ -47,5 +47,6 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, > void zs_unmap_object(struct zs_pool *pool, unsigned long handle); > > u64 zs_get_total_size_bytes(struct zs_pool *pool); > +u64 zs_get_max_size_bytes(struct zs_pool *pool); > > #endif > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index a6089bd26621..3b5be076268a 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -219,6 +219,7 @@ struct zs_pool { > > gfp_t flags; /* allocation flags used when growing pool */ > unsigned long pages_allocated; > + unsigned long max_pages_allocated; Same here with atomic. Seth > }; > > /* > @@ -946,6 +947,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size) > set_zspage_mapping(first_page, class->index, ZS_EMPTY); > spin_lock(&pool->stat_lock); > pool->pages_allocated += class->pages_per_zspage; > + if (pool->max_pages_allocated < pool->pages_allocated) > + pool->max_pages_allocated = pool->pages_allocated; > spin_unlock(&pool->stat_lock); > spin_lock(&class->lock); > } > @@ -1101,6 +1104,9 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) > } > EXPORT_SYMBOL_GPL(zs_unmap_object); > > +/* > + * Reports current memory usage consumed by zs_malloc > + */ > u64 zs_get_total_size_bytes(struct zs_pool *pool) > { > u64 npages; > @@ -1112,6 +1118,20 @@ u64 zs_get_total_size_bytes(struct zs_pool *pool) > } > EXPORT_SYMBOL_GPL(zs_get_total_size_bytes); > > +/* > + * Reports maximum memory usage zs_malloc have consumed > + */ > +u64 zs_get_max_size_bytes(struct zs_pool *pool) > +{ > + u64 npages; > + > + spin_lock(&pool->stat_lock); > + npages = pool->max_pages_allocated; > + spin_unlock(&pool->stat_lock); > + return npages << PAGE_SHIFT; > +} > +EXPORT_SYMBOL_GPL(zs_get_max_size_bytes); > + > module_init(zs_init); > module_exit(zs_exit); > > -- > 2.0.0 > > -- > 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>
WARNING: multiple messages have this Message-ID (diff)
From: Seth Jennings <sjennings@variantweb.net> To: Minchan Kim <minchan@kernel.org> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Jerome Marchand <jmarchan@redhat.com>, juno.choi@lge.com, seungho1.park@lge.com, Luigi Semenzato <semenzato@google.com>, Nitin Gupta <ngupta@vflare.org> Subject: Re: [RFC 2/3] zsmalloc/zram: add zs_get_max_size_bytes and use it in zram Date: Wed, 13 Aug 2014 10:25:02 -0500 [thread overview] Message-ID: <20140813152502.GB2768@cerebellum.variantweb.net> (raw) In-Reply-To: <1407225723-23754-3-git-send-email-minchan@kernel.org> On Tue, Aug 05, 2014 at 05:02:02PM +0900, Minchan Kim wrote: > Normally, zram user can get maximum memory zsmalloc consumed via > polling mem_used_total with sysfs in userspace. > > But it has a critical problem because user can miss peak memory > usage during update interval so that gap between them could be > huge when memory pressure is really heavy. > > This patch adds new API zs_get_max_size_bytes in zsmalloc so > user(ex, zram) doesn't need to poll in short interval to get > exact value. > > User can just see max memory usage once his test workload is > done. It's pretty handy and accurate. > > Signed-off-by: Minchan Kim <minchan@kernel.org> > --- > Documentation/blockdev/zram.txt | 1 + > drivers/block/zram/zram_drv.c | 17 +++++++++++++++++ > include/linux/zsmalloc.h | 1 + > mm/zsmalloc.c | 20 ++++++++++++++++++++ > 4 files changed, 39 insertions(+) > > diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt > index 0595c3f56ccf..d24534bee763 100644 > --- a/Documentation/blockdev/zram.txt > +++ b/Documentation/blockdev/zram.txt > @@ -95,6 +95,7 @@ size of the disk when not in use so a huge zram is wasteful. > orig_data_size > compr_data_size > mem_used_total > + mem_used_max > > 7) Deactivate: > swapoff /dev/zram0 > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index 36e54be402df..a4d637b4db7d 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -109,6 +109,21 @@ static ssize_t mem_used_total_show(struct device *dev, > return scnprintf(buf, PAGE_SIZE, "%llu\n", val); > } > > +static ssize_t mem_used_max_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + u64 val = 0; > + struct zram *zram = dev_to_zram(dev); > + struct zram_meta *meta = zram->meta; > + > + down_read(&zram->init_lock); > + if (init_done(zram)) > + val = zs_get_max_size_bytes(meta->mem_pool); > + up_read(&zram->init_lock); > + > + return scnprintf(buf, PAGE_SIZE, "%llu\n", val); > +} > + > static ssize_t max_comp_streams_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > @@ -838,6 +853,7 @@ static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL); > static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store); > static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL); > static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL); > +static DEVICE_ATTR(mem_used_max, S_IRUGO, mem_used_max_show, NULL); > static DEVICE_ATTR(max_comp_streams, S_IRUGO | S_IWUSR, > max_comp_streams_show, max_comp_streams_store); > static DEVICE_ATTR(comp_algorithm, S_IRUGO | S_IWUSR, > @@ -866,6 +882,7 @@ static struct attribute *zram_disk_attrs[] = { > &dev_attr_orig_data_size.attr, > &dev_attr_compr_data_size.attr, > &dev_attr_mem_used_total.attr, > + &dev_attr_mem_used_max.attr, > &dev_attr_max_comp_streams.attr, > &dev_attr_comp_algorithm.attr, > NULL, > diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h > index e44d634e7fb7..fb087ca06a88 100644 > --- a/include/linux/zsmalloc.h > +++ b/include/linux/zsmalloc.h > @@ -47,5 +47,6 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, > void zs_unmap_object(struct zs_pool *pool, unsigned long handle); > > u64 zs_get_total_size_bytes(struct zs_pool *pool); > +u64 zs_get_max_size_bytes(struct zs_pool *pool); > > #endif > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index a6089bd26621..3b5be076268a 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -219,6 +219,7 @@ struct zs_pool { > > gfp_t flags; /* allocation flags used when growing pool */ > unsigned long pages_allocated; > + unsigned long max_pages_allocated; Same here with atomic. Seth > }; > > /* > @@ -946,6 +947,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size) > set_zspage_mapping(first_page, class->index, ZS_EMPTY); > spin_lock(&pool->stat_lock); > pool->pages_allocated += class->pages_per_zspage; > + if (pool->max_pages_allocated < pool->pages_allocated) > + pool->max_pages_allocated = pool->pages_allocated; > spin_unlock(&pool->stat_lock); > spin_lock(&class->lock); > } > @@ -1101,6 +1104,9 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) > } > EXPORT_SYMBOL_GPL(zs_unmap_object); > > +/* > + * Reports current memory usage consumed by zs_malloc > + */ > u64 zs_get_total_size_bytes(struct zs_pool *pool) > { > u64 npages; > @@ -1112,6 +1118,20 @@ u64 zs_get_total_size_bytes(struct zs_pool *pool) > } > EXPORT_SYMBOL_GPL(zs_get_total_size_bytes); > > +/* > + * Reports maximum memory usage zs_malloc have consumed > + */ > +u64 zs_get_max_size_bytes(struct zs_pool *pool) > +{ > + u64 npages; > + > + spin_lock(&pool->stat_lock); > + npages = pool->max_pages_allocated; > + spin_unlock(&pool->stat_lock); > + return npages << PAGE_SHIFT; > +} > +EXPORT_SYMBOL_GPL(zs_get_max_size_bytes); > + > module_init(zs_init); > module_exit(zs_exit); > > -- > 2.0.0 > > -- > 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> -- 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:[~2014-08-13 15:25 UTC|newest] Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-08-05 8:02 [RFC 0/3] zram memory control enhance Minchan Kim 2014-08-05 8:02 ` Minchan Kim 2014-08-05 8:02 ` [RFC 1/3] zsmalloc: move pages_allocated to zs_pool Minchan Kim 2014-08-05 8:02 ` Minchan Kim 2014-08-13 13:59 ` Dan Streetman 2014-08-13 13:59 ` Dan Streetman 2014-08-13 14:14 ` Sergey Senozhatsky 2014-08-13 14:14 ` Sergey Senozhatsky 2014-08-13 14:51 ` Dan Streetman 2014-08-13 14:51 ` Dan Streetman 2014-08-13 15:13 ` Sergey Senozhatsky 2014-08-13 15:13 ` Sergey Senozhatsky 2014-08-13 15:25 ` Sergey Senozhatsky 2014-08-13 15:25 ` Sergey Senozhatsky 2014-08-13 16:11 ` Dan Streetman 2014-08-13 16:11 ` Dan Streetman 2014-08-14 13:03 ` Sergey Senozhatsky 2014-08-14 13:03 ` Sergey Senozhatsky 2014-08-14 0:09 ` Minchan Kim 2014-08-14 0:09 ` Minchan Kim 2014-08-13 15:21 ` Seth Jennings 2014-08-13 15:21 ` Seth Jennings 2014-08-05 8:02 ` [RFC 2/3] zsmalloc/zram: add zs_get_max_size_bytes and use it in zram Minchan Kim 2014-08-05 8:02 ` Minchan Kim 2014-08-13 15:25 ` Seth Jennings [this message] 2014-08-13 15:25 ` Seth Jennings 2014-08-05 8:02 ` [RFC 3/3] zram: limit memory size for zram Minchan Kim 2014-08-05 8:02 ` Minchan Kim 2014-08-05 9:48 ` Minchan Kim 2014-08-05 9:48 ` Minchan Kim 2014-08-05 13:16 ` Sergey Senozhatsky 2014-08-05 13:16 ` Sergey Senozhatsky 2014-08-06 6:52 ` Minchan Kim 2014-08-06 6:52 ` Minchan Kim 2014-08-13 15:30 ` Seth Jennings 2014-08-13 15:30 ` Seth Jennings 2014-08-13 23:31 ` Minchan Kim 2014-08-13 23:31 ` Minchan Kim 2014-08-13 23:27 ` Minchan Kim 2014-08-13 23:27 ` Minchan Kim 2014-08-14 13:29 ` Sergey Senozhatsky 2014-08-14 13:29 ` Sergey Senozhatsky 2014-08-17 23:32 ` Minchan Kim 2014-08-17 23:32 ` Minchan Kim 2014-08-14 14:45 ` Dan Streetman 2014-08-14 14:45 ` Dan Streetman 2014-08-06 12:54 ` [RFC 0/3] zram memory control enhance Jerome Marchand 2014-08-13 15:34 ` Seth Jennings 2014-08-13 15:34 ` Seth Jennings 2014-08-13 23:32 ` Minchan Kim 2014-08-13 23:32 ` Minchan Kim 2014-08-08 2:47 [RFC 2/3] zsmalloc/zram: add zs_get_max_size_bytes and use it in zram David Horner 2014-08-08 2:56 David Horner 2014-08-12 7:18 ` 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=20140813152502.GB2768@cerebellum.variantweb.net \ --to=sjennings@variantweb.net \ --cc=jmarchan@redhat.com \ --cc=juno.choi@lge.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=minchan@kernel.org \ --cc=ngupta@vflare.org \ --cc=semenzato@google.com \ --cc=sergey.senozhatsky@gmail.com \ --cc=seungho1.park@lge.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.