mm/damon: minor fixups and improvements for code, tests, and documents
Subsystems (5)
SeongJae Park
maintainercover mm/damon: minor fixups and improvements for code, tests, and documents
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
Signature · 1 line
2.39.5
SeongJae Park
maintainerPATCH 1/6 mm/damon/core: warn and fix nr_accesses[_bp] corruption
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/[email protected]
--- mm/damon/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
mm/damon/core.c +14 -0
@@ -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 ; }
Signature · 1 line
2.39.5
SeongJae Park
maintainerPATCH 2/6 mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs
In reply to SeongJae ParkA comment on damos_sysfs_quota_goal_metric_strs is simply wrong, due to a copy-and-paste error. Fix it.
--- mm/damon/sysfs-schemes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +1 -1
@@ -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" ,
Signature · 1 line
2.39.5
SeongJae Park
maintainerPATCH 3/6 mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat()
In reply to SeongJae ParkCommit 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.
--- mm/damon/paddr.c | 1 - 1 file changed, 1 deletion(-)
mm/damon/paddr.c +0 -1
@@ -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))
Signature · 1 line
2.39.5
SeongJae Park
maintainerPATCH 4/6 mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject()
In reply to SeongJae ParkDAMOS 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/[email protected]
--- mm/damon/tests/core-kunit.h | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
mm/damon/tests/core-kunit.h +70 -0
@@ -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), {}, };
Signature · 1 line
2.39.5
SeongJae Park
maintainerPATCH 5/6 selftests/damon/_damon_sysfs: read tried regions directories in order
In reply to SeongJae ParkKdamond.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.
--- tools/testing/selftests/damon/_damon_sysfs.py | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/damon/_damon_sysfs.py +5 -0
@@ -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(
Signature · 1 line
2.39.5
SeongJae Park
maintainerPATCH 6/6 Docs/damon: update titles and brief introductions to explain DAMOS
In reply to SeongJae ParkDAMON 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.
--- Documentation/admin-guide/mm/damon/index.rst | 11 +++++------ Documentation/mm/damon/index.rst | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-)
Documentation/admin-guide/mm/damon/index.rst +5 -6
@@ -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
Documentation/mm/damon/index.rst +3 -3
@@ -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
Signature · 1 line
2.39.5