Linux Power Management development
 help / color / mirror / Atom feed
From: Youngjun Park <youngjun.park@lge.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Kairui Song <kasong@tencent.com>, Chris Li <chrisl@kernel.org>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>,
	Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
	Barry Song <baohua@kernel.org>, Pavel Machek <pavel@kernel.org>,
	Len Brown <lenb@kernel.org>,
	linux-mm@kvack.org, linux-pm@vger.kernel.org,
	her0gyugyu@gmail.com, youngjun.park@lge.com,
	taejoon.song@lge.com
Subject: [RFC PATCH 01/10] PM: hibernate: give the image's swap slots back when test_resume fails
Date: Tue, 15 Sep 2026 12:16:49 +0900	[thread overview]
Message-ID: <20260915031658.1505680-2-youngjun.park@lge.com> (raw)
In-Reply-To: <20260915031658.1505680-1-youngjun.park@lge.com>

test_resume writes an image and loads it straight back without powering
off.  When the load fails nothing gives the image's swap slots back.
They stay allocated for as long as the system runs, and swapoff on that
device cannot finish, since the slots belong to no process.

Tested by forcing the restore to fail in test_resume mode.

Fixes: fe12c00d21bb ("PM / hibernate: Introduce test_resume mode for hibernation")
Assisted-by: Claude:claude-fable-5
Signed-off-by: Youngjun Park <youngjun.park@lge.com>
---
 kernel/power/hibernate.c |  6 +++++-
 kernel/power/power.h     |  1 +
 kernel/power/swap.c      | 12 ++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index d2479c69d71a..907d791b85ad 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -857,8 +857,12 @@ int hibernate(void)
 	if (snapshot_test) {
 		pm_pr_dbg("Checking hibernation image\n");
 		error = swsusp_check(false);
-		if (!error)
+		if (!error) {
 			error = load_image_and_restore();
+			/* The image was not used, so free its slots. */
+			if (error)
+				swsusp_free_image_slots();
+		}
 	}
 	thaw_processes();
 
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 75b63843886e..9c398cddd0c3 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -171,6 +171,7 @@ extern void hibernate_release(void);
 extern sector_t alloc_swapdev_block(int swap);
 extern void free_all_swap_pages(int swap);
 extern int swsusp_swap_in_use(void);
+void swsusp_free_image_slots(void);
 
 /*
  * Flags that can be passed from the hibernatig hernel to the "boot" kernel in
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index c78f1593600b..dc65ec409207 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -1612,6 +1612,18 @@ int swsusp_check(bool exclusive)
 	return error;
 }
 
+/**
+ * swsusp_free_image_slots - Give back the swap slots the image was written to.
+ *
+ * For a path that writes an image and then does not resume from it.  Until
+ * the slots are given back they stay allocated, and swapoff on that device
+ * cannot finish either.
+ */
+void swsusp_free_image_slots(void)
+{
+	free_all_swap_pages(root_swap);
+}
+
 /**
  * swsusp_close - close resume device.
  */
-- 
2.48.1


  reply	other threads:[~2026-09-15  3:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  3:16 [RFC PATCH 00/10] mm/swap, PM: hibernate: improve image slot allocation and I/O Youngjun Park
2026-09-15  3:16 ` Youngjun Park [this message]
2026-09-15  3:16 ` [RFC PATCH 02/10] mm, swap: skip swap devices without a block device in hibernation lookups Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 03/10] mm, swap: move hibernation swap code to mm/swap_hibernate.c Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 04/10] mm, swap: skip swap cache reclaim while storage is suspended Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 05/10] mm, swap: hand the hibernation image whole free clusters Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 06/10] mm, swap: hand the image's free clusters out in disk order Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 07/10] PM: hibernate: build one bio per contiguous run of the image Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 08/10] PM: hibernate: read the image back a run at a time Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 09/10] PM: hibernate: tell swap how much space an image needs Youngjun Park
2026-09-15  3:16 ` [RFC PATCH 10/10] mm, swap: hold swap space back for a hibernation image at swapon Youngjun Park
2026-09-29 17:25 ` [RFC PATCH 00/10] mm/swap, PM: hibernate: improve image slot allocation and I/O Kairui Song
2026-10-04 17:39   ` 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=20260915031658.1505680-2-youngjun.park@lge.com \
    --to=youngjun.park@lge.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=lenb@kernel.org \
    --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=taejoon.song@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