@@ -25290,6 +25290,13 @@ S: Maintained
F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml
F: drivers/iio/light/veml6030.c
+VIRTUAL SWAP SPACE
+M: Nhat Pham <nphamcs@gmail.com>
+M: Johannes Weiner <hannes@cmpxchg.org>
+L: linux-mm@kvack.org
+S: Maintained
+F: mm/vswap.c
+
VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER
M: Javier Carrasco <javier.carrasco.cruz@gmail.com>
S: Maintained
@@ -726,6 +726,15 @@ static inline bool mem_cgroup_swap_full(struct folio *folio)
}
#endif
+#ifdef CONFIG_VIRTUAL_SWAP
+int vswap_init(void);
+#else /* CONFIG_VIRTUAL_SWAP */
+static inline int vswap_init(void)
+{
+ return 0;
+}
+#endif /* CONFIG_VIRTUAL_SWAP */
+
/**
* swp_entry_to_swp_slot - look up the physical swap slot corresponding to a
* virtual swap slot.
@@ -22,6 +22,31 @@ menuconfig SWAP
used to provide more virtual memory than the actual RAM present
in your computer. If unsure say Y.
+config VIRTUAL_SWAP
+ bool "Swap space virtualization"
+ depends on SWAP
+ default n
+ help
+ When this is selected, the kernel is built with the new swap
+ design, where each swap entry is associated with a virtual swap
+ slot that is decoupled from a specific physical backing storage
+ location. As a result, swap entries that are:
+
+ 1. Zero-filled
+
+ 2. Stored in the zswap pool.
+
+ 3. Rejected by zswap/zram but cannot be written back to a
+ backing swap device.
+
+ no longer take up any disk storage (i.e they do not occupy any
+ slot in the backing swap device).
+
+ Swapoff is also more efficient.
+
+ There might be more lock contentions with heavy swap use, since
+ the swap cache is no longer range partitioned.
+
config ZSWAP
bool "Compressed cache for swap pages"
depends on SWAP
@@ -76,6 +76,7 @@ ifdef CONFIG_MMU
endif
obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o swap_slots.o
+obj-$(CONFIG_VIRTUAL_SWAP) += vswap.o
obj-$(CONFIG_ZSWAP) += zswap.o
obj-$(CONFIG_HAS_DMA) += dmapool.o
obj-$(CONFIG_HUGETLBFS) += hugetlb.o
@@ -930,6 +930,12 @@ static int __init swap_init_sysfs(void)
int err;
struct kobject *swap_kobj;
+ err = vswap_init();
+ if (err) {
+ pr_err("failed to initialize virtual swap space\n");
+ return err;
+ }
+
swap_kobj = kobject_create_and_add("swap", mm_kobj);
if (!swap_kobj) {
pr_err("failed to create swap kobject\n");
new file mode 100644
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Virtual swap space
+ *
+ * Copyright (C) 2024 Meta Platforms, Inc., Nhat Pham
+ */
+ #include <linux/swap.h>
+
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+
+static struct dentry *vswap_debugfs_root;
+
+static int vswap_debug_fs_init(void)
+{
+ if (!debugfs_initialized())
+ return -ENODEV;
+
+ vswap_debugfs_root = debugfs_create_dir("vswap", NULL);
+ return 0;
+}
+#else
+static int vswap_debug_fs_init(void)
+{
+ return 0;
+}
+#endif
+
+int vswap_init(void)
+{
+ if (vswap_debug_fs_init())
+ pr_warn("Failed to initialize vswap debugfs\n");
+
+ return 0;
+}
In prepration for the implementation of swap virtualization, add new scaffolds for the new code: 1. Add a new mm/vswap.c source file, which currently only holds the logic to set up the (for now, empty) vswap debugfs directory. Hook this up in the swap setup step in mm/swap_state.c. Add a new maintainer entry for the new source file. 2. Add a new config option (CONFIG_VIRTUAL_SWAP). We will only get new behavior when the kernel is built with this config option. The entry for the config option in mm/Kconfig summarizes the pros and cons of the new virtual swap design, which the remainder of the patch series will implement. 3. Set up vswap compilation in the Makefile. Other than the debugfs directory, no behavioral change intended. Signed-off-by: Nhat Pham <nphamcs@gmail.com> --- MAINTAINERS | 7 +++++++ include/linux/swap.h | 9 +++++++++ mm/Kconfig | 25 +++++++++++++++++++++++++ mm/Makefile | 1 + mm/swap_state.c | 6 ++++++ mm/vswap.c | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 mm/vswap.c