aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGanesh Mahendran <opensource.ganesh@gmail.com>2015-02-12 18:00:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-12 21:54:12 -0500
commit3eba0c6a56c04f2b017b43641a821f1ebfb7fb4c (patch)
treeae8732c7012ccee1573769e2a686eb98df173bca
parentee98016010ae036a5b27300d83bd99ef3fd5776e (diff)
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: Ganesh Mahendran <opensource.ganesh@gmail.com> Acked-by: Minchan 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/block/zram/zram_drv.c8
-rw-r--r--include/linux/zpool.h5
-rw-r--r--include/linux/zsmalloc.h2
-rw-r--r--mm/zbud.c3
-rw-r--r--mm/zpool.c6
-rw-r--r--mm/zsmalloc.c6
-rw-r--r--mm/zswap.c5
7 files changed, 21 insertions, 14 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index eca4b67274c1..8e233edd7a09 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -327,9 +327,10 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
327 kfree(meta); 327 kfree(meta);
328} 328}
329 329
330static struct zram_meta *zram_meta_alloc(u64 disksize) 330static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
331{ 331{
332 size_t num_pages; 332 size_t num_pages;
333 char pool_name[8];
333 struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL); 334 struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
334 335
335 if (!meta) 336 if (!meta)
@@ -342,7 +343,8 @@ static struct zram_meta *zram_meta_alloc(u64 disksize)
342 goto out_error; 343 goto out_error;
343 } 344 }
344 345
345 meta->mem_pool = zs_create_pool(GFP_NOIO | __GFP_HIGHMEM); 346 snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
347 meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
346 if (!meta->mem_pool) { 348 if (!meta->mem_pool) {
347 pr_err("Error creating memory pool\n"); 349 pr_err("Error creating memory pool\n");
348 goto out_error; 350 goto out_error;
@@ -783,7 +785,7 @@ static ssize_t disksize_store(struct device *dev,
783 return -EINVAL; 785 return -EINVAL;
784 786
785 disksize = PAGE_ALIGN(disksize); 787 disksize = PAGE_ALIGN(disksize);
786 meta = zram_meta_alloc(disksize); 788 meta = zram_meta_alloc(zram->disk->first_minor, disksize);
787 if (!meta) 789 if (!meta)
788 return -ENOMEM; 790 return -ENOMEM;
789 791
diff --git a/include/linux/zpool.h b/include/linux/zpool.h
index f14bd75f08b3..56529b34dc63 100644
--- a/include/linux/zpool.h
+++ b/include/linux/zpool.h
@@ -36,7 +36,8 @@ enum zpool_mapmode {
36 ZPOOL_MM_DEFAULT = ZPOOL_MM_RW 36 ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
37}; 37};
38 38
39struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops); 39struct zpool *zpool_create_pool(char *type, char *name,
40 gfp_t gfp, struct zpool_ops *ops);
40 41
41char *zpool_get_type(struct zpool *pool); 42char *zpool_get_type(struct zpool *pool);
42 43
@@ -80,7 +81,7 @@ struct zpool_driver {
80 atomic_t refcount; 81 atomic_t refcount;
81 struct list_head list; 82 struct list_head list;
82 83
83 void *(*create)(gfp_t gfp, struct zpool_ops *ops); 84 void *(*create)(char *name, gfp_t gfp, struct zpool_ops *ops);
84 void (*destroy)(void *pool); 85 void (*destroy)(void *pool);
85 86
86 int (*malloc)(void *pool, size_t size, gfp_t gfp, 87 int (*malloc)(void *pool, size_t size, gfp_t gfp,
diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h
index 05c214760977..3283c6a55425 100644
--- a/include/linux/zsmalloc.h
+++ b/include/linux/zsmalloc.h
@@ -36,7 +36,7 @@ enum zs_mapmode {
36 36
37struct zs_pool; 37struct zs_pool;
38 38
39struct zs_pool *zs_create_pool(gfp_t flags); 39struct zs_pool *zs_create_pool(char *name, gfp_t flags);
40void zs_destroy_pool(struct zs_pool *pool); 40void zs_destroy_pool(struct zs_pool *pool);
41 41
42unsigned long zs_malloc(struct zs_pool *pool, size_t size); 42unsigned long zs_malloc(struct zs_pool *pool, size_t size);
diff --git a/mm/zbud.c b/mm/zbud.c
index 4e387bea702e..2ee4e4520493 100644
--- a/mm/zbud.c
+++ b/mm/zbud.c
@@ -130,7 +130,8 @@ static struct zbud_ops zbud_zpool_ops = {
130 .evict = zbud_zpool_evict 130 .evict = zbud_zpool_evict
131}; 131};
132 132
133static void *zbud_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops) 133static void *zbud_zpool_create(char *name, gfp_t gfp,
134 struct zpool_ops *zpool_ops)
134{ 135{
135 return zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL); 136 return zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL);
136} 137}
diff --git a/mm/zpool.c b/mm/zpool.c
index 739cdf0d183a..bacdab6e47de 100644
--- a/mm/zpool.c
+++ b/mm/zpool.c
@@ -129,6 +129,7 @@ static void zpool_put_driver(struct zpool_driver *driver)
129/** 129/**
130 * zpool_create_pool() - Create a new zpool 130 * zpool_create_pool() - Create a new zpool
131 * @type The type of the zpool to create (e.g. zbud, zsmalloc) 131 * @type The type of the zpool to create (e.g. zbud, zsmalloc)
132 * @name The name of the zpool (e.g. zram0, zswap)
132 * @gfp The GFP flags to use when allocating the pool. 133 * @gfp The GFP flags to use when allocating the pool.
133 * @ops The optional ops callback. 134 * @ops The optional ops callback.
134 * 135 *
@@ -140,7 +141,8 @@ static void zpool_put_driver(struct zpool_driver *driver)
140 * 141 *
141 * Returns: New zpool on success, NULL on failure. 142 * Returns: New zpool on success, NULL on failure.
142 */ 143 */
143struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops) 144struct zpool *zpool_create_pool(char *type, char *name, gfp_t gfp,
145 struct zpool_ops *ops)
144{ 146{
145 struct zpool_driver *driver; 147 struct zpool_driver *driver;
146 struct zpool *zpool; 148 struct zpool *zpool;
@@ -168,7 +170,7 @@ struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops)
168 170
169 zpool->type = driver->type; 171 zpool->type = driver->type;
170 zpool->driver = driver; 172 zpool->driver = driver;
171 zpool->pool = driver->create(gfp, ops); 173 zpool->pool = driver->create(name, gfp, ops);
172 zpool->ops = ops; 174 zpool->ops = ops;
173 175
174 if (!zpool->pool) { 176 if (!zpool->pool) {
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index b72403927aa4..2359e61b02bf 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -246,9 +246,9 @@ struct mapping_area {
246 246
247#ifdef CONFIG_ZPOOL 247#ifdef CONFIG_ZPOOL
248 248
249static void *zs_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops) 249static void *zs_zpool_create(char *name, gfp_t gfp, struct zpool_ops *zpool_ops)
250{ 250{
251 return zs_create_pool(gfp); 251 return zs_create_pool(name, gfp);
252} 252}
253 253
254static void zs_zpool_destroy(void *pool) 254static void zs_zpool_destroy(void *pool)
@@ -1148,7 +1148,7 @@ EXPORT_SYMBOL_GPL(zs_free);
1148 * On success, a pointer to the newly created pool is returned, 1148 * On success, a pointer to the newly created pool is returned,
1149 * otherwise NULL. 1149 * otherwise NULL.
1150 */ 1150 */
1151struct zs_pool *zs_create_pool(gfp_t flags) 1151struct zs_pool *zs_create_pool(char *name, gfp_t flags)
1152{ 1152{
1153 int i; 1153 int i;
1154 struct zs_pool *pool; 1154 struct zs_pool *pool;
diff --git a/mm/zswap.c b/mm/zswap.c
index 0cfce9bc51e4..4249e82ff934 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -906,11 +906,12 @@ static int __init init_zswap(void)
906 906
907 pr_info("loading zswap\n"); 907 pr_info("loading zswap\n");
908 908
909 zswap_pool = zpool_create_pool(zswap_zpool_type, gfp, &zswap_zpool_ops); 909 zswap_pool = zpool_create_pool(zswap_zpool_type, "zswap", gfp,
910 &zswap_zpool_ops);
910 if (!zswap_pool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) { 911 if (!zswap_pool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) {
911 pr_info("%s zpool not available\n", zswap_zpool_type); 912 pr_info("%s zpool not available\n", zswap_zpool_type);
912 zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT; 913 zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
913 zswap_pool = zpool_create_pool(zswap_zpool_type, gfp, 914 zswap_pool = zpool_create_pool(zswap_zpool_type, "zswap", gfp,
914 &zswap_zpool_ops); 915 &zswap_zpool_ops);
915 } 916 }
916 if (!zswap_pool) { 917 if (!zswap_pool) {