Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3eba0c6a authored by Ganesh Mahendran's avatar Ganesh Mahendran Committed by Linus Torvalds
Browse files

mm/zpool: add name argument to create zpool



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: default avatarGanesh Mahendran <opensource.ganesh@gmail.com>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: Seth Jennings <sjennings@variantweb.net>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ee980160
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -327,9 +327,10 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
	kfree(meta);
	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;
	size_t num_pages;
	char pool_name[8];
	struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
	struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);


	if (!meta)
	if (!meta)
@@ -342,7 +343,8 @@ static struct zram_meta *zram_meta_alloc(u64 disksize)
		goto out_error;
		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) {
	if (!meta->mem_pool) {
		pr_err("Error creating memory pool\n");
		pr_err("Error creating memory pool\n");
		goto out_error;
		goto out_error;
@@ -783,7 +785,7 @@ static ssize_t disksize_store(struct device *dev,
		return -EINVAL;
		return -EINVAL;


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


+3 −2
Original line number Original line Diff line number Diff line
@@ -36,7 +36,8 @@ enum zpool_mapmode {
	ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
	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);
char *zpool_get_type(struct zpool *pool);


@@ -80,7 +81,7 @@ struct zpool_driver {
	atomic_t refcount;
	atomic_t refcount;
	struct list_head list;
	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);
	void (*destroy)(void *pool);


	int (*malloc)(void *pool, size_t size, gfp_t gfp,
	int (*malloc)(void *pool, size_t size, gfp_t gfp,
+1 −1
Original line number Original line Diff line number Diff line
@@ -36,7 +36,7 @@ enum zs_mapmode {


struct zs_pool;
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);
void zs_destroy_pool(struct zs_pool *pool);


unsigned long zs_malloc(struct zs_pool *pool, size_t size);
unsigned long zs_malloc(struct zs_pool *pool, size_t size);
+2 −1
Original line number Original line Diff line number Diff line
@@ -130,7 +130,8 @@ static struct zbud_ops zbud_zpool_ops = {
	.evict =	zbud_zpool_evict
	.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);
	return zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL);
}
}
+4 −2
Original line number Original line Diff line number Diff line
@@ -129,6 +129,7 @@ static void zpool_put_driver(struct zpool_driver *driver)
/**
/**
 * zpool_create_pool() - Create a new zpool
 * zpool_create_pool() - Create a new zpool
 * @type	The type of the zpool to create (e.g. zbud, zsmalloc)
 * @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.
 * @gfp		The GFP flags to use when allocating the pool.
 * @ops		The optional ops callback.
 * @ops		The optional ops callback.
 *
 *
@@ -140,7 +141,8 @@ static void zpool_put_driver(struct zpool_driver *driver)
 *
 *
 * Returns: New zpool on success, NULL on failure.
 * 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_driver *driver;
	struct zpool *zpool;
	struct zpool *zpool;
@@ -168,7 +170,7 @@ struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops)


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


	if (!zpool->pool) {
	if (!zpool->pool) {
Loading