summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorKemeng Shi <shikemeng@huaweicloud.com>2026-09-07 17:13:54 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-09-13 21:32:38 -0700
commita55993b7935f3e4229943eef0d61759e6069b80d (patch)
treed5316510b20c803c840bbec9ec342ccb3364ffe4 /mm
parentba85601f6bcf0629860c342b7dbbfa4e5733be0c (diff)
downloadlinux-next-a55993b7935f3e4229943eef0d61759e6069b80d.tar.gz
linux-next-a55993b7935f3e4229943eef0d61759e6069b80d.zip
mm, swap: move setup_swap_clusters_info() after SWP_SOLIDSTATE initialization
In setup_swap_clusters_info(), SWP_SOLIDSTATE is used to decide global_cluster allocation. Move setup_swap_clusters_info() after SWP_SOLIDSTATE initialization to avoid unneeded global_cluster allocation. Link: https://lore.kernel.org/20260907091356.53026-3-shikemeng@huaweicloud.com Fixes: 451c6326105b ("mm, swap: clean up swapon process and locking") Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Luiz Capitulino <luizcap@redhat.com> Acked-by: Kairui Song <kasong@tencent.com> Cc: Baoquan He <baoquan.he@linux.dev> Cc: Barry Song <baohua@kernel.org> Cc: Chris Li <chrisl@kernel.org> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Youngjun Park <youngjun.park@lge.com>
Diffstat (limited to 'mm')
-rw-r--r--mm/swapfile.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 8df8b2c2e5b4..40ceab21ed5b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3763,11 +3763,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
maxpages = si->max;
- /* Set up the swap cluster info */
- error = setup_swap_clusters_info(si, swap_header, maxpages);
- if (error)
- goto bad_swap_unlock_inode;
-
if (si->bdev && bdev_stable_writes(si->bdev))
si->flags |= SWP_STABLE_WRITES;
@@ -3781,6 +3776,14 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
inced_nr_rotate_swap = true;
}
+ /*
+ * Set up the swap cluster info after SWP_ flags handling as
+ * setup_swap_clusters_info() checks SWP_SOLIDSTATE.
+ */
+ error = setup_swap_clusters_info(si, swap_header, maxpages);
+ if (error)
+ goto bad_swap_unlock_inode;
+
if ((swap_flags & SWAP_FLAG_DISCARD) &&
si->bdev && bdev_max_discard_sectors(si->bdev)) {
/*