]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mm/swap: remove redundant swap device reference in alloc/free
authorYoungjun Park <youngjun.park@lge.com>
Mon, 23 Mar 2026 16:08:22 +0000 (01:08 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 9 Jun 2026 01:21:32 +0000 (18:21 -0700)
commit0d97349679c5fe9941d283715ca109d61bbdc06e
treeb400710e42fe7ca05f912a85dbf2070f3936de54
parentc13a0316aef5f4b73e8b4bf6943737f836d65e1d
mm/swap: remove redundant swap device reference in alloc/free

In the previous commit, uswsusp was modified to pin the swap device when
the swap type is determined, ensuring the device remains valid throughout
the hibernation I/O path.

Therefore, it is no longer necessary to repeatedly get and put the swap
device reference for each swap slot allocation and free operation.

For hibernation via the sysfs interface, user-space tasks are frozen
before swap allocation begins, so swapoff cannot race with allocation.
After resume, tasks remain frozen while swap slots are freed, so
additional reference management is not required there either.

Remove the redundant swap device get/put operations from the hibernation
swap allocation and free paths.

Also remove the SWP_WRITEOK check before allocation, as the cluster
allocation logic already validates the swap device state.

Update function comments to document the caller's responsibility for
ensuring swap device stability.

Link: https://lore.kernel.org/20260323160822.1409904-3-youngjun.park@lge.com
Signed-off-by: Youngjun Park <youngjun.park@lge.com>
Reviewed-by: Kairui Song <kasong@tencent.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c