@@ -24,6 +24,7 @@ struct zswap_lruvec_state {
atomic_long_t nr_disk_swapins;
};
+bool zswap_store_batching_enabled(void);
unsigned long zswap_total_pages(void);
bool zswap_store(struct folio *folio);
bool zswap_load(struct folio *folio);
@@ -39,6 +40,11 @@ bool zswap_never_enabled(void);
struct zswap_lruvec_state {};
+static inline bool zswap_store_batching_enabled(void)
+{
+ return false;
+}
+
static inline bool zswap_store(struct folio *folio)
{
return false;
@@ -125,6 +125,18 @@ config ZSWAP_COMPRESSOR_DEFAULT
default "zstd" if ZSWAP_COMPRESSOR_DEFAULT_ZSTD
default ""
+config ZSWAP_STORE_BATCHING_ENABLED
+ bool "Batching of zswap stores with Intel IAA"
+ depends on ZSWAP && CRYPTO_DEV_IAA_CRYPTO
+ default n
+ help
+ Enables zswap_store to swapout large folios in batches of 8 pages,
+ rather than a page at a time, if the system has Intel IAA for hardware
+ acceleration of compressions. If IAA is configured as the zswap
+ compressor, this will parallelize batch compression of upto 8 pages
+ in the folio in hardware, thereby improving large folio compression
+ throughput and reducing swapout latency.
+
choice
prompt "Default allocator"
depends on ZSWAP
@@ -127,6 +127,15 @@ static bool zswap_shrinker_enabled = IS_ENABLED(
CONFIG_ZSWAP_SHRINKER_DEFAULT_ON);
module_param_named(shrinker_enabled, zswap_shrinker_enabled, bool, 0644);
+/*
+ * Enable/disable batching of compressions if zswap_store is called with a
+ * large folio. If enabled, and if IAA is the zswap compressor, pages are
+ * compressed in parallel in batches of say, 8 pages.
+ * If not, every page is compressed sequentially.
+ */
+static bool __zswap_store_batching_enabled = IS_ENABLED(
+ CONFIG_ZSWAP_STORE_BATCHING_ENABLED);
+
bool zswap_is_enabled(void)
{
return zswap_enabled;
@@ -241,6 +250,11 @@ static inline struct xarray *swap_zswap_tree(swp_entry_t swp)
pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \
zpool_get_type((p)->zpool))
+__always_inline bool zswap_store_batching_enabled(void)
+{
+ return __zswap_store_batching_enabled;
+}
+
/*********************************
* pool functions
**********************************/
Add a new zswap config variable that controls whether zswap_store() will compress a batch of pages, for instance, the pages in a large folio: CONFIG_ZSWAP_STORE_BATCHING_ENABLED The existing CONFIG_CRYPTO_DEV_IAA_CRYPTO variable added in commit ea7a5cbb4369 ("crypto: iaa - Add Intel IAA Compression Accelerator crypto driver core") is used to detect if the system has the Intel Analytics Accelerator (IAA), and the iaa_crypto module is available. If so, the kernel build will prompt for CONFIG_ZSWAP_STORE_BATCHING_ENABLED. Hence, users have the ability to set CONFIG_ZSWAP_STORE_BATCHING_ENABLED="y" only on systems that have Intel IAA. If CONFIG_ZSWAP_STORE_BATCHING_ENABLED is enabled, and IAA is configured as the zswap compressor, zswap_store() will process the pages in a large folio in batches, i.e., multiple pages at a time. Pages in a batch will be compressed in parallel in hardware, then stored. On systems without Intel IAA and/or if zswap uses software compressors, pages in the batch will be compressed sequentially and stored. The patch also implements a zswap API that returns the status of this config variable. Suggested-by: Ying Huang <ying.huang@intel.com> Signed-off-by: Kanchana P Sridhar <kanchana.p.sridhar@intel.com> --- include/linux/zswap.h | 6 ++++++ mm/Kconfig | 12 ++++++++++++ mm/zswap.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+)