linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kairui Song <ryncsn@gmail.com>
To: Youngjun Park <youngjun.park@lge.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
	 Kemeng Shi <shikemeng@huaweicloud.com>,
	Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
	 Barry Song <baohua@kernel.org>,
	Jianyue Wu <wujianyue000@gmail.com>,
	her0gyugyu@gmail.com,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] mm, swap: don't free a hibernation slot that is in the swap cache
Date: Sat, 8 Aug 2026 20:09:44 +0800	[thread overview]
Message-ID: <ancWz-4R93dnNOXn@KASONG-MC4> (raw)
In-Reply-To: <20260806190636.446205-2-youngjun.park@lge.com>

On Fri, Aug 07, 2026 at 04:06:33AM +0800, Youngjun Park wrote:
> A slot with a folio in the swap cache is freed when the folio leaves the
> cache, not when its count drops.  swap_put_entries_cluster() follows that
> rule.  swap_free_hibernation_slot() does not, it calls
> __swap_cluster_free_entries() whether or not a folio sits on the slot.
> 
> Cluster readahead can put one there.  It walks a raw page_cluster sized
> window of offsets around the faulting entry, and a hibernation slot passes
> __swap_cache_add_check() because it is not a folio and its count is not
> zero.  Freeing the slot then clears the entry under that folio.
> 
> The folio is now unreachable from the swap table, and the offset goes back
> to the allocator.  The folio is still on the LRU though, so reclaim can
> pick it up later.  It then takes the old offset out of folio->swap and
> overwrites the table entry there, which by then may belong to someone else.
> 
> Check for a cached folio before freeing.  The slot is then left in the
> ordinary state where only the swap cache holds it, and it is freed when the
> folio leaves the cache, either through the reclaim below or through normal
> reclaim later.
> 
> Fixes: 0d6af9bcf383 ("mm, swap: use the swap table to track the swap count")
> Signed-off-by: Youngjun Park <youngjun.park@lge.com>
> ---
>  mm/swapfile.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

Hi Youngjun,

Thanks a lot for looking into the hibernation issue, I've been thinking
about using a exclusive type for it, glad to see actual code for it :)

And this patch looks good to me, nice catch!

Acked-by: Kairui Song <kasong@tencent.com>


  reply	other threads:[~2026-08-08 12:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 19:06 [PATCH 0/4] mm, swap: keep hibernation swap slots out of the swap cache Youngjun Park
2026-08-06 19:06 ` [PATCH 1/4] mm, swap: don't free a hibernation slot that is in " Youngjun Park
2026-08-08 12:09   ` Kairui Song [this message]
2026-08-08 13:26     ` Kairui Song
2026-08-06 19:06 ` [PATCH 2/4] mm, swap: give hibernation swap slots their own swap table entry type Youngjun Park
2026-08-08 13:25   ` Kairui Song
2026-08-06 19:06 ` [PATCH 3/4] mm, swap: only allow swapped-out slots into the swap cache Youngjun Park
2026-08-06 19:06 ` [PATCH 4/4] mm, swap: drop the swap cache guard and reclaim in swap_free_hibernation_slot() 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=ancWz-4R93dnNOXn@KASONG-MC4 \
    --to=ryncsn@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=her0gyugyu@gmail.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=wujianyue000@gmail.com \
    --cc=youngjun.park@lge.com \
    /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;
as well as URLs for NNTP newsgroup(s).