zswap.c (c9f289701540baeef9ac7c9977d67a7259f404db) zswap.c (bb8b93b5b65130138d3c80f3136af721863f561a)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * zswap.c - zswap driver file
4 *
5 * zswap is a backend for frontswap that takes pages that are in the process
6 * of being swapped out and attempts to compress and store them in a
7 * RAM-based memory pool. This can result in a significant I/O reduction on
8 * the swap device and, in the case where decompressing from RAM is faster

--- 63 unchanged lines hidden (view full) ---

72static bool zswap_pool_reached_full;
73
74/*********************************
75* tunables
76**********************************/
77
78#define ZSWAP_PARAM_UNSET ""
79
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * zswap.c - zswap driver file
4 *
5 * zswap is a backend for frontswap that takes pages that are in the process
6 * of being swapped out and attempts to compress and store them in a
7 * RAM-based memory pool. This can result in a significant I/O reduction on
8 * the swap device and, in the case where decompressing from RAM is faster

--- 63 unchanged lines hidden (view full) ---

72static bool zswap_pool_reached_full;
73
74/*********************************
75* tunables
76**********************************/
77
78#define ZSWAP_PARAM_UNSET ""
79
80/* Enable/disable zswap (disabled by default) */
81static bool zswap_enabled;
80/* Enable/disable zswap */
81static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON);
82static int zswap_enabled_param_set(const char *,
83 const struct kernel_param *);
84static struct kernel_param_ops zswap_enabled_param_ops = {
85 .set = zswap_enabled_param_set,
86 .get = param_get_bool,
87};
88module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644);
89
90/* Crypto compressor to use */
82static int zswap_enabled_param_set(const char *,
83 const struct kernel_param *);
84static struct kernel_param_ops zswap_enabled_param_ops = {
85 .set = zswap_enabled_param_set,
86 .get = param_get_bool,
87};
88module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644);
89
90/* Crypto compressor to use */
91#define ZSWAP_COMPRESSOR_DEFAULT "lzo"
92static char *zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
91static char *zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
93static int zswap_compressor_param_set(const char *,
94 const struct kernel_param *);
95static struct kernel_param_ops zswap_compressor_param_ops = {
96 .set = zswap_compressor_param_set,
97 .get = param_get_charp,
98 .free = param_free_charp,
99};
100module_param_cb(compressor, &zswap_compressor_param_ops,
101 &zswap_compressor, 0644);
102
103/* Compressed storage zpool to use */
92static int zswap_compressor_param_set(const char *,
93 const struct kernel_param *);
94static struct kernel_param_ops zswap_compressor_param_ops = {
95 .set = zswap_compressor_param_set,
96 .get = param_get_charp,
97 .free = param_free_charp,
98};
99module_param_cb(compressor, &zswap_compressor_param_ops,
100 &zswap_compressor, 0644);
101
102/* Compressed storage zpool to use */
104#define ZSWAP_ZPOOL_DEFAULT "zbud"
105static char *zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
103static char *zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
106static int zswap_zpool_param_set(const char *, const struct kernel_param *);
107static struct kernel_param_ops zswap_zpool_param_ops = {
108 .set = zswap_zpool_param_set,
109 .get = param_get_charp,
110 .free = param_free_charp,
111};
112module_param_cb(zpool, &zswap_zpool_param_ops, &zswap_zpool_type, 0644);
113

--- 480 unchanged lines hidden (view full) ---

594 return NULL;
595}
596
597static __init struct zswap_pool *__zswap_pool_create_fallback(void)
598{
599 bool has_comp, has_zpool;
600
601 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
104static int zswap_zpool_param_set(const char *, const struct kernel_param *);
105static struct kernel_param_ops zswap_zpool_param_ops = {
106 .set = zswap_zpool_param_set,
107 .get = param_get_charp,
108 .free = param_free_charp,
109};
110module_param_cb(zpool, &zswap_zpool_param_ops, &zswap_zpool_type, 0644);
111

--- 480 unchanged lines hidden (view full) ---

592 return NULL;
593}
594
595static __init struct zswap_pool *__zswap_pool_create_fallback(void)
596{
597 bool has_comp, has_zpool;
598
599 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
602 if (!has_comp && strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) {
600 if (!has_comp && strcmp(zswap_compressor,
601 CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
603 pr_err("compressor %s not available, using default %s\n",
602 pr_err("compressor %s not available, using default %s\n",
604 zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT);
603 zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT);
605 param_free_charp(&zswap_compressor);
604 param_free_charp(&zswap_compressor);
606 zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
605 zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
607 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
608 }
609 if (!has_comp) {
610 pr_err("default compressor %s not available\n",
611 zswap_compressor);
612 param_free_charp(&zswap_compressor);
613 zswap_compressor = ZSWAP_PARAM_UNSET;
614 }
615
616 has_zpool = zpool_has_pool(zswap_zpool_type);
606 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
607 }
608 if (!has_comp) {
609 pr_err("default compressor %s not available\n",
610 zswap_compressor);
611 param_free_charp(&zswap_compressor);
612 zswap_compressor = ZSWAP_PARAM_UNSET;
613 }
614
615 has_zpool = zpool_has_pool(zswap_zpool_type);
617 if (!has_zpool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) {
616 if (!has_zpool && strcmp(zswap_zpool_type,
617 CONFIG_ZSWAP_ZPOOL_DEFAULT)) {
618 pr_err("zpool %s not available, using default %s\n",
618 pr_err("zpool %s not available, using default %s\n",
619 zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT);
619 zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT);
620 param_free_charp(&zswap_zpool_type);
620 param_free_charp(&zswap_zpool_type);
621 zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
621 zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
622 has_zpool = zpool_has_pool(zswap_zpool_type);
623 }
624 if (!has_zpool) {
625 pr_err("default zpool %s not available\n",
626 zswap_zpool_type);
627 param_free_charp(&zswap_zpool_type);
628 zswap_zpool_type = ZSWAP_PARAM_UNSET;
629 }

--- 750 unchanged lines hidden ---
622 has_zpool = zpool_has_pool(zswap_zpool_type);
623 }
624 if (!has_zpool) {
625 pr_err("default zpool %s not available\n",
626 zswap_zpool_type);
627 param_free_charp(&zswap_zpool_type);
628 zswap_zpool_type = ZSWAP_PARAM_UNSET;
629 }

--- 750 unchanged lines hidden ---