Skip to content

Commit

Permalink
mm/zpool: add name argument to create zpool
Browse files Browse the repository at this point in the history
Currently the underlay of zpool: zsmalloc/zbud, do not know who creates
them.  There is not a method to let zsmalloc/zbud find which caller they
belong to.

Now we want to add statistics collection in zsmalloc.  We need to name the
debugfs dir for each pool created.  The way suggested by Minchan Kim is to
use a name passed by caller(such as zram) to create the zsmalloc pool.

    /sys/kernel/debug/zsmalloc/zram0

This patch adds an argument `name' to zs_create_pool() and other related
functions.

Signed-off-by: Ganesh Mahendran <[email protected]>
Acked-by: Minchan Kim <[email protected]>
Cc: Seth Jennings <[email protected]>
Cc: Nitin Gupta <[email protected]>
Cc: Dan Streetman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
yzkqfll authored and torvalds committed Feb 13, 2015
1 parent ee98016 commit 3eba0c6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
8 changes: 5 additions & 3 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,10 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
kfree(meta);
}

static struct zram_meta *zram_meta_alloc(u64 disksize)
static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
{
size_t num_pages;
char pool_name[8];
struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);

if (!meta)
Expand All @@ -342,7 +343,8 @@ static struct zram_meta *zram_meta_alloc(u64 disksize)
goto out_error;
}

meta->mem_pool = zs_create_pool(GFP_NOIO | __GFP_HIGHMEM);
snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
if (!meta->mem_pool) {
pr_err("Error creating memory pool\n");
goto out_error;
Expand Down Expand Up @@ -783,7 +785,7 @@ static ssize_t disksize_store(struct device *dev,
return -EINVAL;

disksize = PAGE_ALIGN(disksize);
meta = zram_meta_alloc(disksize);
meta = zram_meta_alloc(zram->disk->first_minor, disksize);
if (!meta)
return -ENOMEM;

Expand Down
5 changes: 3 additions & 2 deletions include/linux/zpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ enum zpool_mapmode {
ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
};

struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops);
struct zpool *zpool_create_pool(char *type, char *name,
gfp_t gfp, struct zpool_ops *ops);

char *zpool_get_type(struct zpool *pool);

Expand Down Expand Up @@ -80,7 +81,7 @@ struct zpool_driver {
atomic_t refcount;
struct list_head list;

void *(*create)(gfp_t gfp, struct zpool_ops *ops);
void *(*create)(char *name, gfp_t gfp, struct zpool_ops *ops);
void (*destroy)(void *pool);

int (*malloc)(void *pool, size_t size, gfp_t gfp,
Expand Down
2 changes: 1 addition & 1 deletion include/linux/zsmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum zs_mapmode {

struct zs_pool;

struct zs_pool *zs_create_pool(gfp_t flags);
struct zs_pool *zs_create_pool(char *name, gfp_t flags);
void zs_destroy_pool(struct zs_pool *pool);

unsigned long zs_malloc(struct zs_pool *pool, size_t size);
Expand Down
3 changes: 2 additions & 1 deletion mm/zbud.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static struct zbud_ops zbud_zpool_ops = {
.evict = zbud_zpool_evict
};

static void *zbud_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops)
static void *zbud_zpool_create(char *name, gfp_t gfp,
struct zpool_ops *zpool_ops)
{
return zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL);
}
Expand Down
6 changes: 4 additions & 2 deletions mm/zpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ static void zpool_put_driver(struct zpool_driver *driver)
/**
* zpool_create_pool() - Create a new zpool
* @type The type of the zpool to create (e.g. zbud, zsmalloc)
* @name The name of the zpool (e.g. zram0, zswap)
* @gfp The GFP flags to use when allocating the pool.
* @ops The optional ops callback.
*
Expand All @@ -140,7 +141,8 @@ static void zpool_put_driver(struct zpool_driver *driver)
*
* Returns: New zpool on success, NULL on failure.
*/
struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops)
struct zpool *zpool_create_pool(char *type, char *name, gfp_t gfp,
struct zpool_ops *ops)
{
struct zpool_driver *driver;
struct zpool *zpool;
Expand Down Expand Up @@ -168,7 +170,7 @@ struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops)

zpool->type = driver->type;
zpool->driver = driver;
zpool->pool = driver->create(gfp, ops);
zpool->pool = driver->create(name, gfp, ops);
zpool->ops = ops;

if (!zpool->pool) {
Expand Down
6 changes: 3 additions & 3 deletions mm/zsmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ struct mapping_area {

#ifdef CONFIG_ZPOOL

static void *zs_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops)
static void *zs_zpool_create(char *name, gfp_t gfp, struct zpool_ops *zpool_ops)
{
return zs_create_pool(gfp);
return zs_create_pool(name, gfp);
}

static void zs_zpool_destroy(void *pool)
Expand Down Expand Up @@ -1148,7 +1148,7 @@ EXPORT_SYMBOL_GPL(zs_free);
* On success, a pointer to the newly created pool is returned,
* otherwise NULL.
*/
struct zs_pool *zs_create_pool(gfp_t flags)
struct zs_pool *zs_create_pool(char *name, gfp_t flags)
{
int i;
struct zs_pool *pool;
Expand Down
5 changes: 3 additions & 2 deletions mm/zswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,12 @@ static int __init init_zswap(void)

pr_info("loading zswap\n");

zswap_pool = zpool_create_pool(zswap_zpool_type, gfp, &zswap_zpool_ops);
zswap_pool = zpool_create_pool(zswap_zpool_type, "zswap", gfp,
&zswap_zpool_ops);
if (!zswap_pool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) {
pr_info("%s zpool not available\n", zswap_zpool_type);
zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
zswap_pool = zpool_create_pool(zswap_zpool_type, gfp,
zswap_pool = zpool_create_pool(zswap_zpool_type, "zswap", gfp,
&zswap_zpool_ops);
}
if (!zswap_pool) {
Expand Down

0 comments on commit 3eba0c6

Please sign in to comment.