mm/damon/sysfs: free setup failures generated zombie sub-sub dirs
Subsystems (3)
SeongJae Park
maintainercover 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
SeongJae Park
maintainerPATCH 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.
--- mm/damon/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs.c +3 -1
@@ -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
SeongJae Park
maintainerPATCH 2/4 mm/damon/sysfs: cleanup attrs subdirs on context dir setup failure
In reply to SeongJae ParkWhen 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.
--- mm/damon/sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +3 -2
@@ -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
SeongJae Park
maintainerPATCH 3/4 mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme dir setup failure
In reply to SeongJae ParkWhen 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.
--- mm/damon/sysfs-schemes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/sysfs-schemes.c +3 -2
@@ -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
SeongJae Park
maintainerPATCH 4/4 mm/damon/sysfs-scheme: cleanup access_pattern subdirs on scheme dir setup failure
In reply to SeongJae ParkWhen 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.
--- mm/damon/sysfs-schemes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/sysfs-schemes.c +3 -2
@@ -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
SeongJae Park
maintainerHello 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
[...]
Andrew Morton
maintainerQuoted 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.