summaryrefslogtreecommitdiffstats
path: root/mm/zswap.c
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2017-02-27 17:26:50 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-27 21:43:45 -0500
commitbae21db88b7075662f28a0aa57e97016a2fdabfd (patch)
treec052b5c5769cd00584c4e5744249ecac5c6d63dd /mm/zswap.c
parentae3d89a7e0871bc7b57ef8d3c4dd7fdda43c285c (diff)
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>
Diffstat (limited to 'mm/zswap.c')
-rw-r--r--mm/zswap.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/mm/zswap.c b/mm/zswap.c
index 77cb847938e1..9e8565d9c66b 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -76,6 +76,8 @@ static u64 zswap_duplicate_entry;
76* tunables 76* tunables
77**********************************/ 77**********************************/
78 78
79#define ZSWAP_PARAM_UNSET ""
80
79/* Enable/disable zswap (disabled by default) */ 81/* Enable/disable zswap (disabled by default) */
80static bool zswap_enabled; 82static bool zswap_enabled;
81static int zswap_enabled_param_set(const char *, 83static int zswap_enabled_param_set(const char *,
@@ -501,6 +503,17 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
501 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; 503 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
502 int ret; 504 int ret;
503 505
506 if (!zswap_has_pool) {
507 /* if either are unset, pool initialization failed, and we
508 * need both params to be set correctly before trying to
509 * create a pool.
510 */
511 if (!strcmp(type, ZSWAP_PARAM_UNSET))
512 return NULL;
513 if (!strcmp(compressor, ZSWAP_PARAM_UNSET))
514 return NULL;
515 }
516
504 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 517 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
505 if (!pool) { 518 if (!pool) {
506 pr_err("pool alloc failed\n"); 519 pr_err("pool alloc failed\n");
@@ -550,28 +563,40 @@ error:
550 563
551static __init struct zswap_pool *__zswap_pool_create_fallback(void) 564static __init struct zswap_pool *__zswap_pool_create_fallback(void)
552{ 565{
553 if (!crypto_has_comp(zswap_compressor, 0, 0)) { 566 bool has_comp, has_zpool;
554 if (!strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) { 567
555 pr_err("default compressor %s not available\n", 568 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
556 zswap_compressor); 569 if (!has_comp && strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) {
557 return NULL;
558 }
559 pr_err("compressor %s not available, using default %s\n", 570 pr_err("compressor %s not available, using default %s\n",
560 zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT); 571 zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT);
561 param_free_charp(&zswap_compressor); 572 param_free_charp(&zswap_compressor);
562 zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT; 573 zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
574 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
563 } 575 }
564 if (!zpool_has_pool(zswap_zpool_type)) { 576 if (!has_comp) {
565 if (!strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) { 577 pr_err("default compressor %s not available\n",
566 pr_err("default zpool %s not available\n", 578 zswap_compressor);
567 zswap_zpool_type); 579 param_free_charp(&zswap_compressor);
568 return NULL; 580 zswap_compressor = ZSWAP_PARAM_UNSET;
569 } 581 }
582
583 has_zpool = zpool_has_pool(zswap_zpool_type);
584 if (!has_zpool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) {
570 pr_err("zpool %s not available, using default %s\n", 585 pr_err("zpool %s not available, using default %s\n",
571 zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT); 586 zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT);
572 param_free_charp(&zswap_zpool_type); 587 param_free_charp(&zswap_zpool_type);
573 zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT; 588 zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
589 has_zpool = zpool_has_pool(zswap_zpool_type);
574 } 590 }
591 if (!has_zpool) {
592 pr_err("default zpool %s not available\n",
593 zswap_zpool_type);
594 param_free_charp(&zswap_zpool_type);
595 zswap_zpool_type = ZSWAP_PARAM_UNSET;
596 }
597
598 if (!has_comp || !has_zpool)
599 return NULL;
575 600
576 return zswap_pool_create(zswap_zpool_type, zswap_compressor); 601 return zswap_pool_create(zswap_zpool_type, zswap_compressor);
577} 602}