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. Closes: https://sashiko.dev/#/bug/linux-228a4c52-0545-4c1f-90ce-41114d8272e9 Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()") Cc: # 6.14.x Signed-off-by: SJ Park --- mm/damon/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index b8678a53b0a98..ec7f20b7856de 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -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 -- 2.47.3