History

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.

Dan Streetman committed 10 years ago

Commit 32a4e161 parent 127393f1 file · +7 −1Browse files

Unified · Split

mm/zswap.c+7−1
@@ -170,6 +170,8 @@ static struct zswap_tree *zswap_trees[MAX_SWAPFILES]; · 169 unmodified lines
170170 static LIST_HEAD(zswap_pools);
171171 /* protects zswap_pools list modification */
172172 static DEFINE_SPINLOCK(zswap_pools_lock);
173+/* pool counter to provide unique names to zpool */
174+static atomic_t zswap_pools_count = ATOMIC_INIT(0);
173175
174176 /* used by param callback function */
175177 static bool zswap_init_started;
@@ -565,6 +567,7 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) · 389 unmodified lines
565567 static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
566568 {
567569 struct zswap_pool *pool;
570+ char name[38]; /* 'zswap' + 32 char (max) num + \0 */
568571 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
569572
570573 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
@@ -573,7 +576,10 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) · 2 unmodified lines
573576 return NULL;
574577 }
575578
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);
577583 if (!pool->zpool) {
578584 pr_err("%s zpool not available\n", type);
579585 goto error;