Skip to content

Commit

Permalink
zsmalloc: change return value unit of zs_get_total_size_bytes
Browse files Browse the repository at this point in the history
zs_get_total_size_bytes returns a amount of memory zsmalloc consumed with
*byte unit* but zsmalloc operates *page unit* rather than byte unit so
let's change the API so benefit we could get is that reduce unnecessary
overhead (ie, change page unit with byte unit) in zsmalloc.

Since return type is pages, "zs_get_total_pages" is better than
"zs_get_total_size_bytes".

Signed-off-by: Minchan Kim <[email protected]>
Reviewed-by: Dan Streetman <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Jerome Marchand <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: Luigi Semenzato <[email protected]>
Cc: Nitin Gupta <[email protected]>
Cc: Seth Jennings <[email protected]>
Cc: David Horner <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
minchank authored and torvalds committed Oct 10, 2014
1 parent 13de893 commit 722cdc1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ static ssize_t mem_used_total_show(struct device *dev,

down_read(&zram->init_lock);
if (init_done(zram))
val = zs_get_total_size_bytes(meta->mem_pool);
val = zs_get_total_pages(meta->mem_pool);
up_read(&zram->init_lock);

return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
return scnprintf(buf, PAGE_SIZE, "%llu\n", val << PAGE_SHIFT);
}

static ssize_t max_comp_streams_show(struct device *dev,
Expand Down
2 changes: 1 addition & 1 deletion include/linux/zsmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle,
enum zs_mapmode mm);
void zs_unmap_object(struct zs_pool *pool, unsigned long handle);

u64 zs_get_total_size_bytes(struct zs_pool *pool);
unsigned long zs_get_total_pages(struct zs_pool *pool);

#endif
9 changes: 4 additions & 5 deletions mm/zsmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static void zs_zpool_unmap(void *pool, unsigned long handle)

static u64 zs_zpool_total_size(void *pool)
{
return zs_get_total_size_bytes(pool);
return zs_get_total_pages(pool) << PAGE_SHIFT;
}

static struct zpool_driver zs_zpool_driver = {
Expand Down Expand Up @@ -1181,12 +1181,11 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle)
}
EXPORT_SYMBOL_GPL(zs_unmap_object);

u64 zs_get_total_size_bytes(struct zs_pool *pool)
unsigned long zs_get_total_pages(struct zs_pool *pool)
{
u64 npages = atomic_long_read(&pool->pages_allocated);
return npages << PAGE_SHIFT;
return atomic_long_read(&pool->pages_allocated);
}
EXPORT_SYMBOL_GPL(zs_get_total_size_bytes);
EXPORT_SYMBOL_GPL(zs_get_total_pages);

module_init(zs_init);
module_exit(zs_exit);
Expand Down

0 comments on commit 722cdc1

Please sign in to comment.