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

zswap: clear compressor or zpool param if invalid at init

If either the compressor and/or zpool param are invalid at boot, and
their default value is also invalid, set the param to the empty string
to indicate there is no compressor and/or zpool configured. This allows
users to check the sysfs interface to see which param needs changing.

Link: http://lkml.kernel.org/r/20170124200259.16191-4-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
bae21db8 ae3d89a7

+37 -12
+37 -12
mm/zswap.c
··· 76 76 * tunables 77 77 **********************************/ 78 78 79 + #define ZSWAP_PARAM_UNSET "" 80 + 79 81 /* Enable/disable zswap (disabled by default) */ 80 82 static bool zswap_enabled; 81 83 static int zswap_enabled_param_set(const char *, ··· 503 501 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; 504 502 int ret; 505 503 504 + if (!zswap_has_pool) { 505 + /* if either are unset, pool initialization failed, and we 506 + * need both params to be set correctly before trying to 507 + * create a pool. 508 + */ 509 + if (!strcmp(type, ZSWAP_PARAM_UNSET)) 510 + return NULL; 511 + if (!strcmp(compressor, ZSWAP_PARAM_UNSET)) 512 + return NULL; 513 + } 514 + 506 515 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 507 516 if (!pool) { 508 517 pr_err("pool alloc failed\n"); ··· 563 550 564 551 static __init struct zswap_pool *__zswap_pool_create_fallback(void) 565 552 { 566 - if (!crypto_has_comp(zswap_compressor, 0, 0)) { 567 - if (!strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) { 568 - pr_err("default compressor %s not available\n", 569 - zswap_compressor); 570 - return NULL; 571 - } 553 + bool has_comp, has_zpool; 554 + 555 + has_comp = crypto_has_comp(zswap_compressor, 0, 0); 556 + if (!has_comp && strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) { 572 557 pr_err("compressor %s not available, using default %s\n", 573 558 zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT); 574 559 param_free_charp(&zswap_compressor); 575 560 zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT; 561 + has_comp = crypto_has_comp(zswap_compressor, 0, 0); 576 562 } 577 - if (!zpool_has_pool(zswap_zpool_type)) { 578 - if (!strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) { 579 - pr_err("default zpool %s not available\n", 580 - zswap_zpool_type); 581 - return NULL; 582 - } 563 + if (!has_comp) { 564 + pr_err("default compressor %s not available\n", 565 + zswap_compressor); 566 + param_free_charp(&zswap_compressor); 567 + zswap_compressor = ZSWAP_PARAM_UNSET; 568 + } 569 + 570 + has_zpool = zpool_has_pool(zswap_zpool_type); 571 + if (!has_zpool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) { 583 572 pr_err("zpool %s not available, using default %s\n", 584 573 zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT); 585 574 param_free_charp(&zswap_zpool_type); 586 575 zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT; 576 + has_zpool = zpool_has_pool(zswap_zpool_type); 587 577 } 578 + if (!has_zpool) { 579 + pr_err("default zpool %s not available\n", 580 + zswap_zpool_type); 581 + param_free_charp(&zswap_zpool_type); 582 + zswap_zpool_type = ZSWAP_PARAM_UNSET; 583 + } 584 + 585 + if (!has_comp || !has_zpool) 586 + return NULL; 588 587 589 588 return zswap_pool_create(zswap_zpool_type, zswap_compressor); 590 589 }