DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 01/11] mm/damon/core: handle <min_region_sz remaining quota as empty
Date: Tue, 28 Apr 2026 02:00:25 +0000	[thread overview]
Message-ID: <20260428020025.BDC94C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260428013402.115171-2-sj@kernel.org>

Sashiko AI review found 1 potential issue(s):
- [High] The patch unmasks an existing off-by-one bug in the DAMOS quota checkpoint logic, which permanently starves memory regions following a quota boundary.
--

commit 6b38ae7237b3de6636c6c420fb6a8b80b4e7eb87
Author: SeongJae Park <sj@kernel.org>

mm/damon/core: handle <min_region_sz remaining quota as empty
    
This commit updates the DAMOS quota logic to treat quotas with less than
min_region_sz remaining as fully charged. This ensures that charge_target_from
and charge_addr_from are updated appropriately to prevent DAMOS actions from
being applied too frequently to specific memory areas.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c

[ ... ]

> @@ -2103,8 +2117,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
>  		quota->total_charged_ns += timespec64_to_ns(&end) -
>  			timespec64_to_ns(&begin);
>  		quota->charged_sz += sz;
> -		if (damos_quota_is_set(quota) &&
> -				quota->charged_sz >= quota->esz) {
> +		if (damos_quota_is_full(quota, c->min_region_sz)) {
>  			quota->charge_target_from = t;
>  			quota->charge_addr_from = r->ar.end + 1;

Does this reliably unmask an existing off-by-one bug here?

Since DAMON ranges [start, end) are exclusive at the end, r->ar.end is
exactly the start of the next region. By adding 1, the checkpoint
address advances 1 byte into the next uncharged region.

During the subsequent charge window, damos_skip_charged_region()
evaluates the next region and checks if it falls within the skipped area:

mm/damon/core.c:damos_skip_charged_region() {
    ...
    if (quota->charge_addr_from && r->ar.start <
            quota->charge_addr_from) {
        sz_to_skip = ALIGN_DOWN(quota->charge_addr_from -
                r->ar.start, min_region_sz);
        if (!sz_to_skip) {
            if (damon_sz_region(r) <= min_region_sz)
                return true;
            sz_to_skip = min_region_sz;
        }
    ...
}

Because the checkpoint is 1 byte inside the next region, sz_to_skip
evaluates to ALIGN_DOWN(1, min_region_sz), which becomes 0. The
fallback logic then forcefully skips min_region_sz bytes and returns true
without clearing the checkpoint.

Could this cause the min_region_sz bytes immediately following a quota
boundary to be permanently starved of DAMOS actions?

Should the assignment be changed to quota->charge_addr_from = r->ar.end
instead?

>  		}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260428013402.115171-1-sj@kernel.org?part=1

  reply	other threads:[~2026-04-28  2:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28  1:33 [PATCH 00/11] mm/damon: introduce DAMOS failed region quota charge ratio SeongJae Park
2026-04-28  1:33 ` [PATCH 01/11] mm/damon/core: handle <min_region_sz remaining quota as empty SeongJae Park
2026-04-28  2:00   ` sashiko-bot [this message]
2026-04-28  3:23     ` SeongJae Park
2026-04-28  1:33 ` [PATCH 02/11] mm/damon/core: merge regions after applying DAMOS schemes SeongJae Park
2026-04-28  1:33 ` [PATCH 03/11] mm/damon/core: introduce failed region quota charge ratio SeongJae Park
2026-04-28  3:00   ` sashiko-bot
2026-04-28  3:38     ` SeongJae Park
2026-04-28  1:33 ` [PATCH 04/11] mm/damon/sysfs-schemes: implement fail_charge_{num,denom} files SeongJae Park
2026-04-28  1:54   ` sashiko-bot
2026-04-28  3:41     ` SeongJae Park
2026-04-28  1:33 ` [PATCH 05/11] Docs/mm/damon/design: document fail_charge_{num,denom} SeongJae Park
2026-04-28  1:33 ` [PATCH 06/11] Docs/admin-guide/mm/damon/usage: document fail_charge_{num,denom} files SeongJae Park
2026-04-28  1:33 ` [PATCH 07/11] Docs/ABI/damon: document fail_charge_{num,denom} SeongJae Park
2026-04-28  1:33 ` [PATCH 08/11] mm/damon/tests/core-kunit: test fail_charge_{num,denom} committing SeongJae Park
2026-04-28  1:33 ` [PATCH 09/11] selftests/damon/_damon_sysfs: support failed region quota charge ratio SeongJae Park
2026-04-28  1:33 ` [PATCH 10/11] selftests/damon/drgn_dump_damon_status: " SeongJae Park
2026-04-28  1:34 ` [PATCH 11/11] selftests/damon/sysfs.py: test " SeongJae Park
2026-04-28 14:48 ` [PATCH 00/11] mm/damon: introduce DAMOS " Andrew Morton
2026-04-28 15:24   ` SeongJae Park
2026-05-01  1:56     ` SeongJae Park
2026-05-01  6:49       ` David Hildenbrand (Arm)
2026-05-02  1:56         ` SeongJae Park

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=20260428020025.BDC94C19425@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko@lists.linux.dev \
    --cc=sj@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