mm-swap-clean-up-plist-removal-and-adding.patch removed from -mm tree
The quilt patch titled
Subject: mm, swap: clean up plist removal and adding
has been removed from the -mm tree. Its filename was
mm-swap-clean-up-plist-removal-and-adding.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Kairui Song <[email protected]>
Subject: mm, swap: clean up plist removal and adding
Date: Tue, 14 Jan 2025 01:57:25 +0800
When the swap device is full (inuse_pages == pages), it should be removed from the allocation available plist. If any slot is freed, the swap device should be added back to the plist. Additionally, during swapon or swapoff, the swap device is forcefully added or removed.
Currently, the condition (inuse_pages == pages) is checked after every counter update, then remove or add the device accordingly. This is serialized by si->lock.
This commit decouples it from the protection of si->lock and reworked plist removal and adding, making it possible to get rid of the hard dependency on si->lock in allocation path in later commits.
To achieve this, simply using another lock is not an optimal approach, as the overhead is observable for a hot counter, and may cause complex locking issues. Thus, this commit manages to make it a lock-free atomic operation, by embedding the plist state into the second highest bit of the atomic counter.
Simply making the counter an atomic will not work, if the update and plist status check are not performed atomically, we may miss an addition or removal. With the embedded info we can update the counter and check the plist status with single atomic operations, and avoid any extra overheads:
If the counter is full (inuse_pages == pages) and the off-list bit is unset, we attempt to remove it from the plist. If the counter is not full (inuse_pages != pages) and the off-list bit is set, we attempt to add it to the plist. Removing, adding and bit update is serialized with a lock, which is a cold path. Ordinary counter updates will be lock-free.
---
include/linux/swap.h | 2 mm/swapfile.c | 186 ++++++++++++++++++++++++++++++----------- 2 files changed, 138 insertions(+), 50 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~mm-swap-clean-up-plist-removal-and-adding +1 -1
@@ -306,7 +306,7 @@ struct swap_info_struct {/* list of cluster that are fragmented or contented */ unsigned int frag_cluster_nr[SWAP_NR_ORDERS ];unsigned int pages;/* total of usable pages of swap */ -unsigned int inuse_pages;/* number of those currently in use */ +atomic_long_t inuse_pages;/* number of those currently in use */ struct percpu_cluster __percpu *percpu_cluster;/* per cpu's swap location */ struct rb_root swap_extent_root;/* root of the swap extent rbtree */ struct block_device *bdev;/* swap device or bdev of swap file */
mm/swapfile.c renamed from mm/swapfile.c~mm-swap-clean-up-plist-removal-and-adding +137 -49
325 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are