Skip to contentSkip to conversation

mm/damon/core: let kdamond freezable

PATCH In review SJ Park 3 participants 5 messages Nov 28

Subsystems (3)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

PATCH 1/1 mm/damon/core: let kdamond freezable

DAMON's worker threads, kdamonds, are not freezable. If DAMOS is set, it could migrate or reclaim pages while the hibernation image is being copied. It could corrupt the resulting image. As a result the system could run with the corrupted memory after resuming from hibernation.

Users could work around by stopping or pausing the kdamond before the hibernation imaging is started. But it is easy to forget. Just make it freezable.

The user impact is quite bad. Nonetheless, the problem is only found by the theory. No real issue from such memory corruption is found and reported so far.

This change was originally suggested [1] by Lin Ruifeng.

[1] https://lore.kernel.org/[email protected]

Fixes af122dd8f3c0 ("mm/damon/dbgfs: support DAMON-based Operation Schemes")
Cc <[email protected]> # 5.16.x

---
Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
- Rebase to the latest mm-new.
- Drop RFC tag.

 mm/damon/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/core.c +3 -1
index 0e6b361f97ea..f421965d1f58 100644
@@ -7,6 +7,7 @@
 
 #include <linux/damon.h>
 #include <linux/delay.h>
+#include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/memcontrol.h>
 #include <linux/mm.h>
@@ -3845,7 +3846,7 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
 {
 	struct damon_target *t;
 
-	if (kthread_should_stop())
+	if (kthread_freezable_should_stop(NULL))
 		return true;
 
 	if (!ctx->ops.target_valid)
@@ -4056,6 +4057,7 @@ static int kdamond_fn(void *data)
 
 	sz_limit = damon_apply_min_nr_regions(ctx);
 
+	set_freezable();
 	while (!kdamond_need_stop(ctx)) {
 		/*
 		 * ctx->attrs and ctx->next_{aggregation,ops_update}_sis could

base-commit: ba13b07abc534725a32302825071f2c6bd26b033

Signature · 1 line
2.47.3
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

DAMON's worker threads, kdamonds, are not freezable. If DAMOS is set, it could migrate or reclaim pages while the hibernation image is being copied. It could corrupt the resulting image. As a result the system could run with the corrupted memory after resuming from hibernation.

Users could work around by stopping or pausing the kdamond before the hibernation imaging is started. But it is easy to forget. Just make it freezable.

The user impact is quite bad. Nonetheless, the problem is only found by the theory. No real issue from such memory corruption is found and reported so far.

Quoted 8 lines

This change was originally suggested [1] by Lin Ruifeng.

[1] https://lore.kernel.org/[email protected]

Fixes af122dd8f3c0 ("mm/damon/dbgfs: support DAMON-based Operation Schemes")
Cc <[email protected]> # 5.16.x

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to SJ Park
Quoted 1 line · On Sat, 28 Nov 2026 10:43:10 -0800 SJ Park <[email protected]> wrote:

Subject: [PATCH] mm/damon/core: let kdamond freezable

Let's use "make kdamond freezable".

Quoted 20 lines
mm/damon/core.c +2 -1
@@ -7,6 +7,7 @@
 
 #include <linux/damon.h>
 #include <linux/delay.h>
+#include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/memcontrol.h>
 #include <linux/mm.h>
@@ -3845,7 +3846,7 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
 {
 	struct damon_target *t;
 
-	if (kthread_should_stop())
+	if (kthread_freezable_should_stop(NULL))
 		return true;
 
 	if (!ctx->ops.target_valid)

mm/damon/core.c static int kdamond_fn(void *data) · line 4063

Quoted 7 lines
mm/damon/core.c +1 -0
@@ -4056,6 +4057,7 @@ static int kdamond_fn(void *data)
 
 	sz_limit = damon_apply_min_nr_regions(ctx);
 
+	set_freezable();
 	while (!kdamond_need_stop(ctx)) {
 		/*
 		 * ctx->attrs and ctx->next_{aggregation,ops_update}_sis could

Nice.

author maintainer
#3 lore raw
Quoted 5 lines · On Sat, 28 Nov 2026 10:51:38 -0800 Andrew Morton <[email protected]>…
Quoted 1 line · On Sat, 28 Nov 2026 10:43:10 -0800 SJ Park <[email protected]> wrote:

Subject: [PATCH] mm/damon/core: let kdamond freezable

Let's use "make kdamond freezable".

Sounds good, thank you Andrew!

Thanks,
SJ

[...]

maintainer tree notice
#4 lore raw

+ mm-damon-core-let-kdamond-freezable.patch added to mm-hotfixes-unstable branch

In reply to SJ Park
The patch titled Subject: mm/damon/core: make kdamond freezable has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-damon-core-let-kdamond-freezable.patch

The patch titled
Subject: mm/damon/core: make kdamond freezable
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
mm-damon-core-let-kdamond-freezable.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-core-let-kdamond-freezable.patch

This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: SJ Park <[email protected]>
Subject: mm/damon/core: make kdamond freezable
Date: Sat, 28 Nov 2026 10:43:10 -0800

DAMON's worker threads, kdamonds, are not freezable. If DAMOS is set, it could migrate or reclaim pages while the hibernation image is being copied. It could corrupt the resulting image. As a result the system could run with the corrupted memory after resuming from hibernation.

Users could work around by stopping or pausing the kdamond before the hibernation imaging is started. But it is easy to forget. Just make it freezable.

The user impact is quite bad. Nonetheless, the problem is only found by the theory. No real issue from such memory corruption is found and reported so far.

This change was originally suggested [1] by Lin Ruifeng.

Fixes af122dd8f3c0 ("mm/damon/dbgfs: support DAMON-based Operation Schemes")
Cc <[email protected]> # 5.16.x
 mm/damon/core.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-let-kdamond-freezable +3 -1
@@ -7,6 +7,7 @@
 
 #include <linux/damon.h>
 #include <linux/delay.h>
+#include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/memcontrol.h>
 #include <linux/mm.h>
@@ -3845,7 +3846,7 @@ static bool kdamond_need_stop(struct dam
 {
 	struct damon_target *t;
 
-	if (kthread_should_stop())
+	if (kthread_freezable_should_stop(NULL))
 		return true;
 
 	if (!ctx->ops.target_valid)
@@ -4056,6 +4057,7 @@ static int kdamond_fn(void *data)
 
 	sz_limit = damon_apply_min_nr_regions(ctx);
 
+	set_freezable();
 	while (!kdamond_need_stop(ctx)) {
 		/*
 		 * ctx->attrs and ctx->next_{aggregation,ops_update}_sis could

_

Patches currently in -mm which might be from [email protected] are

mm-damon-core-let-kdamond-freezable.patch mm-damon-core-copy-only-installed-probe-in-damon_split_region_at.patch mm-damon-core-add-damos_filter_type_age_ms.patch mm-damon-sysfs-schemes-support-damos_filter_type_age_ms.patch docs-mm-damon-design-update-for-age_ms-damos-core-filter-type.patch docs-admin-guide-mm-damon-usage-update-for-age_ms-damos-core-filter.patch mm-damon-api-define-damon_filter_type_active.patch mm-damon-ops-common-implement-damon_filter_type_active-operation.patch mm-damon-sysfs-support-lru-activeness-based-damon-filter-setup.patch docs-mm-damon-design-update-for-damon_filter_type_active.patch maintainers-change-damon-scm-tree-to-mm-damongit.patch docs-mm-damon-maintainer-profile-use-damongit-for-patch-baselines.patch docs-mm-damon-maintainer-profile-drop-scm-trees-section.patch docs-mm-damon-maintainer-profile-update-key-cycle-dates-for-damongit.patch mm-damon-api-introduce-struct-damon_report.patch mm-damon-core-implement-data-attribute-report-queue.patch mm-damon-core-introduce-damon_submit_report.patch mm-damon-sysfs-add-admin-reports-directory.patch mm-damon-sysfs-add-reports-producers-directory.patch mm-damon-sysfs-add-producers-nr_producers-file.patch mm-damon-sysfs-implement-report-producer-directory.patch mm-damon-sysfs-implement-report-producer-type-and-state-files.patch docs-mm-damon-design-update-for-report-system.patch docs-admin-guide-mm-damon-usage-update-for-report-producer-sysfs.patch docs-abi-damon-update-for-report-producer-sysfs-files.patch mm-damon-core-introduce-damon_filter_type_report_made.patch mm-damon-core-introduce-damon_report_exist.patch mm-damon-paddr-support-report_made-type-probe-filter.patch mm-damon-sysfs-add-filter_report_type-file-under-probe-filter-directory.patch mm-damon-sysfs-support-report_made-type-probe-filter-setup.patch docs-mm-damon-design-update-for-report_made-probe-filter-type.patch docs-admin-guide-mm-damon-usage-update-for-report_made-probe-filter.patch docs-abi-damon-update-for-report_made-probe-filter.patch mm-damon-api-introduce-user_report-report-type.patch mm-damon-sysfs-add-user_report-support-for-report-type-input.patch mm-damon-sysfs-implement-report-producer-addr_startend-files.patch mm-damon-sysfs-implement-submit-command-for-report-producer.patch selftests-damon-sysfssh-add-basic-tests-for-admin-reports.patch docs-mm-damon-design-update-for-user-report-support.patch docs-admin-guide-mm-damon-usage-update-for-user_report-report-support.patch docs-abi-damon-update-for-user_report-report-support.patch