// SPDX-License-Identifier: GPL-2.0-or-later/* * zswap.c - zswap driver file * * zswap is a backend for frontswap that takes pages that are in the process * of being swapped out and attempts to compress and store them in a * RAM-based memory pool. This can result in a significant I/O reduction on * the swap device and, in the case where decompressing from RAM is faster * than reading from the swap device, can also improve workload performance. * * Copyright (C) 2012 Seth Jennings <sjenning@linux.vnet.ibm.com>*/#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt#include<linux/module.h>#include<linux/cpu.h>#include<linux/highmem.h>#include<linux/slab.h>#include<linux/spinlock.h>#include<linux/types.h>#include<linux/atomic.h>#include<linux/frontswap.h>#include<linux/rbtree.h>#include<linux/swap.h>#include<linux/crypto.h>#include<linux/scatterlist.h>#include<linux/mempool.h>#include<linux/zpool.h>#include<crypto/acompress.h>#include<linux/mm_types.h>#include<linux/page-flags.h>#include<linux/swapops.h>#include<linux/writeback.h>#include<linux/pagemap.h>#include<linux/workqueue.h>/********************************** statistics**********************************//* Total bytes used by the compressed storage */staticu64zswap_pool_total_size;/* The number of compressed pages currently stored in zswap */staticatomic_tzswap_stored_pages=ATOMIC_INIT(0);/* The number of same-value filled pages currently stored in zswap */staticatomic_tzswap_same_filled_pages=ATOMIC_INIT(0);/* * The statistics below are not protected from concurrent access for * performance reasons so they may not be a 100% accurate. However, * they do provide useful information on roughly how many times a * certain event is occurring.*//* Pool limit was hit (see zswap_max_pool_percent) */staticu64zswap_pool_limit_hit;/* Pages written back when pool limit was reached */staticu64zswap_written_back_pages;/* Store failed due to a reclaim failure after pool limit was reached */staticu64zswap_reject_reclaim_fail;/* Compressed page was too big for the allocator to (optimally) store */staticu64zswap_reject_compress_poor;/* Store failed because underlying allocator could not get memory */static