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.
Unified · Split
| @@ -170,6 +170,8 @@ static struct zswap_tree *zswap_trees[MAX_SWAPFILES]; · 169 unmodified lines | |||
| 170 | static LIST_HEAD(zswap_pools); | 170 | static LIST_HEAD(zswap_pools); |
| 171 | /* protects zswap_pools list modification */ | 171 | /* protects zswap_pools list modification */ |
| 172 | static DEFINE_SPINLOCK(zswap_pools_lock); | 172 | 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); | ||
| 173 | 175 | ||
| 174 | /* used by param callback function */ | 176 | /* used by param callback function */ |
| 175 | static bool zswap_init_started; | 177 | static bool zswap_init_started; |
| @@ -565,6 +567,7 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) · 389 unmodified lines | |||
| 565 | static struct zswap_pool *zswap_pool_create(char *type, char *compressor) | 567 | static 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) · 2 unmodified lines | |||
| 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; |