From: Kairui Song The swap_active_head plist tracked all writable swap devices, ordered by priority. Now that every consumer that needed priority ordering has moved to the priority queue, the remaining users only need to find any writable device. Remove swap_active_head, the associated plist_node from swap_info_struct, and migrate the remaining plist operations. Signed-off-by: Kairui Song Signed-off-by: Lian Wang (ProcessMission) Tested-by: Kunwu Chan --- include/linux/swap.h | 1 - mm/swapfile.c | 27 +++++---------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 0c8c1ebcab9c..9d86db144b94 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -267,7 +267,6 @@ struct swap_info_struct { struct percpu_ref users; /* indicate and keep swap device valid. */ unsigned long flags; /* SWP_USED etc: see above */ signed short prio; /* swap priority of this type */ - struct plist_node list; /* entry in swap_active_head */ signed char type; /* strange name for an index */ unsigned int max; /* size of this swap device */ struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */ diff --git a/mm/swapfile.c b/mm/swapfile.c index cb27f2e246f0..0acb1f31df8c 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include @@ -90,12 +89,6 @@ bool swap_migration_ad_supported; static const char Bad_file[] = "Bad swap file entry "; static const char Bad_offset[] = "Bad swap offset entry "; -/* - * all active swap_info_structs - * protected with swapon_rwsem, and ordered by priority. - */ -static PLIST_HEAD(swap_active_head); - static inline struct swap_info_struct *__swap_iter(int *i, unsigned long flag) { lockdep_assert_held(&swapon_rwsem); @@ -3262,7 +3255,6 @@ static void __swap_device_enable(struct swap_info_struct *si) spin_unlock(&swap_queue_update_lock); atomic_long_add(si->pages, &nr_swap_pages); total_swap_pages += si->pages; - plist_add(&si->list, &swap_active_head); add_to_avail_list(si); } @@ -3282,9 +3274,8 @@ static int swap_device_disable(struct address_space *mapping, int err = -EINVAL; percpu_down_write(&swapon_rwsem); - plist_for_each_entry(si, &swap_active_head, list) { - if ((si->flags & SWP_WRITEOK) && - si->swap_file->f_mapping == mapping) { + for_each_avail_swap(si) { + if (si->swap_file->f_mapping == mapping) { err = 0; break; } @@ -3309,7 +3300,6 @@ static int swap_device_disable(struct address_space *mapping, spin_lock(&swap_queue_update_lock); si->flags &= ~SWP_WRITEOK; spin_unlock(&swap_queue_update_lock); - plist_del(&si->list, &swap_active_head); total_swap_pages -= si->pages; atomic_long_sub(si->pages, &nr_swap_pages); @@ -3641,7 +3631,6 @@ static struct swap_info_struct *alloc_swap_info(void) */ } p->swap_extent_root = RB_ROOT; - plist_node_init(&p->list, 0); p->flags = SWP_USED; percpu_up_write(&swapon_rwsem); if (defer) { @@ -4050,12 +4039,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) if (swap_flags & SWAP_FLAG_PREFER) prio = swap_flags & SWAP_FLAG_PRIO_MASK; - /* - * The plist prio is negated because plist ordering is - * low-to-high, while swap ordering is high-to-low - */ si->prio = prio; - si->list.prio = -si->prio; /* * Publish swap_file before making the percpu ref live, then add the device @@ -4176,7 +4160,7 @@ int swap_dup_entry_direct(swp_entry_t entry) #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) static bool __has_usable_swap(void) { - return !plist_head_empty(&swap_active_head); + return READ_ONCE(total_swap_pages) > 0; } void __folio_throttle_swaprate(struct folio *folio, gfp_t gfp) @@ -4200,9 +4184,8 @@ void __folio_throttle_swaprate(struct folio *folio, gfp_t gfp) return; percpu_down_read(&swapon_rwsem); - plist_for_each_entry(si, &swap_active_head, list) { - if ((si->flags & SWP_WRITEOK) && - !(atomic_long_read(&si->inuse_pages) & + for_each_avail_swap(si) { + if (!(atomic_long_read(&si->inuse_pages) & SWAP_USAGE_OFFLIST_BIT) && si->bdev) { blkcg_schedule_throttle(si->bdev->bd_disk, true); break; -- 2.55.0