linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mm/damon: misc fixes
@ 2023-01-19  1:38 SeongJae Park
  2023-01-19  1:38 ` [PATCH 1/3] mm/damon: update comments in damon.h for damon_attrs SeongJae Park
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SeongJae Park @ 2023-01-19  1:38 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, linux-mm, linux-kernel

This patchset contains three miscellaneous simple fixes for DAMON online
tuning.

SeongJae Park (3):
  mm/damon: update comments in damon.h for damon_attrs
  mm/damon/core: update monitoring results for new monitoring attributes
  mm/damon/core-test: add a test for damon_update_monitoring_results()

 include/linux/damon.h |  6 ++--
 mm/damon/core-test.h  | 30 ++++++++++++++++++
 mm/damon/core.c       | 71 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 3 deletions(-)

-- 
2.25.1



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

* [PATCH 1/3] mm/damon: update comments in damon.h for damon_attrs
  2023-01-19  1:38 [PATCH 0/3] mm/damon: misc fixes SeongJae Park
@ 2023-01-19  1:38 ` SeongJae Park
  2023-01-19  1:38 ` [PATCH 2/3] mm/damon/core: update monitoring results for new monitoring attributes SeongJae Park
  2023-01-19  1:38 ` [PATCH 3/3] mm/damon/core-test: add a test for damon_update_monitoring_results() SeongJae Park
  2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-01-19  1:38 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, linux-mm, linux-kernel

Commit cbeaa77b0449 ("mm/damon/core: use a dedicated struct for
monitoring attributes") moved monitoring intervals from damon_ctx to a
new struct, damon_attrs, but a comment in the header file has not
updated for the change.  Update it.

Fixes: cbeaa77b0449 ("mm/damon/core: use a dedicated struct for monitoring attributes")
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 include/linux/damon.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index dfb245bb3053..d5d4d19928e0 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -354,10 +354,10 @@ struct damon_ctx;
  * users should register the low level operations for their target address
  * space and usecase via the &damon_ctx.ops.  Then, the monitoring thread
  * (&damon_ctx.kdamond) calls @init and @prepare_access_checks before starting
- * the monitoring, @update after each &damon_ctx.ops_update_interval, and
+ * the monitoring, @update after each &damon_attrs.ops_update_interval, and
  * @check_accesses, @target_valid and @prepare_access_checks after each
- * &damon_ctx.sample_interval.  Finally, @reset_aggregated is called after each
- * &damon_ctx.aggr_interval.
+ * &damon_attrs.sample_interval.  Finally, @reset_aggregated is called after
+ * each &damon_attrs.aggr_interval.
  *
  * Each &struct damon_operations instance having valid @id can be registered
  * via damon_register_ops() and selected by damon_select_ops() later.
-- 
2.25.1



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

* [PATCH 2/3] mm/damon/core: update monitoring results for new monitoring attributes
  2023-01-19  1:38 [PATCH 0/3] mm/damon: misc fixes SeongJae Park
  2023-01-19  1:38 ` [PATCH 1/3] mm/damon: update comments in damon.h for damon_attrs SeongJae Park
@ 2023-01-19  1:38 ` SeongJae Park
  2023-01-19  1:38 ` [PATCH 3/3] mm/damon/core-test: add a test for damon_update_monitoring_results() SeongJae Park
  2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-01-19  1:38 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, linux-mm, linux-kernel

region->nr_accesses is the number of sampling intervals in the last
aggregation interval that access to the region has found, and
region->age is the number of aggregation intervals that its access
pattern has maintained.  Hence, the real meaning of the two fields'
values is depending on current sampling and aggregation intervals.

This means the values need to be updated for every sampling and/or
aggregation intervals updates.  As DAMON core doesn't, it is a duty of
in-kernel DAMON framework applications like DAMON sysfs interface, or
the userspace users.

Handling it in userspace or in-kernel DAMON application is complicated,
inefficient, and repetitive compared to doing the update in DAMON core.
Do the update in DAMON core.

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

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 2db8c53491ca..d9ef62047bf5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -465,6 +465,76 @@ void damon_destroy_ctx(struct damon_ctx *ctx)
 	kfree(ctx);
 }
 
+static unsigned int damon_age_for_new_attrs(unsigned int age,
+		struct damon_attrs *old_attrs, struct damon_attrs *new_attrs)
+{
+	return age * old_attrs->aggr_interval / new_attrs->aggr_interval;
+}
+
+/* convert access ratio in bp (per 10,000) to nr_accesses */
+static unsigned int damon_accesses_bp_to_nr_accesses(
+		unsigned int accesses_bp, struct damon_attrs *attrs)
+{
+	unsigned int max_nr_accesses =
+		attrs->aggr_interval / attrs->sample_interval;
+
+	return accesses_bp * max_nr_accesses / 10000;
+}
+
+/* convert nr_accesses to access ratio in bp (per 10,000) */
+static unsigned int damon_nr_accesses_to_accesses_bp(
+		unsigned int nr_accesses, struct damon_attrs *attrs)
+{
+	unsigned int max_nr_accesses =
+		attrs->aggr_interval / attrs->sample_interval;
+
+	return nr_accesses * 10000 / max_nr_accesses;
+}
+
+static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses,
+		struct damon_attrs *old_attrs, struct damon_attrs *new_attrs)
+{
+	return damon_accesses_bp_to_nr_accesses(
+			damon_nr_accesses_to_accesses_bp(
+				nr_accesses, old_attrs),
+			new_attrs);
+}
+
+static void damon_update_monitoring_result(struct damon_region *r,
+		struct damon_attrs *old_attrs, struct damon_attrs *new_attrs)
+{
+	r->nr_accesses = damon_nr_accesses_for_new_attrs(r->nr_accesses,
+			old_attrs, new_attrs);
+	r->age = damon_age_for_new_attrs(r->age, old_attrs, new_attrs);
+}
+
+/*
+ * region->nr_accesses is the number of sampling intervals in the last
+ * aggregation interval that access to the region has found, and region->age is
+ * the number of aggregation intervals that its access pattern has maintained.
+ * For the reason, the real meaning of the two fields depend on current
+ * sampling interval and aggregation interval.  This function updates
+ * ->nr_accesses and ->age of given damon_ctx's regions for new damon_attrs.
+ */
+static void damon_update_monitoring_results(struct damon_ctx *ctx,
+		struct damon_attrs *new_attrs)
+{
+	struct damon_attrs *old_attrs = &ctx->attrs;
+	struct damon_target *t;
+	struct damon_region *r;
+
+	/* if any interval is zero, simply forgive conversion */
+	if (!old_attrs->sample_interval || !old_attrs->aggr_interval ||
+			!new_attrs->sample_interval ||
+			!new_attrs->aggr_interval)
+		return;
+
+	damon_for_each_target(t, ctx)
+		damon_for_each_region(r, t)
+			damon_update_monitoring_result(
+					r, old_attrs, new_attrs);
+}
+
 /**
  * damon_set_attrs() - Set attributes for the monitoring.
  * @ctx:		monitoring context
@@ -482,6 +552,7 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
 	if (attrs->min_nr_regions > attrs->max_nr_regions)
 		return -EINVAL;
 
+	damon_update_monitoring_results(ctx, attrs);
 	ctx->attrs = *attrs;
 	return 0;
 }
-- 
2.25.1



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

* [PATCH 3/3] mm/damon/core-test: add a test for damon_update_monitoring_results()
  2023-01-19  1:38 [PATCH 0/3] mm/damon: misc fixes SeongJae Park
  2023-01-19  1:38 ` [PATCH 1/3] mm/damon: update comments in damon.h for damon_attrs SeongJae Park
  2023-01-19  1:38 ` [PATCH 2/3] mm/damon/core: update monitoring results for new monitoring attributes SeongJae Park
@ 2023-01-19  1:38 ` SeongJae Park
  2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-01-19  1:38 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, brendanhiggins, kunit-dev, damon, linux-mm, linux-kernel

Add a simple unit test for damon_update_monitoring_results() function.

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

diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index 3db9b7368756..fae64d32b925 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -289,6 +289,35 @@ static void damon_test_set_regions(struct kunit *test)
 	damon_destroy_target(t);
 }
 
+static void damon_test_update_monitoring_result(struct kunit *test)
+{
+	struct damon_attrs old_attrs = {
+		.sample_interval = 10, .aggr_interval = 1000,};
+	struct damon_attrs new_attrs;
+	struct damon_region *r = damon_new_region(3, 7);
+
+	r->nr_accesses = 15;
+	r->age = 20;
+
+	new_attrs = (struct damon_attrs){
+		.sample_interval = 100, .aggr_interval = 10000,};
+	damon_update_monitoring_result(r, &old_attrs, &new_attrs);
+	KUNIT_EXPECT_EQ(test, r->nr_accesses, 15);
+	KUNIT_EXPECT_EQ(test, r->age, 2);
+
+	new_attrs = (struct damon_attrs){
+		.sample_interval = 1, .aggr_interval = 1000};
+	damon_update_monitoring_result(r, &old_attrs, &new_attrs);
+	KUNIT_EXPECT_EQ(test, r->nr_accesses, 150);
+	KUNIT_EXPECT_EQ(test, r->age, 2);
+
+	new_attrs = (struct damon_attrs){
+		.sample_interval = 1, .aggr_interval = 100};
+	damon_update_monitoring_result(r, &old_attrs, &new_attrs);
+	KUNIT_EXPECT_EQ(test, r->nr_accesses, 150);
+	KUNIT_EXPECT_EQ(test, r->age, 20);
+}
+
 static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_target),
 	KUNIT_CASE(damon_test_regions),
@@ -299,6 +328,7 @@ static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_split_regions_of),
 	KUNIT_CASE(damon_test_ops_registration),
 	KUNIT_CASE(damon_test_set_regions),
+	KUNIT_CASE(damon_test_update_monitoring_result),
 	{},
 };
 
-- 
2.25.1



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

end of thread, other threads:[~2023-01-19  1:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-19  1:38 [PATCH 0/3] mm/damon: misc fixes SeongJae Park
2023-01-19  1:38 ` [PATCH 1/3] mm/damon: update comments in damon.h for damon_attrs SeongJae Park
2023-01-19  1:38 ` [PATCH 2/3] mm/damon/core: update monitoring results for new monitoring attributes SeongJae Park
2023-01-19  1:38 ` [PATCH 3/3] mm/damon/core-test: add a test for damon_update_monitoring_results() SeongJae Park

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