Skip to contentSkip to conversation

mm/damon/sysfs: free setup failures generated zombie sub-sub dirs

PATCH Applied SeongJae Park 2 participants 7 messages Dec 25, 2025 – Jan 3

Subsystems (3)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon/sysfs: free setup failures generated zombie sub-sub dirs

Some DAMON sysfs directory setup functions generates its sub and sub-sub directories. For example, 'monitoring_attrs/' directory setup creates 'intervals/' and 'intervals/intervals_goal/' directories under 'monitoring_attrs/' directory. When such sub-sub directories are successfully made but followup setup is failed, the setup function should recursively clean up the subdirectories.

However, such setup functions are only dereferencing sub directory reference counters. As a result, under certain setup failures, the
sub-sub directories keep having non-zero reference counters. It means
the directories cannot be removed like zombies, and the memory for the directories cannot be freed.

The user impact of this issue is limited due to the following reasons.

When the issue happens, the zombie directories are still taking the path. Hence attempts to generate the directories again will fail, without additional memory leak. This means the upper bound memory leak is limited. Nonetheless this also implies controlling DAMON with a feature that requires the setup-failed sysfs files will be impossible until the system reboots.

Also, the setup operations are quite simple. The certain failures would hence only rarely happen, and are difficult to artificially trigger.

SeongJae Park (4):
mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure mm/damon/sysfs: cleanup attrs subdirs on context dir setup failure mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme dir setup
failure
mm/damon/sysfs-scheme: cleanup access_pattern subdirs on scheme dir
setup failure

 mm/damon/sysfs-schemes.c | 10 ++++++----
 mm/damon/sysfs.c         |  9 ++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

base-commit: 6d039da6a260dd7919bebc70ebb65d250bb9c24e

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/4 mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure

When attrs/ DAMON sysfs directory setup is failed after setup of intervals/ directory, intervals/intervals_goal/ directory is not cleaned up. As a result, DAMON sysfs interface is nearly broken until the system reboots, and the memory for the unremoved directory is leaked.

Cleanup the directory under such failures.

Fixes 8fbbcbeaafeb ("mm/damon/sysfs: implement intervals tuning goal directory")
Cc <[email protected]> # 6.15.x
---
 mm/damon/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs.c +3 -1
index e2bd2d7becdd..a669de068770 100644
@@ -792,7 +792,7 @@ static int damon_sysfs_attrs_add_dirs(struct damon_sysfs_attrs *attrs)
 	nr_regions_range = damon_sysfs_ul_range_alloc(10, 1000);
 	if (!nr_regions_range) {
 		err = -ENOMEM;
-		goto put_intervals_out;
+		goto rmdir_put_intervals_out;
 	}
 
 	err = kobject_init_and_add(&nr_regions_range->kobj,
@@ -806,6 +806,8 @@ static int damon_sysfs_attrs_add_dirs(struct damon_sysfs_attrs *attrs)
 put_nr_regions_intervals_out:
 	kobject_put(&nr_regions_range->kobj);
 	attrs->nr_regions_range = NULL;
+rmdir_put_intervals_out:
+	damon_sysfs_intervals_rm_dirs(intervals);
 put_intervals_out:
 	kobject_put(&intervals->kobj);
 	attrs->intervals = NULL;
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 2/4 mm/damon/sysfs: cleanup attrs subdirs on context dir setup failure

In reply to SeongJae Park

When a context DAMON sysfs directory setup is failed after setup of attrs/ directory, subdirectories of attrs/ directory are not cleaned up. As a result, DAMON sysfs interface is nearly broken until the system reboots, and the memory for the unremoved directory is leaked.

Cleanup the directories under such failures.

Fixes c951cd3b8901 ("mm/damon: implement a minimal stub for sysfs-based DAMON interface")
Cc <[email protected]> # 5.18.x
---
 mm/damon/sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +3 -2
index a669de068770..95fd9375a7d8 100644
@@ -950,7 +950,7 @@ static int damon_sysfs_context_add_dirs(struct damon_sysfs_context *context)
 
 	err = damon_sysfs_context_set_targets(context);
 	if (err)
-		goto put_attrs_out;
+		goto rmdir_put_attrs_out;
 
 	err = damon_sysfs_context_set_schemes(context);
 	if (err)
@@ -960,7 +960,8 @@ static int damon_sysfs_context_add_dirs(struct damon_sysfs_context *context)
 put_targets_attrs_out:
 	kobject_put(&context->targets->kobj);
 	context->targets = NULL;
-put_attrs_out:
+rmdir_put_attrs_out:
+	damon_sysfs_attrs_rm_dirs(context->attrs);
 	kobject_put(&context->attrs->kobj);
 	context->attrs = NULL;
 	return err;
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 3/4 mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme dir setup failure

In reply to SeongJae Park

When a DAMOS-scheme DAMON sysfs directory setup fails after setup of quotas/ directory, subdirectories of quotas/ directory are not cleaned up. As a result, DAMON sysfs interface is nearly broken until the system reboots, and the memory for the unremoved directory is leaked.

Cleanup the directories under such failures.

Fixes 1b32234ab087 ("mm/damon/sysfs: support DAMOS watermarks")
Cc <[email protected]> # 5.18.x
---
 mm/damon/sysfs-schemes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/sysfs-schemes.c +3 -2
index e198234f0763..7f14e0d3e7a0 100644
@@ -2199,7 +2199,7 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 		goto put_dests_out;
 	err = damon_sysfs_scheme_set_watermarks(scheme);
 	if (err)
-		goto put_quotas_access_pattern_out;
+		goto rmdir_put_quotas_access_pattern_out;
 	err = damos_sysfs_set_filter_dirs(scheme);
 	if (err)
 		goto put_watermarks_quotas_access_pattern_out;
@@ -2224,7 +2224,8 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 put_watermarks_quotas_access_pattern_out:
 	kobject_put(&scheme->watermarks->kobj);
 	scheme->watermarks = NULL;
-put_quotas_access_pattern_out:
+rmdir_put_quotas_access_pattern_out:
+	damon_sysfs_quotas_rm_dirs(scheme->quotas);
 	kobject_put(&scheme->quotas->kobj);
 	scheme->quotas = NULL;
 put_dests_out:
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 4/4 mm/damon/sysfs-scheme: cleanup access_pattern subdirs on scheme dir setup failure

In reply to SeongJae Park

When a DAMOS-scheme DAMON sysfs directory setup fails after setup of access_pattern/ directory, subdirectories of access_pattern/ directory are not cleaned up. As a result, DAMON sysfs interface is nearly broken until the system reboots, and the memory for the unremoved directory is leaked.

Cleanup the directories under such failures.

Fixes 9bbb820a5bd5 ("mm/damon/sysfs: support DAMOS quotas")
Cc <[email protected]> # 5.18.x
---
 mm/damon/sysfs-schemes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/sysfs-schemes.c +3 -2
index 7f14e0d3e7a0..19bc2288cd68 100644
@@ -2193,7 +2193,7 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 		return err;
 	err = damos_sysfs_set_dests(scheme);
 	if (err)
-		goto put_access_pattern_out;
+		goto rmdir_put_access_pattern_out;
 	err = damon_sysfs_scheme_set_quotas(scheme);
 	if (err)
 		goto put_dests_out;
@@ -2231,7 +2231,8 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 put_dests_out:
 	kobject_put(&scheme->dests->kobj);
 	scheme->dests = NULL;
-put_access_pattern_out:
+rmdir_put_access_pattern_out:
+	damon_sysfs_access_pattern_rm_dirs(scheme->access_pattern);
 	kobject_put(&scheme->access_pattern->kobj);
 	scheme->access_pattern = NULL;
 	return err;
Signature · 1 line
2.47.3
author maintainer
#5 lore raw
In reply to SeongJae Park

Hello Andrew, happy new year!

Quoted 22 lines · On Wed, 24 Dec 2025 18:30:33 -0800 SeongJae Park <[email protected]> wrote:

Some DAMON sysfs directory setup functions generates its sub and sub-sub directories. For example, 'monitoring_attrs/' directory setup creates 'intervals/' and 'intervals/intervals_goal/' directories under 'monitoring_attrs/' directory. When such sub-sub directories are successfully made but followup setup is failed, the setup function should recursively clean up the subdirectories.

However, such setup functions are only dereferencing sub directory reference counters. As a result, under certain setup failures, the
sub-sub directories keep having non-zero reference counters. It means
the directories cannot be removed like zombies, and the memory for the directories cannot be freed.

The user impact of this issue is limited due to the following reasons.

When the issue happens, the zombie directories are still taking the path. Hence attempts to generate the directories again will fail, without additional memory leak. This means the upper bound memory leak is limited. Nonetheless this also implies controlling DAMON with a feature that requires the setup-failed sysfs files will be impossible until the system reboots.

Quoted 2 lines

Also, the setup operations are quite simple. The certain failures would hence only rarely happen, and are difficult to artificially trigger.

The user impact of the bugs is limited as explained above, but the bugs exist in the code for real world usages. I therefore expected this series would be added to mm-hotfixes-unstable.

Do you have any concern at treating this series as hotfixes? If not, could you please move this series into mm-hotfixes-unstable?

Thanks,
SJ

[...]

maintainer
#6 lore raw
Quoted 9 lines · On Fri, 2 Jan 2026 16:21:37 -0800 SeongJae Park <[email protected]> wrote:
Quoted 2 lines

Also, the setup operations are quite simple. The certain failures would hence only rarely happen, and are difficult to artificially trigger.

The user impact of the bugs is limited as explained above, but the bugs exist in the code for real world usages. I therefore expected this series would be added to mm-hotfixes-unstable.

Do you have any concern at treating this series as hotfixes? If not, could you please move this series into mm-hotfixes-unstable?

Sure, I have made that change.