From: YoungJun Park <youngjun.park@lge.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: rafael@kernel.org, chrisl@kernel.org, kasong@tencent.com,
pavel@kernel.org, shikemeng@huaweicloud.com, nphamcs@gmail.com,
bhe@redhat.com, baohua@kernel.org, usama.arif@linux.dev,
linux-mm@kvack.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v5 0/3] Fix swapoff race and cleanup in hibernation swap path
Date: Fri, 20 Mar 2026 18:49:06 +0900 [thread overview]
Message-ID: <ab0YEn+Fd41q6LM7@yjaykim-PowerEdge-T330> (raw)
In-Reply-To: <20260319195032.5c3b187d5779cf43cd63fcd0@linux-foundation.org>
On Thu, Mar 19, 2026 at 07:50:32PM -0700, Andrew Morton wrote:
> On Thu, 19 Mar 2026 23:24:01 +0900 Youngjun Park <youngjun.park@lge.com> wrote:
>
> > 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.
>
> AI review has questions:
> https://sashiko.dev/#/patchset/20260319142404.3683019-1-youngjun.park%40lge.com
Hi Andrew,
Thanks for sharing the AI review. Some comments are indeed good catches.
patch 2 comments are wrong.
patch 3 comments are right.
Regarding patch 2, the AI review raised the following concerns:
> If this race occurs, swapoff clears SWP_WRITEOK and calls try_to_unuse()
> to scan and evict swap slots. Without the SWP_WRITEOK check here, it
> looks like uswsusp could successfully allocate slots while
> try_to_unuse() is actively scanning.
Right. but..
> If try_to_unuse() encounters these newly allocated slots, wouldn't it
> attempt to page them in and subsequently free them via
> folio_free_swap()?
I believe this concern is not valid.
swapoff calls try_to_unuse(), which scans swap_map[] entries:
(this logic is slightly different from each kerenl version but, fundamental is same)
...
for (i = prev + 1; i < si->max; i++) {
count = READ_ONCE(si->swap_map[i]);
if (count && swap_count(count) != SWAP_MAP_BAD)
break;
}
...
However, hibernation allocations marked with SWAP_HAS_CACHE are not
visible via this swap_map[] scanning logic, so they cannot be found
or reclaimed in that path.
As a result swapoff keeps retrying while swap_usage_in_pages(si) is
non-zero until user signal is delivered., rather than freeing those entrie.
I will also verify this behavior at runtime to be absolutely sure.
For patch 3, I agree with the comment and have responded in Rafael’s
thread.
I will update the series shortly.
Thanks,
Youngjun Park
prev parent reply other threads:[~2026-03-20 9:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 14:24 [PATCH v5 0/3] Fix swapoff race and cleanup in hibernation swap path Youngjun Park
2026-03-19 14:24 ` [PATCH v5 1/3] mm/swap, PM: hibernate: fix swapoff race in uswsusp by getting swap reference Youngjun Park
2026-03-19 14:24 ` [PATCH v5 2/3] mm/swap: remove redundant swap device reference in alloc/free Youngjun Park
2026-03-19 14:24 ` [PATCH v5 3/3] PM: hibernate: fix spurious GFP mask WARNING in uswsusp path Youngjun Park
2026-03-19 19:55 ` Rafael J. Wysocki
2026-03-20 8:18 ` YoungJun Park
2026-03-20 2:50 ` [PATCH v5 0/3] Fix swapoff race and cleanup in hibernation swap path Andrew Morton
2026-03-20 9:49 ` YoungJun Park [this message]
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=ab0YEn+Fd41q6LM7@yjaykim-PowerEdge-T330 \
--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