From: SJ Park <sj@kernel.org>
Cc: SJ Park <sj@kernel.org>,
stable@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>,
Enze Li <lienze@kylinos.cn>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [RFC PATCH v2] mm/damon/core: reset invalid quota->charge_target_from
Date: Tue, 8 Sep 2026 07:42:44 -0700 [thread overview]
Message-ID: <20260908144246.104162-1-sj@kernel.org> (raw)
DAMOS can suddenly stop working if a target process that the quota is
just fully charged on is terminated. Fix by catching and processing the
corner case.
When DAMOS quota is fully charged, the target and the region to continue
applying the action in the next round is saved in
damos_quota->charge_{target,addr}_from. In the next round, DAMOS
iterates targets and regions from the beginning. It skips applying the
action to the regions until it visits and skips the saved target/region.
Virtual address space targets become invalid if the process is
terminated. Trying to apply the scheme to invalid target is just a
waste of time. Hence commit 6e4930e33329 ("mm/damon/core: fix wasteful
CPU calls by skipping non-existent targets") made the logic to skip
invalid targets. However, it does skip before the charged target/region
skipping/updating.
Let's suppose the user runs DAMOS for multiple virtual address spaces
with a quota. The quota exceeded in the middle of a virtual address
space. And the process of the address space is terminated. Then the
charge_target_from points to the invalid target. The pointer update
logic is skipped for the invalid target, so the charge_target_from is
never updated. DAMOS action to every target/region is skipped. From
the user's perspective, it would look like suddenly DAMOS has stopped
working.
No critical leak or crash can happen. The user could reinstall the
scheme. But this makes use of DAMOS under certain setups quite
unreliable.
When the invalid target is found, further check the corner case and
reset the pointer.
This issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260830064708.40CA61F000E9@smtp.kernel.org
Fixes: 6e4930e33329 ("mm/damon/core: fix wasteful CPU calls by skipping non-existent targets")
Cc: <stable@vger.kernel.org> # 7.0.x
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260907165529.98874-1-sj@kernel.org
- Move the corner case check to invalid target found case, to handle
dynamic quota uninstall case.
- Add RFC tag again.
Changes from RFC v1
- RFC v1: https://lore.kernel.org/20260906183654.95634-1-sj@kernel.org
- Drop RFC tag.
mm/damon/core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index ce8c6f99106ed..a360c41cda89c 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3389,8 +3389,15 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
max_region_sz = damon_region_sz_limit(c);
mutex_lock(&c->walk_control_lock);
damon_for_each_target(t, c) {
- if (c->ops.target_valid && c->ops.target_valid(t) == false)
+ if (c->ops.target_valid && c->ops.target_valid(t) == false) {
+ damon_for_each_scheme(s, c) {
+ if (s->quota.charge_target_from != t)
+ continue;
+ s->quota.charge_target_from = NULL;
+ s->quota.charge_addr_from = 0;
+ }
continue;
+ }
damos_apply_target(c, t, max_region_sz);
}
base-commit: 4c152875952628604696dbba38cd487fdfde28ea
--
2.47.3
reply other threads:[~2026-09-08 14:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908144246.104162-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=lienze@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®