Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

zswap: allow initialization at boot without pool

Allow zswap to initialize at boot even if it can't create its pool due
to a failure to create a zpool and/or compressor. Allow those to be
created later, from the sysfs module param interface.

Link: http://lkml.kernel.org/r/20170124200259.16191-3-ddstreet@ieee.org
Signed-off-by: Dan Streetman <dan.streetman@canonical.com>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dan Streetman and committed by
Linus Torvalds
ae3d89a7 01cddfe9

+34 -12
+34 -12
mm/zswap.c
··· 185 185 /* fatal error during init */ 186 186 static bool zswap_init_failed; 187 187 188 + /* init completed, but couldn't create the initial pool */ 189 + static bool zswap_has_pool; 190 + 188 191 /********************************* 189 192 * helpers and fwd declarations 190 193 **********************************/ ··· 427 424 struct zswap_pool *pool; 428 425 429 426 pool = list_first_or_null_rcu(&zswap_pools, typeof(*pool), list); 430 - WARN_ON(!pool); 427 + WARN_ONCE(!pool && zswap_has_pool, 428 + "%s: no page storage pool!\n", __func__); 431 429 432 430 return pool; 433 431 } ··· 447 443 rcu_read_lock(); 448 444 449 445 pool = __zswap_pool_current(); 450 - if (!pool || !zswap_pool_get(pool)) 446 + if (!zswap_pool_get(pool)) 451 447 pool = NULL; 452 448 453 449 rcu_read_unlock(); ··· 463 459 464 460 list_for_each_entry_rcu(pool, &zswap_pools, list) 465 461 last = pool; 466 - if (!WARN_ON(!last) && !zswap_pool_get(last)) 462 + WARN_ONCE(!last && zswap_has_pool, 463 + "%s: no page storage pool!\n", __func__); 464 + if (!zswap_pool_get(last)) 467 465 last = NULL; 468 466 469 467 rcu_read_unlock(); ··· 588 582 589 583 static int __must_check zswap_pool_get(struct zswap_pool *pool) 590 584 { 585 + if (!pool) 586 + return 0; 587 + 591 588 return kref_get_unless_zero(&pool->kref); 592 589 } 593 590 ··· 648 639 } 649 640 650 641 /* no change required */ 651 - if (!strcmp(s, *(char **)kp->arg)) 642 + if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) 652 643 return 0; 653 644 654 645 /* if this is load-time (pre-init) param setting, ··· 694 685 if (!ret) { 695 686 put_pool = zswap_pool_current(); 696 687 list_add_rcu(&pool->list, &zswap_pools); 688 + zswap_has_pool = true; 697 689 } else if (pool) { 698 690 /* add the possibly pre-existing pool to the end of the pools 699 691 * list; if it's new (and empty) then it'll be removed and ··· 702 692 */ 703 693 list_add_tail_rcu(&pool->list, &zswap_pools); 704 694 put_pool = pool; 695 + } else if (!zswap_has_pool) { 696 + /* if initial pool creation failed, and this pool creation also 697 + * failed, maybe both compressor and zpool params were bad. 698 + * Allow changing this param, so pool creation will succeed 699 + * when the other param is changed. We already verified this 700 + * param is ok in the zpool_has_pool() or crypto_has_comp() 701 + * checks above. 702 + */ 703 + ret = param_set_charp(s, kp); 705 704 } 706 705 707 706 spin_unlock(&zswap_pools_lock); ··· 741 722 { 742 723 if (zswap_init_failed) { 743 724 pr_err("can't enable, initialization failed\n"); 725 + return -ENODEV; 726 + } 727 + if (!zswap_has_pool && zswap_init_started) { 728 + pr_err("can't enable, no pool configured\n"); 744 729 return -ENODEV; 745 730 } 746 731 ··· 1228 1205 goto hp_fail; 1229 1206 1230 1207 pool = __zswap_pool_create_fallback(); 1231 - if (!pool) { 1208 + if (pool) { 1209 + pr_info("loaded using pool %s/%s\n", pool->tfm_name, 1210 + zpool_get_type(pool->zpool)); 1211 + list_add(&pool->list, &zswap_pools); 1212 + zswap_has_pool = true; 1213 + } else { 1232 1214 pr_err("pool creation failed\n"); 1233 - goto pool_fail; 1215 + zswap_enabled = false; 1234 1216 } 1235 - pr_info("loaded using pool %s/%s\n", pool->tfm_name, 1236 - zpool_get_type(pool->zpool)); 1237 - 1238 - list_add(&pool->list, &zswap_pools); 1239 1217 1240 1218 frontswap_register_ops(&zswap_frontswap_ops); 1241 1219 if (zswap_debugfs_init()) 1242 1220 pr_warn("debugfs initialization failed\n"); 1243 1221 return 0; 1244 1222 1245 - pool_fail: 1246 - cpuhp_remove_state_nocalls(CPUHP_MM_ZSWP_POOL_PREPARE); 1247 1223 hp_fail: 1248 1224 cpuhp_remove_state(CPUHP_MM_ZSWP_MEM_PREPARE); 1249 1225 dstmem_fail: