linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Youngjun Park <youngjun.park@lge.com>
Cc: rafael@kernel.org, akpm@linux-foundation.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-pm@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v4 0/3] mm/swap, PM: hibernate: fix swapoff race and optimize swap
Date: Thu, 19 Mar 2026 14:33:30 +0100	[thread overview]
Message-ID: <CAJZ5v0iOh46gM9YVFnvN6bYcG5_kcqASqS+38brRg2BWAtOOzw@mail.gmail.com> (raw)
In-Reply-To: <20260317181318.2517015-1-youngjun.park@lge.com>

On Tue, Mar 17, 2026 at 7:13 PM 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.
>
> 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.
> - Patch 3: Fixes a spurious WARNING in the uswsusp GFP mask restore path.
>   (Founded during uswsusp test)
>
> 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/
> RFC v3: https://lore.kernel.org/linux-mm/20260312112511.3596781-1-youngjun.park@lge.com/
>
> Testing:
> - Hibernate/resume via sysfs
>   (echo reboot > /sys/power/disk && echo disk > /sys/power/state)
> - Hibernate with suspend via sysfs
>   (echo suspend > /sys/power/disk && echo disk > /sys/power/state)
> - Hibernate/resume via uswsusp (suspend-utils s2disk/resume on QEMU)
>   - Verified swap I/O works correctly after resume.
>   - Verified swapoff succeeds after snapshot resume completes.
>   - Verified pm_restore_gfp_mask() WARNING no longer triggers (Patch 3).
> - swapoff during active uswsusp session:
>   - Verified swapoff blocks while uswsusp holds swap reference.
>   - Verified swapoff can be cancelled by signal (e.g. Ctrl+C).
>   - Verified swapoff succeeds after uswsusp process terminates.
>
> Changelog:
> rfc v3 -> v4:
>  - Introduced get/find/put_hibernation_swap_type() helpers per Kairui's
>    feedback. find_ for lookup-only, get/put for reference management.
>  - Switched to swap_type_to_info() and added type < 0 check per
>    Kairui's suggestion.
>  - Fixed get_hibernation_swap_type() return when ref == false (Reviewd by Kairui)
>  - Made swapoff wait interruptible to prevent hang when uswsusp
>    holds a swap reference.
>  - Fixed spurious WARN_ON in pm_restore_gfp_mask() by introducing
>    pm_restore_gfp_mask_safe() (Patch 3).
>  - Updated commit messages and added comments for clarity.
>  - Rebased onto latest mm-new tree.
>
>  Note: Kairui suggested adding WARN on NULL in put_hibernation_swap_type(),
>  but kept silent return instead, as type can legitimately be -1 when
>  snapshot_open() fails to find a matching swap device. swap_type_to_info()
>  returns NULL for type < 0, so the cleanup path stays simple.
>
> rfc v2 -> rfc v3:
>  - Split into 2 patches per Chris Li's feedback.
>  - Simplified by not holding reference in normal hibernation path
>    per Chris Li's suggestion.
>  - Removed redundant SWP_WRITEOK check.
>  - Rebased onto f543926f9d0c3f6dfb354adfe7fbaeedd1277c6b.
>
> rfc v1 -> rfc v2:
>  - Squashed into single patch per Usama Arif's feedback.
>
> Youngjun Park (3):
>   mm/swap, PM: hibernate: fix swapoff race in uswsusp by getting swap
>     reference
>   mm/swap: remove redundant swap device reference in alloc/free
>   PM: hibernate: fix spurious GFP mask WARNING in uswsusp path
>
>  include/linux/suspend.h |   1 +
>  include/linux/swap.h    |   4 +-
>  kernel/power/main.c     |   7 ++
>  kernel/power/swap.c     |   2 +-
>  kernel/power/user.c     |  19 +++--
>  mm/swapfile.c           | 154 +++++++++++++++++++++++++++-------------
>  6 files changed, 132 insertions(+), 55 deletions(-)
>
> --

Which kernel version does this series apply to?

It doesn't apply for me on top of 7.0-rc4, so please consider rebasing.


  parent reply	other threads:[~2026-03-19 13:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 18:13 Youngjun Park
2026-03-17 18:13 ` [PATCH v4 1/3] mm/swap, PM: hibernate: fix swapoff race in uswsusp by getting swap reference Youngjun Park
2026-03-19 16:34   ` Kairui Song
2026-03-20  7:59     ` YoungJun Park
2026-03-17 18:13 ` [PATCH v4 2/3] mm/swap: remove redundant swap device reference in alloc/free Youngjun Park
2026-03-17 18:13 ` [PATCH v4 3/3] PM: hibernate: fix spurious GFP mask WARNING in uswsusp path Youngjun Park
2026-03-17 19:16 ` [PATCH v4 0/3] mm/swap, PM: hibernate: fix swapoff race and optimize swap Andrew Morton
2026-03-18  2:16   ` YoungJun Park
2026-03-19 13:33 ` Rafael J. Wysocki [this message]
2026-03-19 13:48   ` 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=CAJZ5v0iOh46gM9YVFnvN6bYcG5_kcqASqS+38brRg2BWAtOOzw@mail.gmail.com \
    --to=rafael@kernel.org \
    --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=shikemeng@huaweicloud.com \
    --cc=usama.arif@linux.dev \
    --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