Skip to contentSkip to conversation

mm/damon/core: cleanup damos->walk_completed in damos_walk_cancel()

RFC PATCH New SJ Park 2 participants 2 messages Nov 22

Subsystems (3)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

RFC PATCH 1/1 mm/damon/core: cleanup damos->walk_completed in damos_walk_cancel()

DAMOS walk could be unexpectedly only partially performed. It can happen when there are multiple schemes and the walk is requested after the previous walk is canceled.

The expectation of DAMOS walk for a setup that has multiple schemes is that it will walk for one snapshot for all schemes. To know if the walk for the one snapshot of a given scheme is done, each damos struct has the walk_completed field. It is set when the walk for the given scheme is completed. The walk skips schemes having the field set. It is reset for all schemes when all the schemes get it set.

damos_walk_cancel() cancels all existing walks. But it does not reset the walk_completed field. damos_walk_cancel() can be called at any kdamond loop iteration. For example, due to DAMON context pause or DAMOS watermarks-caused deactivation. It means that the function can be called while only some of the schemes completed their walks. And users could request another walk after the canceled walk. In the case, because some of the schemes still have walk_completed fields set, the walk for them is skipped. As a result, DAMOS walk based user operations such as update_schemes_tried_bytes kdamond command could show incomplete output.

Fix by unsetting the fields of all schemes in damos_walk_cancel().

The user impact is not critical. No crash or leak happens. Only DAMOS based monitoring results retrieval could work unexpectedly, under the certain setup and the race. Given the best effort nature of DAMON, such occasional monitoring quality degradation would be not critical.

The issue has found from the Sashiko bug database.

Fixes bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
Cc <[email protected]> # 6.14.x
---
 mm/damon/core.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/damon/core.c +4 -0
index b8678a53b0a98..ec7f20b7856de 100644
@@ -2699,6 +2699,7 @@ static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s)
 static void damos_walk_cancel(struct damon_ctx *ctx)
 {
 	struct damos_walk_control *control;
+	struct damos *s;
 
 	mutex_lock(&ctx->walk_control_lock);
 	control = ctx->walk_control;
@@ -2706,6 +2707,9 @@ static void damos_walk_cancel(struct damon_ctx *ctx)
 
 	if (!control)
 		return;
+
+	damon_for_each_scheme(s, ctx)
+		s->walk_completed = false;
 	control->canceled = true;
 	complete(&control->completion);
 	mutex_lock(&ctx->walk_control_lock);

base-commit: bcafbab5174a89c3f689e458b5114641a0f68032

Signature · 1 line
2.47.3
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

DAMOS walk could be unexpectedly only partially performed. It can happen when there are multiple schemes and the walk is requested after the previous walk is canceled.

The expectation of DAMOS walk for a setup that has multiple schemes is that it will walk for one snapshot for all schemes. To know if the walk for the one snapshot of a given scheme is done, each damos struct has the walk_completed field. It is set when the walk for the given scheme is completed. The walk skips schemes having the field set. It is reset for all schemes when all the schemes get it set.

damos_walk_cancel() cancels all existing walks. But it does not reset the walk_completed field. damos_walk_cancel() can be called at any kdamond loop iteration. For example, due to DAMON context pause or DAMOS watermarks-caused deactivation. It means that the function can be [ ... ]

Quoted 4 lines
Fixes bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
Cc <[email protected]> # 6.14.x

Sashiko has reviewed this patch and found no issues.

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