linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] mm/damon/sysfs: free setup failures generated zombie sub-sub dirs
@ 2025-12-25  2:30 SeongJae Park
  2025-12-25  2:30 ` [PATCH 1/4] mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure SeongJae Park
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: SeongJae Park @ 2025-12-25  2:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, # 5 . 18 . x, Jiapeng Chong, damon, linux-kernel,
	linux-mm

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
-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure
  2025-12-25  2:30 [PATCH 0/4] mm/damon/sysfs: free setup failures generated zombie sub-sub dirs SeongJae Park
@ 2025-12-25  2:30 ` SeongJae Park
  2025-12-25  2:30 ` [PATCH 2/4] mm/damon/sysfs: cleanup attrs subdirs on context " SeongJae Park
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-12-25  2:30 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, # 6 . 15 . x, damon, linux-kernel, linux-mm

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: <stable@vger.kernel.org> # 6.15.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index e2bd2d7becdd..a669de068770 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -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;
-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] mm/damon/sysfs: cleanup attrs subdirs on context dir setup failure
  2025-12-25  2:30 [PATCH 0/4] mm/damon/sysfs: free setup failures generated zombie sub-sub dirs SeongJae Park
  2025-12-25  2:30 ` [PATCH 1/4] mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure SeongJae Park
@ 2025-12-25  2:30 ` SeongJae Park
  2025-12-25  2:30 ` [PATCH 3/4] mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme " SeongJae Park
  2025-12-25  2:30 ` [PATCH 4/4] mm/damon/sysfs-scheme: cleanup access_pattern " SeongJae Park
  3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-12-25  2:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, # 5 . 18 . x, Jiapeng Chong, damon, linux-kernel,
	linux-mm

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: <stable@vger.kernel.org> # 5.18.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index a669de068770..95fd9375a7d8 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -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;
-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme dir setup failure
  2025-12-25  2:30 [PATCH 0/4] mm/damon/sysfs: free setup failures generated zombie sub-sub dirs SeongJae Park
  2025-12-25  2:30 ` [PATCH 1/4] mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure SeongJae Park
  2025-12-25  2:30 ` [PATCH 2/4] mm/damon/sysfs: cleanup attrs subdirs on context " SeongJae Park
@ 2025-12-25  2:30 ` SeongJae Park
  2025-12-25  2:30 ` [PATCH 4/4] mm/damon/sysfs-scheme: cleanup access_pattern " SeongJae Park
  3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-12-25  2:30 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, # 5 . 18 . x, damon, linux-kernel, linux-mm

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: <stable@vger.kernel.org> # 5.18.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index e198234f0763..7f14e0d3e7a0 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -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:
-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] mm/damon/sysfs-scheme: cleanup access_pattern subdirs on scheme dir setup failure
  2025-12-25  2:30 [PATCH 0/4] mm/damon/sysfs: free setup failures generated zombie sub-sub dirs SeongJae Park
                   ` (2 preceding siblings ...)
  2025-12-25  2:30 ` [PATCH 3/4] mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme " SeongJae Park
@ 2025-12-25  2:30 ` SeongJae Park
  3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-12-25  2:30 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, # 5 . 18 . x, damon, linux-kernel, linux-mm

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: <stable@vger.kernel.org> # 5.18.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 7f14e0d3e7a0..19bc2288cd68 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -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;
-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-12-25  2:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-25  2:30 [PATCH 0/4] mm/damon/sysfs: free setup failures generated zombie sub-sub dirs SeongJae Park
2025-12-25  2:30 ` [PATCH 1/4] mm/damon/sysfs: cleanup intervals subdirs on attrs dir setup failure SeongJae Park
2025-12-25  2:30 ` [PATCH 2/4] mm/damon/sysfs: cleanup attrs subdirs on context " SeongJae Park
2025-12-25  2:30 ` [PATCH 3/4] mm/damon/sysfs-scheme: cleanup quotas subdirs on scheme " SeongJae Park
2025-12-25  2:30 ` [PATCH 4/4] mm/damon/sysfs-scheme: cleanup access_pattern " SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox