diff mbox series

[RFC,v2,18/18] swapfile: remove zeromap in virtual swap implementation

Message ID 20250429233848.3093350-19-nphamcs@gmail.com
State New
Headers show
Series Virtual Swap Space | expand

Commit Message

Nhat Pham April 29, 2025, 11:38 p.m. UTC
We are not using the zeromap for swapped out zero-filled pages in the
virtual swap implementation. Remove it. This saves about 1 bit per
physical swap slot.

Signed-off-by: Nhat Pham <nphamcs@gmail.com>
---
 include/linux/swap.h |  2 ++
 mm/swapfile.c        | 12 ++++++++++++
 2 files changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 0c585103d228..408368d56dfb 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -312,7 +312,9 @@  struct swap_info_struct {
 	signed char	type;		/* strange name for an index */
 	unsigned int	max;		/* extent of the swap_map */
 	unsigned char *swap_map;	/* vmalloc'ed array of usage counts */
+#ifndef CONFIG_VIRTUAL_SWAP
 	unsigned long *zeromap;		/* kvmalloc'ed bitmap to track zero pages */
+#endif
 	struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */
 	struct list_head free_clusters; /* free clusters list */
 	struct list_head full_clusters; /* full clusters list */
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 3ed7edc800fe..3d99bd02ede9 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2824,7 +2824,9 @@  static void enable_swap_info(struct swap_info_struct *si, int prio,
 	spin_lock(&swap_lock);
 	spin_lock(&si->lock);
 	setup_swap_info(si, prio, swap_map, cluster_info);
+#ifndef CONFIG_VIRTUAL_SWAP
 	si->zeromap = zeromap;
+#endif
 	spin_unlock(&si->lock);
 	spin_unlock(&swap_lock);
 	/*
@@ -2885,7 +2887,9 @@  SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 {
 	struct swap_info_struct *p = NULL;
 	unsigned char *swap_map;
+#ifndef CONFIG_VIRTUAL_SWAP
 	unsigned long *zeromap;
+#endif
 	struct swap_cluster_info *cluster_info;
 	struct file *swap_file, *victim;
 	struct address_space *mapping;
@@ -3000,8 +3004,10 @@  SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	p->max = 0;
 	swap_map = p->swap_map;
 	p->swap_map = NULL;
+#ifndef CONFIG_VIRTUAL_SWAP
 	zeromap = p->zeromap;
 	p->zeromap = NULL;
+#endif
 	cluster_info = p->cluster_info;
 	p->cluster_info = NULL;
 	spin_unlock(&p->lock);
@@ -3014,7 +3020,9 @@  SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	kfree(p->global_cluster);
 	p->global_cluster = NULL;
 	vfree(swap_map);
+#ifndef CONFIG_VIRTUAL_SWAP
 	kvfree(zeromap);
+#endif
 	kvfree(cluster_info);
 	/* Destroy swap account information */
 	swap_cgroup_swapoff(p->type);
@@ -3601,6 +3609,7 @@  SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 		goto bad_swap_unlock_inode;
 	}
 
+#ifndef CONFIG_VIRTUAL_SWAP
 	/*
 	 * Use kvmalloc_array instead of bitmap_zalloc as the allocation order might
 	 * be above MAX_PAGE_ORDER incase of a large swap file.
@@ -3611,6 +3620,7 @@  SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 		error = -ENOMEM;
 		goto bad_swap_unlock_inode;
 	}
+#endif
 
 	if (si->bdev && bdev_stable_writes(si->bdev))
 		si->flags |= SWP_STABLE_WRITES;
@@ -3722,7 +3732,9 @@  SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	si->flags = 0;
 	spin_unlock(&swap_lock);
 	vfree(swap_map);
+#ifndef CONFIG_VIRTUAL_SWAP
 	kvfree(zeromap);
+#endif
 	kvfree(cluster_info);
 	if (inced_nr_rotate_swap)
 		atomic_dec(&nr_rotate_swap);