linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents
@ 2025-05-13  0:27 SeongJae Park
  2025-05-13  0:27 ` [PATCH 1/6] mm/damon/core: warn and fix nr_accesses[_bp] corruption SeongJae Park
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Brendan Higgins, David Gow, Jonathan Corbet,
	Shuah Khan, damon, kernel-team, kunit-dev, linux-doc,
	linux-kernel, linux-kselftest, linux-mm

Yet another batch of miscellaneous DAMON changes.  Fix and improve minor
problems in code, tests and documents.

SeongJae Park (6):
  mm/damon/core: warn and fix nr_accesses[_bp] corruption
  mm/damon/sysfs-schemes: fix wrong comment on
    damons_sysfs_quota_goal_metric_strs
  mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat()
  mm/damon/tests/core-kunit: add a test for
    damos_set_filters_default_reject()
  selftests/damon/_damon_sysfs: read tried regions directories in order
  Docs/damon: update titles and brief introductions to explain DAMOS

 Documentation/admin-guide/mm/damon/index.rst  | 11 ++-
 Documentation/mm/damon/index.rst              |  6 +-
 mm/damon/core.c                               | 14 ++++
 mm/damon/paddr.c                              |  1 -
 mm/damon/sysfs-schemes.c                      |  2 +-
 mm/damon/tests/core-kunit.h                   | 70 +++++++++++++++++++
 tools/testing/selftests/damon/_damon_sysfs.py |  5 ++
 7 files changed, 98 insertions(+), 11 deletions(-)


base-commit: fb227aa50d133236ef02a71dd9e3d510f4fad42f
-- 
2.39.5



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

* [PATCH 1/6] mm/damon/core: warn and fix nr_accesses[_bp] corruption
  2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
@ 2025-05-13  0:27 ` SeongJae Park
  2025-05-13  0:27 ` [PATCH 2/6] mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs SeongJae Park
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm

For a bug such as double aggregation reset[1], ->nr_accesses and/or
->nr_accesses_bp of damon_region could be corrupted.  Such corruption
can make monitoring results pretty inaccurate, so the root causing bug
should be investigated.  Meanwhile, the corruption itself can easily be
fixed but silently fixing it will hide the bug.

Fix the corruption as soon as found, but WARN_ONCE() so that we can be
aware of the existence of the bug while keeping the system running in a
more sane way.

[1] https://lore.kernel.org/20250302214145.356806-1-sj@kernel.org

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 587fb9a4fef8..0bb71e2ab713 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1391,6 +1391,19 @@ int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control)
 	return 0;
 }
 
+/*
+ * Warn and fix corrupted ->nr_accesses[_bp] for investigations and preventing
+ * the problem being propagated.
+ */
+static void damon_warn_fix_nr_accesses_corruption(struct damon_region *r)
+{
+	if (r->nr_accesses_bp == r->nr_accesses * 10000)
+		return;
+	WARN_ONCE(true, "invalid nr_accesses_bp at reset: %u %u\n",
+			r->nr_accesses_bp, r->nr_accesses);
+	r->nr_accesses_bp = r->nr_accesses * 10000;
+}
+
 /*
  * Reset the aggregated monitoring results ('nr_accesses' of each region).
  */
@@ -1404,6 +1417,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c)
 
 		damon_for_each_region(r, t) {
 			trace_damon_aggregated(ti, r, damon_nr_regions(t));
+			damon_warn_fix_nr_accesses_corruption(r);
 			r->last_nr_accesses = r->nr_accesses;
 			r->nr_accesses = 0;
 		}
-- 
2.39.5



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

* [PATCH 2/6] mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs
  2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
  2025-05-13  0:27 ` [PATCH 1/6] mm/damon/core: warn and fix nr_accesses[_bp] corruption SeongJae Park
@ 2025-05-13  0:27 ` SeongJae Park
  2025-05-13  0:27 ` [PATCH 3/6] mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat() SeongJae Park
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm

A comment on damos_sysfs_quota_goal_metric_strs is simply wrong, due to
a copy-and-paste error.  Fix it.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index c2b8a9cb44ec..0f6c9e1fec0b 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -940,7 +940,7 @@ struct damos_sysfs_quota_goal {
 	int nid;
 };
 
-/* This should match with enum damos_action */
+/* This should match with enum damos_quota_goal_metric */
 static const char * const damos_sysfs_quota_goal_metric_strs[] = {
 	"user_input",
 	"some_mem_psi_us",
-- 
2.39.5



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

* [PATCH 3/6] mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat()
  2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
  2025-05-13  0:27 ` [PATCH 1/6] mm/damon/core: warn and fix nr_accesses[_bp] corruption SeongJae Park
  2025-05-13  0:27 ` [PATCH 2/6] mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs SeongJae Park
@ 2025-05-13  0:27 ` SeongJae Park
  2025-05-13  0:27 ` [PATCH 4/6] mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject() SeongJae Park
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm

Commit c0cb9d91bf297 ("mm/damon/paddr: report filter-passed bytes back
for DAMOS_STAT action") added unused variable in damon_pa_stat(), due to
a copy-and-paste error.  Remove it.

Fixes: c0cb9d91bf297 ("mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action")
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/paddr.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 1b70d3f36046..e8464f7e0014 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -548,7 +548,6 @@ static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s,
 		unsigned long *sz_filter_passed)
 {
 	unsigned long addr;
-	LIST_HEAD(folio_list);
 	struct folio *folio;
 
 	if (!damon_pa_scheme_has_filter(s))
-- 
2.39.5



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

* [PATCH 4/6] mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject()
  2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
                   ` (2 preceding siblings ...)
  2025-05-13  0:27 ` [PATCH 3/6] mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat() SeongJae Park
@ 2025-05-13  0:27 ` SeongJae Park
  2025-05-13  0:27 ` [PATCH 5/6] selftests/damon/_damon_sysfs: read tried regions directories in order SeongJae Park
  2025-05-13  0:27 ` [PATCH 6/6] Docs/damon: update titles and brief introductions to explain DAMOS SeongJae Park
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Brendan Higgins, David Gow, damon, kernel-team,
	kunit-dev, linux-kernel, linux-kselftest, linux-mm

DAMOS filters' default reject behavior is not very simple.  Actually
there was a mistake[1] during the development.  Add a kunit test for
validating the behavior.

[1] https://lore.kernel.org/20250227002913.19359-1-sj@kernel.org

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/tests/core-kunit.h | 70 +++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index be0fea9ee5fc..298c67557fae 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -510,6 +510,75 @@ static void damon_test_feed_loop_next_input(struct kunit *test)
 			damon_feed_loop_next_input(last_input, 2000));
 }
 
+static void damon_test_set_filters_default_reject(struct kunit *test)
+{
+	struct damos scheme;
+	struct damos_filter *target_filter, *anon_filter;
+
+	INIT_LIST_HEAD(&scheme.filters);
+	INIT_LIST_HEAD(&scheme.ops_filters);
+
+	damos_set_filters_default_reject(&scheme);
+	/*
+	 * No filter is installed.  Allow by default on both core and ops layer
+	 * filtering stages, since there are no filters at all.
+	 */
+	KUNIT_EXPECT_EQ(test, scheme.core_filters_default_reject, false);
+	KUNIT_EXPECT_EQ(test, scheme.ops_filters_default_reject, false);
+
+	target_filter = damos_new_filter(DAMOS_FILTER_TYPE_TARGET, true, true);
+	damos_add_filter(&scheme, target_filter);
+	damos_set_filters_default_reject(&scheme);
+	/*
+	 * A core-handled allow-filter is installed.
+	 * Rejct by default on core layer filtering stage due to the last
+	 * core-layer-filter's behavior.
+	 * Allow by default on ops layer filtering stage due to the absence of
+	 * ops layer filters.
+	 */
+	KUNIT_EXPECT_EQ(test, scheme.core_filters_default_reject, true);
+	KUNIT_EXPECT_EQ(test, scheme.ops_filters_default_reject, false);
+
+	target_filter->allow = false;
+	damos_set_filters_default_reject(&scheme);
+	/*
+	 * A core-handled reject-filter is installed.
+	 * Allow by default on core layer filtering stage due to the last
+	 * core-layer-filter's behavior.
+	 * Allow by default on ops layer filtering stage due to the absence of
+	 * ops layer filters.
+	 */
+	KUNIT_EXPECT_EQ(test, scheme.core_filters_default_reject, false);
+	KUNIT_EXPECT_EQ(test, scheme.ops_filters_default_reject, false);
+
+	anon_filter = damos_new_filter(DAMOS_FILTER_TYPE_ANON, true, true);
+	damos_add_filter(&scheme, anon_filter);
+
+	damos_set_filters_default_reject(&scheme);
+	/*
+	 * A core-handled reject-filter and ops-handled allow-filter are installed.
+	 * Allow by default on core layer filtering stage due to the existence
+	 * of the ops-handled filter.
+	 * Reject by default on ops layer filtering stage due to the last
+	 * ops-layer-filter's behavior.
+	 */
+	KUNIT_EXPECT_EQ(test, scheme.core_filters_default_reject, false);
+	KUNIT_EXPECT_EQ(test, scheme.ops_filters_default_reject, true);
+
+	target_filter->allow = true;
+	damos_set_filters_default_reject(&scheme);
+	/*
+	 * A core-handled allow-filter and ops-handled allow-filter are
+	 * installed.
+	 * Allow by default on core layer filtering stage due to the existence
+	 * of the ops-handled filter.
+	 * Reject by default on ops layer filtering stage due to the last
+	 * ops-layer-filter's behavior.
+	 */
+	KUNIT_EXPECT_EQ(test, scheme.core_filters_default_reject, false);
+	KUNIT_EXPECT_EQ(test, scheme.ops_filters_default_reject, true);
+}
+
 static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_target),
 	KUNIT_CASE(damon_test_regions),
@@ -527,6 +596,7 @@ static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damos_test_new_filter),
 	KUNIT_CASE(damos_test_filter_out),
 	KUNIT_CASE(damon_test_feed_loop_next_input),
+	KUNIT_CASE(damon_test_set_filters_default_reject),
 	{},
 };
 
-- 
2.39.5



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

* [PATCH 5/6] selftests/damon/_damon_sysfs: read tried regions directories in order
  2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
                   ` (3 preceding siblings ...)
  2025-05-13  0:27 ` [PATCH 4/6] mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject() SeongJae Park
@ 2025-05-13  0:27 ` SeongJae Park
  2025-05-13  0:27 ` [PATCH 6/6] Docs/damon: update titles and brief introductions to explain DAMOS SeongJae Park
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Shuah Khan, damon, kernel-team, linux-kernel,
	linux-kselftest, linux-mm

Kdamond.update_schemes_tried_regions() reads and stores tried regions
information out of address order.  It makes debugging a test failure
difficult.  Change the behavior to do the reading and writing in the
address order.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 tools/testing/selftests/damon/_damon_sysfs.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index 6e136dc3df19..1e587e0b1a39 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -420,11 +420,16 @@ class Kdamond:
                 tried_regions = []
                 tried_regions_dir = os.path.join(
                         scheme.sysfs_dir(), 'tried_regions')
+                region_indices = []
                 for filename in os.listdir(
                         os.path.join(scheme.sysfs_dir(), 'tried_regions')):
                     tried_region_dir = os.path.join(tried_regions_dir, filename)
                     if not os.path.isdir(tried_region_dir):
                         continue
+                    region_indices.append(int(filename))
+                for region_idx in sorted(region_indices):
+                    tried_region_dir = os.path.join(tried_regions_dir,
+                                                    '%d' % region_idx)
                     region_values = []
                     for f in ['start', 'end', 'nr_accesses', 'age']:
                         content, err = read_file(
-- 
2.39.5



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

* [PATCH 6/6] Docs/damon: update titles and brief introductions to explain DAMOS
  2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
                   ` (4 preceding siblings ...)
  2025-05-13  0:27 ` [PATCH 5/6] selftests/damon/_damon_sysfs: read tried regions directories in order SeongJae Park
@ 2025-05-13  0:27 ` SeongJae Park
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2025-05-13  0:27 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Jonathan Corbet, damon, kernel-team, linux-doc,
	linux-kernel, linux-mm

DAMON was initially developed only for data access monitoring, and then
extended for not only access monitoring but also access-aware system
operations (DAMOS).  But the documents have old titles and brief
introductions for only the monitoring part.  Update the titles and the
brief introductions to explain DAMOS part together.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/admin-guide/mm/damon/index.rst | 11 +++++------
 Documentation/mm/damon/index.rst             |  6 +++---
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/Documentation/admin-guide/mm/damon/index.rst b/Documentation/admin-guide/mm/damon/index.rst
index 33d37bb2fb4e..bc7e976120e0 100644
--- a/Documentation/admin-guide/mm/damon/index.rst
+++ b/Documentation/admin-guide/mm/damon/index.rst
@@ -1,12 +1,11 @@
 .. SPDX-License-Identifier: GPL-2.0
 
-==========================
-DAMON: Data Access MONitor
-==========================
+================================================================
+DAMON: Data Access MONitoring and Access-aware System Operations
+================================================================
 
-:doc:`DAMON </mm/damon/index>` allows light-weight data access monitoring.
-Using DAMON, users can analyze the memory access patterns of their systems and
-optimize those.
+:doc:`DAMON </mm/damon/index>` is a Linux kernel subsystem for efficient data
+access monitoring and access-aware system operations.
 
 .. toctree::
    :maxdepth: 2
diff --git a/Documentation/mm/damon/index.rst b/Documentation/mm/damon/index.rst
index 5a3359704cce..31c1fa955b3d 100644
--- a/Documentation/mm/damon/index.rst
+++ b/Documentation/mm/damon/index.rst
@@ -1,8 +1,8 @@
 .. SPDX-License-Identifier: GPL-2.0
 
-==========================
-DAMON: Data Access MONitor
-==========================
+================================================================
+DAMON: Data Access MONitoring and Access-aware System Operations
+================================================================
 
 DAMON is a Linux kernel subsystem that provides a framework for data access
 monitoring and the monitoring results based system operations.  The core
-- 
2.39.5



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

end of thread, other threads:[~2025-05-13  0:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-13  0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
2025-05-13  0:27 ` [PATCH 1/6] mm/damon/core: warn and fix nr_accesses[_bp] corruption SeongJae Park
2025-05-13  0:27 ` [PATCH 2/6] mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs SeongJae Park
2025-05-13  0:27 ` [PATCH 3/6] mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat() SeongJae Park
2025-05-13  0:27 ` [PATCH 4/6] mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject() SeongJae Park
2025-05-13  0:27 ` [PATCH 5/6] selftests/damon/_damon_sysfs: read tried regions directories in order SeongJae Park
2025-05-13  0:27 ` [PATCH 6/6] Docs/damon: update titles and brief introductions to explain DAMOS SeongJae Park

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