From: Youngjun Park <youngjun.park@lge.com>
To: rafael@kernel.org, akpm@linux-foundation.org
Cc: chrisl@kernel.org, kasong@tencent.com, pavel@kernel.org,
shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com,
baohua@kernel.org, youngjun.park@lge.com, usama.arif@linux.dev,
linux-pm@vger.kernel.org, linux-mm@kvack.org
Subject: [RESEND RFC PATCH v3 0/2] mm/swap, PM: hibernate: fix swapoff race and optimize swap reference
Date: Thu, 12 Mar 2026 20:25:09 +0900 [thread overview]
Message-ID: <20260312112511.3596781-1-youngjun.park@lge.com> (raw)
Currently, in the uswsusp path, only the swap type value is retrieved at
lookup time without holding a reference. If swapoff races after the type
is acquired, subsequent slot allocations operate on a stale swap device.
Additionally, grabbing and releasing the swap device reference on every
slot allocation is inefficient across the entire hibernation swap path.
This patch series addresses these issues:
- Patch 1: Fixes the swapoff race in uswsusp by holding the swap device
reference from the point the swap device is looked up.
- Patch 2: Removes the overhead of per-slot reference counting in alloc/free
paths and cleans up the redundant SWP_WRITEOK check.
While this approach seems reasonable and has passed basic testing,
I am not entirely familiar with the snapshot codebase.
Therefore, I am submitting this as an RFC to gather your feedback.
I plan to update it to a formal patch series based on the comments received.
Changelog:
rfc v2 -> rfc v3:
- Split the single patch into 2 patches (Patch 1: race issue, Patch 2:
reference optimization) per Chris Li's feedback.
- Addressed Chris Li's concern regarding the complexity of releasing
references on error paths in normal hibernation. Since normal hibernation
freezes processes (making swapoff impossible), it no longer holds the
reference at all. Instead, uswsusp explicitly acquires the reference,
simplifying the overall fix.
- Removed the SWP_WRITEOK check before allocation, as it is already
handled during cluster allocation.
- Rebased the patch series onto f543926f9d0c3f6dfb354adfe7fbaeedd1277c6b.
- Change the RFC title and modify commit.
rfc v1 -> rfc v2:
- Squashed previous commits into a single patch per Usama Arif's feedback
regarding git bisectability.
Links:
RFC v1: https://lore.kernel.org/linux-mm/20260305202413.1888499-1-usama.arif@linux.dev/T/#m3693d45180f14f441b6951984f4b4bfd90ec0c9d
RFC v2: https://lore.kernel.org/linux-mm/20260306024608.1720991-1-youngjun.park@lge.com/
Thanks,
Youngjun Park
Youngjun Park (2):
mm/swap, PM: hibernate: fix swapoff race in uswsusp by getting swap
reference
mm/swap: remove redundant swap device reference in alloc/free
include/linux/swap.h | 3 +-
kernel/power/swap.c | 2 +-
kernel/power/user.c | 11 +++++--
mm/swapfile.c | 78 +++++++++++++++++++++++---------------------
4 files changed, 52 insertions(+), 42 deletions(-)
--
base-commit: f543926f9d0c3f6dfb354adfe7fbaeedd1277c6b (mm-new)
2.34.1
next reply other threads:[~2026-03-12 11:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 11:25 Youngjun Park [this message]
2026-03-12 11:25 ` [RESEND RFC PATCH v3 1/2] mm/swap, PM: hibernate: fix swapoff race in uswsusp by getting " Youngjun Park
2026-03-13 13:20 ` Kairui Song
2026-03-14 11:48 ` YoungJun Park
2026-03-12 11:25 ` [RESEND RFC PATCH v3 2/2] mm/swap: remove redundant swap device reference in alloc/free Youngjun Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312112511.3596781-1-youngjun.park@lge.com \
--to=youngjun.park@lge.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=bhe@redhat.com \
--cc=chrisl@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=linux-pm@vger.kernel.org \
--cc=nphamcs@gmail.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=shikemeng@huaweicloud.com \
--cc=usama.arif@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox