]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm, swap: use SWP_SOLIDSTATE to determine if swap is rotational
authorYoungjun Park <youngjun.park@lge.com>
Fri, 31 Oct 2025 06:50:08 +0000 (15:50 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 24 Nov 2025 23:08:56 +0000 (15:08 -0800)
The current non rotational check is unreliable as the device's rotational
status can be changed by a user via sysfs.

Use the more reliable SWP_SOLIDSTATE flag which is set at swapon time, to
ensure the nr_rotate_swap count remains consistent.  Plus, it is easy to
read and simple.

Link: https://lkml.kernel.org/r/20251031065011.40863-3-youngjun.park@lge.com
Fixes: 81a0298bdfab ("mm, swap: don't use VMA based swap readahead if HDD is used as swap")
Signed-off-by: Youngjun Park <youngjun.park@lge.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c

index 0a822e0d9bf9220e3986d7d264b1763c5ec0237b..c8ac0fd51c4c524746bb81669b07ad30d6a3d459 100644 (file)
@@ -2910,7 +2910,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
        if (p->flags & SWP_CONTINUED)
                free_swap_count_continuations(p);
 
-       if (!p->bdev || !bdev_nonrot(p->bdev))
+       if (!(p->flags & SWP_SOLIDSTATE))
                atomic_dec(&nr_rotate_swap);
 
        mutex_lock(&swapon_mutex);