* [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool @ 2014-08-14 0:57 Minchan Kim 2014-08-14 0:57 ` [PATCH 2/2] zram: limit memory size for zram Minchan Kim 2014-08-14 1:14 ` [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool Minchan Kim 0 siblings, 2 replies; 5+ messages in thread From: Minchan Kim @ 2014-08-14 0:57 UTC (permalink / raw) To: Andrew Morton Cc: linux-mm, linux-kernel, Sergey Senozhatsky, Jerome Marchand, juno.choi, seungho1.park, Luigi Semenzato, Nitin Gupta, Seth Jennings, Dan Streetman, ds2horner, Minchan Kim Pages_allocated has counted in size_class structure and when user want to see total_size_bytes, it gathers all of value from each size_class to report the sum. It's not bad if user don't see the value often but if user start to see the value frequently, it would be not a good deal for performance POV. Even, this patch moves the variable from size_class to zs_pool so it reduces memory footprint (from [255 * 8byte] to [sizeof(atomic_t)]) but it introduce new atomic opearation but it's not a big deal because atomic operation is called on slow path of zsmalloc where it allocates/free zspage unit, not object. Signed-off-by: Minchan Kim <minchan@kernel.org> --- mm/zsmalloc.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 4e2fc83cb394..2f21ea8921dc 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -199,9 +199,6 @@ struct size_class { spinlock_t lock; - /* stats */ - u64 pages_allocated; - struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS]; }; @@ -220,6 +217,7 @@ struct zs_pool { struct size_class size_class[ZS_SIZE_CLASSES]; gfp_t flags; /* allocation flags used when growing pool */ + atomic_t pages_allocated; }; /* @@ -1027,8 +1025,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size) return 0; set_zspage_mapping(first_page, class->index, ZS_EMPTY); + atomic_add(class->pages_per_zspage, &pool->pages_allocated); spin_lock(&class->lock); - class->pages_allocated += class->pages_per_zspage; } obj = (unsigned long)first_page->freelist; @@ -1081,14 +1079,12 @@ void zs_free(struct zs_pool *pool, unsigned long obj) first_page->inuse--; fullness = fix_fullness_group(pool, first_page); - - if (fullness == ZS_EMPTY) - class->pages_allocated -= class->pages_per_zspage; - spin_unlock(&class->lock); - if (fullness == ZS_EMPTY) + if (fullness == ZS_EMPTY) { + atomic_sub(class->pages_per_zspage, &pool->pages_allocated); free_zspage(first_page); + } } EXPORT_SYMBOL_GPL(zs_free); @@ -1184,12 +1180,9 @@ EXPORT_SYMBOL_GPL(zs_unmap_object); u64 zs_get_total_size_bytes(struct zs_pool *pool) { - int i; - u64 npages = 0; - - for (i = 0; i < ZS_SIZE_CLASSES; i++) - npages += pool->size_class[i].pages_allocated; + u64 npages; + npages = atomic_read(&pool->pages_allocated); return npages << PAGE_SHIFT; } EXPORT_SYMBOL_GPL(zs_get_total_size_bytes); -- 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> ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] zram: limit memory size for zram 2014-08-14 0:57 [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool Minchan Kim @ 2014-08-14 0:57 ` Minchan Kim 2014-08-14 14:33 ` Dan Streetman 2014-08-14 1:14 ` [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool Minchan Kim 1 sibling, 1 reply; 5+ messages in thread From: Minchan Kim @ 2014-08-14 0:57 UTC (permalink / raw) To: Andrew Morton Cc: linux-mm, linux-kernel, Sergey Senozhatsky, Jerome Marchand, juno.choi, seungho1.park, Luigi Semenzato, Nitin Gupta, Seth Jennings, Dan Streetman, ds2horner, Minchan Kim Since zram has no control feature to limit memory usage, it makes hard to manage system memrory. This patch adds new knob "mem_limit" via sysfs to set up the limit. Note: I added the logic in zram, not zsmalloc because the limit is requirement of zram, not zsmalloc so I'd like to avoid unnecessary branch in zsmalloc. Signed-off-by: Minchan Kim <minchan@kernel.org> --- Documentation/blockdev/zram.txt | 20 +++++++++++++++---- drivers/block/zram/zram_drv.c | 43 +++++++++++++++++++++++++++++++++++++++++ drivers/block/zram/zram_drv.h | 1 + 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt index 0595c3f56ccf..9f239ff8c444 100644 --- a/Documentation/blockdev/zram.txt +++ b/Documentation/blockdev/zram.txt @@ -74,14 +74,26 @@ There is little point creating a zram of greater than twice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the size of the disk when not in use so a huge zram is wasteful. -5) Activate: +5) Set memory limit: Optional + Set memory limit by writing the value to sysfs node 'mem_limit'. + The value can be either in bytes or you can use mem suffixes. + Examples: + # limit /dev/zram0 with 50MB memory + echo $((50*1024*1024)) > /sys/block/zram0/mem_limit + + # Using mem suffixes + echo 256K > /sys/block/zram0/mem_limit + echo 512M > /sys/block/zram0/mem_limit + echo 1G > /sys/block/zram0/mem_limit + +6) Activate: mkswap /dev/zram0 swapon /dev/zram0 mkfs.ext4 /dev/zram1 mount /dev/zram1 /tmp -6) Stats: +7) Stats: Per-device statistics are exported as various nodes under /sys/block/zram<id>/ disksize @@ -96,11 +108,11 @@ size of the disk when not in use so a huge zram is wasteful. compr_data_size mem_used_total -7) Deactivate: +8) Deactivate: swapoff /dev/zram0 umount /dev/zram1 -8) Reset: +9) Reset: Write any positive value to 'reset' sysfs node echo 1 > /sys/block/zram0/reset echo 1 > /sys/block/zram1/reset diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d00831c3d731..b48a3d0e9031 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -122,6 +122,35 @@ static ssize_t max_comp_streams_show(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%d\n", val); } +static ssize_t mem_limit_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u64 val; + struct zram *zram = dev_to_zram(dev); + + down_read(&zram->init_lock); + val = zram->limit_bytes; + up_read(&zram->init_lock); + + return scnprintf(buf, PAGE_SIZE, "%llu\n", val); +} + +static ssize_t mem_limit_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + u64 limit; + struct zram *zram = dev_to_zram(dev); + + limit = memparse(buf, NULL); + if (!limit) + return -EINVAL; + + down_write(&zram->init_lock); + zram->limit_bytes = limit; + up_write(&zram->init_lock); + return len; +} + static ssize_t max_comp_streams_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -513,6 +542,14 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, ret = -ENOMEM; goto out; } + + if (zram->limit_bytes && + zs_get_total_size_bytes(meta->mem_pool) > zram->limit_bytes) { + zs_free(meta->mem_pool, handle); + ret = -ENOMEM; + goto out; + } + cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO); if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) { @@ -617,6 +654,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) struct zram_meta *meta; down_write(&zram->init_lock); + + zram->limit_bytes = 0; + if (!init_done(zram)) { up_write(&zram->init_lock); return; @@ -857,6 +897,8 @@ 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_limit, S_IRUGO | S_IWUSR, mem_limit_show, + mem_limit_store); 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, @@ -885,6 +927,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_limit.attr, &dev_attr_max_comp_streams.attr, &dev_attr_comp_algorithm.attr, NULL, diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index e0f725c87cc6..086c51782e75 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -110,6 +110,7 @@ struct zram { * we can store in a disk. */ u64 disksize; /* bytes */ + u64 limit_bytes; int max_comp_streams; struct zram_stats stats; char compressor[10]; -- 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> ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] zram: limit memory size for zram 2014-08-14 0:57 ` [PATCH 2/2] zram: limit memory size for zram Minchan Kim @ 2014-08-14 14:33 ` Dan Streetman 2014-08-17 23:22 ` Minchan Kim 0 siblings, 1 reply; 5+ messages in thread From: Dan Streetman @ 2014-08-14 14:33 UTC (permalink / raw) To: Minchan Kim Cc: Andrew Morton, Linux-MM, linux-kernel, Sergey Senozhatsky, Jerome Marchand, juno.choi, seungho1.park, Luigi Semenzato, Nitin Gupta, Seth Jennings, ds2horner On Wed, Aug 13, 2014 at 8:57 PM, Minchan Kim <minchan@kernel.org> wrote: > Since zram has no control feature to limit memory usage, > it makes hard to manage system memrory. > > This patch adds new knob "mem_limit" via sysfs to set up the > limit. > > Note: I added the logic in zram, not zsmalloc because the limit > is requirement of zram, not zsmalloc so I'd like to avoid > unnecessary branch in zsmalloc. > > Signed-off-by: Minchan Kim <minchan@kernel.org> > --- > Documentation/blockdev/zram.txt | 20 +++++++++++++++---- > drivers/block/zram/zram_drv.c | 43 +++++++++++++++++++++++++++++++++++++++++ > drivers/block/zram/zram_drv.h | 1 + > 3 files changed, 60 insertions(+), 4 deletions(-) > > diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt > index 0595c3f56ccf..9f239ff8c444 100644 > --- a/Documentation/blockdev/zram.txt > +++ b/Documentation/blockdev/zram.txt > @@ -74,14 +74,26 @@ There is little point creating a zram of greater than twice the size of memory > since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the > size of the disk when not in use so a huge zram is wasteful. > > -5) Activate: > +5) Set memory limit: Optional > + Set memory limit by writing the value to sysfs node 'mem_limit'. > + The value can be either in bytes or you can use mem suffixes. > + Examples: > + # limit /dev/zram0 with 50MB memory > + echo $((50*1024*1024)) > /sys/block/zram0/mem_limit > + > + # Using mem suffixes > + echo 256K > /sys/block/zram0/mem_limit > + echo 512M > /sys/block/zram0/mem_limit > + echo 1G > /sys/block/zram0/mem_limit > + > +6) Activate: > mkswap /dev/zram0 > swapon /dev/zram0 > > mkfs.ext4 /dev/zram1 > mount /dev/zram1 /tmp > > -6) Stats: > +7) Stats: > Per-device statistics are exported as various nodes under > /sys/block/zram<id>/ > disksize > @@ -96,11 +108,11 @@ size of the disk when not in use so a huge zram is wasteful. > compr_data_size > mem_used_total > > -7) Deactivate: > +8) Deactivate: > swapoff /dev/zram0 > umount /dev/zram1 > > -8) Reset: > +9) Reset: > Write any positive value to 'reset' sysfs node > echo 1 > /sys/block/zram0/reset > echo 1 > /sys/block/zram1/reset > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index d00831c3d731..b48a3d0e9031 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -122,6 +122,35 @@ static ssize_t max_comp_streams_show(struct device *dev, > return scnprintf(buf, PAGE_SIZE, "%d\n", val); > } > > +static ssize_t mem_limit_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + u64 val; > + struct zram *zram = dev_to_zram(dev); > + > + down_read(&zram->init_lock); > + val = zram->limit_bytes; > + up_read(&zram->init_lock); > + > + return scnprintf(buf, PAGE_SIZE, "%llu\n", val); > +} > + > +static ssize_t mem_limit_store(struct device *dev, > + struct device_attribute *attr, const char *buf, size_t len) > +{ > + u64 limit; > + struct zram *zram = dev_to_zram(dev); > + > + limit = memparse(buf, NULL); > + if (!limit) > + return -EINVAL; Shouldn't passing a 0 limit be allowed, to disable the limit? > + > + down_write(&zram->init_lock); > + zram->limit_bytes = limit; > + up_write(&zram->init_lock); > + return len; > +} > + > static ssize_t max_comp_streams_store(struct device *dev, > struct device_attribute *attr, const char *buf, size_t len) > { > @@ -513,6 +542,14 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, > ret = -ENOMEM; > goto out; > } > + > + if (zram->limit_bytes && > + zs_get_total_size_bytes(meta->mem_pool) > zram->limit_bytes) { > + zs_free(meta->mem_pool, handle); > + ret = -ENOMEM; > + goto out; > + } > + > cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO); > > if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) { > @@ -617,6 +654,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) > struct zram_meta *meta; > > down_write(&zram->init_lock); > + > + zram->limit_bytes = 0; > + > if (!init_done(zram)) { > up_write(&zram->init_lock); > return; > @@ -857,6 +897,8 @@ 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_limit, S_IRUGO | S_IWUSR, mem_limit_show, > + mem_limit_store); > 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, > @@ -885,6 +927,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_limit.attr, > &dev_attr_max_comp_streams.attr, > &dev_attr_comp_algorithm.attr, > NULL, > diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h > index e0f725c87cc6..086c51782e75 100644 > --- a/drivers/block/zram/zram_drv.h > +++ b/drivers/block/zram/zram_drv.h > @@ -110,6 +110,7 @@ struct zram { > * we can store in a disk. > */ > u64 disksize; /* bytes */ > + u64 limit_bytes; > int max_comp_streams; > struct zram_stats stats; > char compressor[10]; > -- > 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> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] zram: limit memory size for zram 2014-08-14 14:33 ` Dan Streetman @ 2014-08-17 23:22 ` Minchan Kim 0 siblings, 0 replies; 5+ messages in thread From: Minchan Kim @ 2014-08-17 23:22 UTC (permalink / raw) To: Dan Streetman Cc: Andrew Morton, Linux-MM, linux-kernel, Sergey Senozhatsky, Jerome Marchand, juno.choi, seungho1.park, Luigi Semenzato, Nitin Gupta, Seth Jennings, ds2horner Hi Dan, On Thu, Aug 14, 2014 at 10:33:29AM -0400, Dan Streetman wrote: > On Wed, Aug 13, 2014 at 8:57 PM, Minchan Kim <minchan@kernel.org> wrote: > > Since zram has no control feature to limit memory usage, > > it makes hard to manage system memrory. > > > > This patch adds new knob "mem_limit" via sysfs to set up the > > limit. > > > > Note: I added the logic in zram, not zsmalloc because the limit > > is requirement of zram, not zsmalloc so I'd like to avoid > > unnecessary branch in zsmalloc. > > > > Signed-off-by: Minchan Kim <minchan@kernel.org> > > --- > > Documentation/blockdev/zram.txt | 20 +++++++++++++++---- > > drivers/block/zram/zram_drv.c | 43 +++++++++++++++++++++++++++++++++++++++++ > > drivers/block/zram/zram_drv.h | 1 + > > 3 files changed, 60 insertions(+), 4 deletions(-) > > > > diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt > > index 0595c3f56ccf..9f239ff8c444 100644 > > --- a/Documentation/blockdev/zram.txt > > +++ b/Documentation/blockdev/zram.txt > > @@ -74,14 +74,26 @@ There is little point creating a zram of greater than twice the size of memory > > since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the > > size of the disk when not in use so a huge zram is wasteful. > > > > -5) Activate: > > +5) Set memory limit: Optional > > + Set memory limit by writing the value to sysfs node 'mem_limit'. > > + The value can be either in bytes or you can use mem suffixes. > > + Examples: > > + # limit /dev/zram0 with 50MB memory > > + echo $((50*1024*1024)) > /sys/block/zram0/mem_limit > > + > > + # Using mem suffixes > > + echo 256K > /sys/block/zram0/mem_limit > > + echo 512M > /sys/block/zram0/mem_limit > > + echo 1G > /sys/block/zram0/mem_limit > > + > > +6) Activate: > > mkswap /dev/zram0 > > swapon /dev/zram0 > > > > mkfs.ext4 /dev/zram1 > > mount /dev/zram1 /tmp > > > > -6) Stats: > > +7) Stats: > > Per-device statistics are exported as various nodes under > > /sys/block/zram<id>/ > > disksize > > @@ -96,11 +108,11 @@ size of the disk when not in use so a huge zram is wasteful. > > compr_data_size > > mem_used_total > > > > -7) Deactivate: > > +8) Deactivate: > > swapoff /dev/zram0 > > umount /dev/zram1 > > > > -8) Reset: > > +9) Reset: > > Write any positive value to 'reset' sysfs node > > echo 1 > /sys/block/zram0/reset > > echo 1 > /sys/block/zram1/reset > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > > index d00831c3d731..b48a3d0e9031 100644 > > --- a/drivers/block/zram/zram_drv.c > > +++ b/drivers/block/zram/zram_drv.c > > @@ -122,6 +122,35 @@ static ssize_t max_comp_streams_show(struct device *dev, > > return scnprintf(buf, PAGE_SIZE, "%d\n", val); > > } > > > > +static ssize_t mem_limit_show(struct device *dev, > > + struct device_attribute *attr, char *buf) > > +{ > > + u64 val; > > + struct zram *zram = dev_to_zram(dev); > > + > > + down_read(&zram->init_lock); > > + val = zram->limit_bytes; > > + up_read(&zram->init_lock); > > + > > + return scnprintf(buf, PAGE_SIZE, "%llu\n", val); > > +} > > + > > +static ssize_t mem_limit_store(struct device *dev, > > + struct device_attribute *attr, const char *buf, size_t len) > > +{ > > + u64 limit; > > + struct zram *zram = dev_to_zram(dev); > > + > > + limit = memparse(buf, NULL); > > + if (!limit) > > + return -EINVAL; > > Shouldn't passing a 0 limit be allowed, to disable the limit? Sure. Will fix. Thanks. -- Kind regards, Minchan Kim -- 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> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool 2014-08-14 0:57 [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool Minchan Kim 2014-08-14 0:57 ` [PATCH 2/2] zram: limit memory size for zram Minchan Kim @ 2014-08-14 1:14 ` Minchan Kim 1 sibling, 0 replies; 5+ messages in thread From: Minchan Kim @ 2014-08-14 1:14 UTC (permalink / raw) To: Andrew Morton Cc: Seth Jennings, Jerome Marchand, Sergey Senozhatsky, juno.choi, linux-kernel, linux-mm, Dan Streetman, seungho1.park, Luigi Semenzato, ds2horner, Nitin Gupta Just resent new one with correcting Seth's mail address and including the one omitted by mistake in this patchset. On Thu, Aug 14, 2014 at 09:57:56AM +0900, Minchan Kim wrote: > Pages_allocated has counted in size_class structure and when user > want to see total_size_bytes, it gathers all of value from each > size_class to report the sum. > > It's not bad if user don't see the value often but if user start > to see the value frequently, it would be not a good deal for > performance POV. > > Even, this patch moves the variable from size_class to zs_pool > so it reduces memory footprint (from [255 * 8byte] to > [sizeof(atomic_t)]) but it introduce new atomic opearation > but it's not a big deal because atomic operation is called on > slow path of zsmalloc where it allocates/free zspage unit, > not object. > > Signed-off-by: Minchan Kim <minchan@kernel.org> > --- > mm/zsmalloc.c | 21 +++++++-------------- > 1 file changed, 7 insertions(+), 14 deletions(-) > > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index 4e2fc83cb394..2f21ea8921dc 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -199,9 +199,6 @@ struct size_class { > > spinlock_t lock; > > - /* stats */ > - u64 pages_allocated; > - > struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS]; > }; > > @@ -220,6 +217,7 @@ struct zs_pool { > struct size_class size_class[ZS_SIZE_CLASSES]; > > gfp_t flags; /* allocation flags used when growing pool */ > + atomic_t pages_allocated; > }; > > /* > @@ -1027,8 +1025,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size) > return 0; > > set_zspage_mapping(first_page, class->index, ZS_EMPTY); > + atomic_add(class->pages_per_zspage, &pool->pages_allocated); > spin_lock(&class->lock); > - class->pages_allocated += class->pages_per_zspage; > } > > obj = (unsigned long)first_page->freelist; > @@ -1081,14 +1079,12 @@ void zs_free(struct zs_pool *pool, unsigned long obj) > > first_page->inuse--; > fullness = fix_fullness_group(pool, first_page); > - > - if (fullness == ZS_EMPTY) > - class->pages_allocated -= class->pages_per_zspage; > - > spin_unlock(&class->lock); > > - if (fullness == ZS_EMPTY) > + if (fullness == ZS_EMPTY) { > + atomic_sub(class->pages_per_zspage, &pool->pages_allocated); > free_zspage(first_page); > + } > } > EXPORT_SYMBOL_GPL(zs_free); > > @@ -1184,12 +1180,9 @@ EXPORT_SYMBOL_GPL(zs_unmap_object); > > u64 zs_get_total_size_bytes(struct zs_pool *pool) > { > - int i; > - u64 npages = 0; > - > - for (i = 0; i < ZS_SIZE_CLASSES; i++) > - npages += pool->size_class[i].pages_allocated; > + u64 npages; > > + npages = atomic_read(&pool->pages_allocated); > return npages << PAGE_SHIFT; > } > EXPORT_SYMBOL_GPL(zs_get_total_size_bytes); > -- > 2.0.0 -- Kind regards, Minchan Kim -- 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> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-08-17 23:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-08-14 0:57 [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool Minchan Kim 2014-08-14 0:57 ` [PATCH 2/2] zram: limit memory size for zram Minchan Kim 2014-08-14 14:33 ` Dan Streetman 2014-08-17 23:22 ` Minchan Kim 2014-08-14 1:14 ` [PATCH 1/2] zsmalloc: move pages_allocated to zs_pool Minchan Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).