Skip to contentSkip to conversation

mm/damon: improvements in efficiency, error handling, documents

PATCH Applied SJ Park 2 participants 9 messages Sep 21

Subsystems (2)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

cover mm/damon: improvements in efficiency, error handling, documents

Four various improvements. Patch 1 from Liew Rui Yan skips unnecessary quota setup work when relevant. Patch 2 from Xuewen Wang propagates ignored damon_call() error to sysfs users. Patch 3 from Adrian Huang (Lenovo) fixes typos in comments. Patch 4 from Karthikeyan KS clarifies zero sample interval acceptance on kernel-doc comment.

---
Note: this is a batched reposting of DAMON patches that were individually posted and reviewed by the DAMON maintainer.

Adrian Huang (Lenovo) (1):
mm/damon: fix typos in comments

Karthikeyan KS (1):
mm/damon: document that a zero sample_interval is accepted

Liew Rui Yan (1):
mm/damon/core: skip quota score setup when the quota is full

Xuewen Wang (1):
mm/damon/sysfs: propagate damon_call() error in turn_damon_on

 include/linux/damon.h | 3 ++-
 mm/damon/core.c       | 8 +++++---
 mm/damon/lru_sort.c   | 2 +-
 mm/damon/sysfs.c      | 3 ++-
 4 files changed, 10 insertions(+), 6 deletions(-)

base-commit: 05b2dd9725f76b0024d387ed2226d1ab531620ce

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/4 mm/damon/core: skip quota score setup when the quota is full

From: Liew Rui Yan <[email protected]>

In damos_adjust_quota(), the quota could already be full.

In this situation, damos_adjust_quota() will still calculates quota->min_score. However, this min_score will not be used in this window, because in damon_do_apply_schemes(), damos_quota_is_full() will always returns true, preventing the scheme from being applied to any region.

Therefore, add a short circuit for 'esz < min_region_sz' schemes to early return from damos_adjust_quota() before calculating min_score.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to the latest mm-new.

 mm/damon/core.c | 2 ++
 1 file changed, 2 insertions(+)
mm/damon/core.c +2 -0
index 2258b72da7a7..98c767b9e6ef 100644
@@ -3368,6 +3368,8 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 			damos_trace_esz(c, s, quota);
 	}
 
+	if (damos_quota_is_full(quota, c->min_region_sz))
+		return;
 	if (!c->ops.get_scheme_score)
 		return;
 
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/4] mm/damon/core: skip quota score setup when the quota is full

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

From: Liew Rui Yan <[email protected]>

In damos_adjust_quota(), the quota could already be full.

In this situation, damos_adjust_quota() will still calculates quota->min_score. However, this min_score will not be used in this window, because in damon_do_apply_schemes(), damos_quota_is_full() will always returns true, preventing the scheme from being applied to any region.

Quoted 6 lines

Therefore, add a short circuit for 'esz < min_region_sz' schemes to early return from damos_adjust_quota() before calculating min_score.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

PATCH 2/4 mm/damon/sysfs: propagate damon_call() error in turn_damon_on

In reply to SJ Park

From: Xuewen Wang <[email protected]>

damon_sysfs_turn_damon_on() ignored the return value of damon_call() for the repeat call control registration and always returned the stale result of damon_start() (0 at that point). When damon_call() fails, e.g., the kdamond is already exiting, the user still gets success from the state file write while monitoring is not actually on.

Save and return the damon_call() result instead. No rollback of damon_start() is needed since a failed damon_call() guarantees the context is stopped.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to the latest mm-new.

 mm/damon/sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/damon/sysfs.c +2 -1
index 43519afb9eb7..70a4b64fb8ea 100644
@@ -2607,7 +2607,8 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
 	repeat_call_control->data = kdamond;
 	repeat_call_control->repeat = true;
 	repeat_call_control->dealloc_on_cancel = true;
-	if (damon_call(ctx, repeat_call_control))
+	err = damon_call(ctx, repeat_call_control);
+	if (err)
 		kfree(repeat_call_control);
 	return err;
 }
Signature · 1 line
2.47.3
#4 lore raw

Re: [PATCH 2/4] mm/damon/sysfs: propagate damon_call() error in turn_damon_on

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

From: Xuewen Wang <[email protected]>

damon_sysfs_turn_damon_on() ignored the return value of damon_call() for the repeat call control registration and always returned the stale result of damon_start() (0 at that point). When damon_call() fails, e.g., the kdamond is already exiting, the user still gets success from the state file write while monitoring is not actually on.

Quoted 7 lines

Save and return the damon_call() result instead. No rollback of damon_start() is needed since a failed damon_call() guarantees the context is stopped.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#5 lore raw

PATCH 3/4 mm/damon: fix typos in comments

In reply to SJ Park

From: "Adrian Huang (Lenovo)" <[email protected]>

Correct spelling mistakes. No functional changes.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from Zenghui and SJ.
- Rebase to the latest mm-new.

 mm/damon/core.c     | 6 +++---
 mm/damon/lru_sort.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
mm/damon/core.c +3 -3
index 98c767b9e6ef..0aa5d0ea8ebc 100644
@@ -2486,7 +2486,7 @@ static bool damos_valid_target(struct damon_ctx *c, struct damon_region *r,
  * This function checks if a given region should be skipped or not for the
  * reason.  If only the starting part of the region has previously charged,
  * this function splits the region into two so that the second one covers the
- * area that not charged in the previous charge widnow, and return true.  The
+ * area that not charged in the previous charge window, and return true.  The
  * caller can see the second one on the next iteration of the region walk.
  * Note that this means the caller should use damon_for_each_region() instead
  * of damon_for_each_region_safe().  If damon_for_each_region_safe() is used,
@@ -2652,7 +2652,7 @@ static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t,
  * This function is called when kdamond finished applying the action of a DAMOS
  * scheme to all regions that eligible for the given &damos->apply_interval_us.
  * If every scheme of @ctx including @s now finished walking for at least one
- * &damos->apply_interval_us, this function makrs the handling of the given
+ * &damos->apply_interval_us, this function marks the handling of the given
  * DAMOS walk request is done, so that damos_walk() can wake up and return.
  */
 static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s)
@@ -4177,7 +4177,7 @@ static bool damon_find_system_rams_range(unsigned long *start,
  * This function sets the region of @t as requested by @start and @end.  If the
  * values of @start and @end are zero, however, this function finds 'System
  * RAM' resources and sets the region to cover all the resource.  In the latter
- * case, this function saves the start and the end addresseses of the first and
+ * case, this function saves the start and the end addresses of the first and
  * the last resources in @start and @end, respectively.
  *
  * Return: 0 on success, negative error code otherwise.
mm/damon/lru_sort.c +1 -1
index ad8e86dd3a93..273efa3c913e 100644
@@ -260,7 +260,7 @@ static int damon_lru_sort_add_filters(struct damos *hot_scheme,
 		return -ENOMEM;
 	damos_add_filter(hot_scheme, filter);
 
-	/* disabllow de-prioritizing young pages */
+	/* disallow de-prioritizing young pages */
 	filter = damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, true, false);
 	if (!filter)
 		return -ENOMEM;
Signature · 1 line
2.47.3
#6 lore raw

Re: [PATCH 3/4] mm/damon: fix typos in comments

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

From: "Adrian Huang (Lenovo)" <[email protected]>

Correct spelling mistakes. No functional changes.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author maintainer
#7 lore raw

PATCH 4/4 mm/damon: document that a zero sample_interval is accepted

In reply to SJ Park

From: Karthikeyan KS <[email protected]>

damon_set_attrs() accepts sample_interval == 0. This was reported as a bug in v1 of this patch (rejecting it in damon_set_attrs()). A similar patch was already declined for the same reason: a zero interval is intentionally supported [1].

Document the behavior instead of changing it.

[1] https://lore.kernel.org/all/[email protected]/

---
Changes from v2
- v2: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebas to the latest mm-new.
Changes from v1:
- Dropped the damon_set_attrs() rejection and the KUnit cases that tested it.
- Added a kernel-doc note on struct damon_attrs's @sample_interval instead.

 include/linux/damon.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/damon.h +2 -1
index 836353c4ab9a..844b175120f0 100644
@@ -836,7 +836,8 @@ struct damon_probe {
 /**
  * struct damon_attrs - Monitoring attributes for accuracy/overhead control.
  *
- * @sample_interval:		The time between access samplings.
+ * @sample_interval:		The time between access samplings.  Zero is
+ *				accepted.
  * @aggr_interval:		The time between monitor results aggregations.
  * @ops_update_interval:	The time between monitoring operations updates.
  * @intervals_goal:		Intervals auto-tuning goal.
Signature · 1 line
2.47.3
#8 lore raw

Re: [PATCH 4/4] mm/damon: document that a zero sample_interval is accepted

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

From: Karthikeyan KS <[email protected]>

damon_set_attrs() accepts sample_interval == 0. This was reported as a bug in v1 of this patch (rejecting it in damon_set_attrs()). A similar patch was already declined for the same reason: a zero interval is intentionally supported [1].

Quoted 7 lines

Document the behavior instead of changing it.

[1] https://lore.kernel.org/all/[email protected]/

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4