summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2016-05-05 19:22:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-05 20:38:53 -0400
commit32a4e169039927bfb6ee9f0ccbbe3a8aaf13a4bc (patch)
tree7b1ab68ce63b91cd828e103f827f0bc76b930b36
parent127393fbe597dd85863a9bdccaa11007e7d4948f (diff)
mm/zswap: provide unique zpool name
Instead of using "zswap" as the name for all zpools created, add an atomic counter and use "zswap%x" with the counter number for each zpool created, to provide a unique name for each new zpool. As zsmalloc, one of the zpool implementations, requires/expects a unique name for each pool created, zswap should provide a unique name. The zsmalloc pool creation does not fail if a new pool with a conflicting name is created, unless CONFIG_ZSMALLOC_STAT is enabled; in that case, zsmalloc pool creation fails with -ENOMEM. Then zswap will be unable to change its compressor parameter if its zpool is zsmalloc; it also will be unable to change its zpool parameter back to zsmalloc, if it has any existing old zpool using zsmalloc with page(s) in it. Attempts to change the parameters will result in failure to create the zpool. This changes zswap to provide a unique name for each zpool creation. Fixes: f1c54846ee45 ("zswap: dynamic pool creation") Signed-off-by: Dan Streetman <ddstreet@ieee.org> Reported-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Dan Streetman <dan.streetman@canonical.com> Cc: Minchan Kim <minchan@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/zswap.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/mm/zswap.c b/mm/zswap.c
index 91dad80d068b..de0f119b1780 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -170,6 +170,8 @@ static struct zswap_tree *zswap_trees[MAX_SWAPFILES];
170static LIST_HEAD(zswap_pools); 170static LIST_HEAD(zswap_pools);
171/* protects zswap_pools list modification */ 171/* protects zswap_pools list modification */
172static DEFINE_SPINLOCK(zswap_pools_lock); 172static DEFINE_SPINLOCK(zswap_pools_lock);
173/* pool counter to provide unique names to zpool */
174static atomic_t zswap_pools_count = ATOMIC_INIT(0);
173 175
174/* used by param callback function */ 176/* used by param callback function */
175static bool zswap_init_started; 177static bool zswap_init_started;
@@ -565,6 +567,7 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
565static struct zswap_pool *zswap_pool_create(char *type, char *compressor) 567static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
566{ 568{
567 struct zswap_pool *pool; 569 struct zswap_pool *pool;
570 char name[38]; /* 'zswap' + 32 char (max) num + \0 */
568 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; 571 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
569 572
570 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 573 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
@@ -573,7 +576,10 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
573 return NULL; 576 return NULL;
574 } 577 }
575 578
576 pool->zpool = zpool_create_pool(type, "zswap", gfp, &zswap_zpool_ops); 579 /* unique name for each pool specifically required by zsmalloc */
580 snprintf(name, 38, "zswap%x", atomic_inc_return(&zswap_pools_count));
581
582 pool->zpool = zpool_create_pool(type, name, gfp, &zswap_zpool_ops);
577 if (!pool->zpool) { 583 if (!pool->zpool) {
578 pr_err("%s zpool not available\n", type); 584 pr_err("%s zpool not available\n", type);
579 goto error; 585 goto error;