linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chris Mason <clm@meta.com>
To: SeongJae Park <sj@kernel.org>
Cc: Chris Mason <clm@meta.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	<damon@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<linux-mm@kvack.org>
Subject: Re: [PATCH 01/12] mm/damon/core: introduce nr_snapshots damos stat
Date: Wed, 14 Jan 2026 04:29:56 -0800	[thread overview]
Message-ID: <20260114122959.1164957-1-clm@meta.com> (raw)
In-Reply-To: <20251216080128.42991-2-sj@kernel.org>

On Tue, 16 Dec 2025 00:01:14 -0800 SeongJae Park <sj@kernel.org> wrote:

> DAMON generates monitoring results snapshots for every sampling
> interval.  DAMOS applies given schemes on the regions of the snapshots,
> for every apply interval of the scheme.
> 
> DAMOS stat informs a given scheme has tried to how many memory entities
> and applied, in the region and byte level.  In some use cases including
> user-space oriented tuning and investigations, it is useful to know that
> in the DAMON-snapshot level.  Introduce a new stat, namely nr_snapshots
> for DAMON core API callers.

Hi everyone,

I ran mm-new through the AI review prompts and this one was flagged:

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -157,6 +157,12 @@ void damon_destroy_region(struct damon_region *r, struct damon_target *t)
>  	damon_free_region(r);
>  }
>
> +static bool damon_is_last_region(struct damon_region *r,
> +		struct damon_target *t)
> +{
> +	return list_is_last(&t->regions_list, &r->list);
                           ^^^^^^^^^^^^^^^^  ^^^^^^^^

Are the arguments to list_is_last() swapped here? The kernel's
list_is_last() expects (entry, head) but this passes (head, entry).

Looking at include/linux/list.h:

    static inline int list_is_last(const struct list_head *list,
                                   const struct list_head *head)
    {
        return list->next == head;
    }

The current code checks if t->regions_list.next == &r->list, which will
be true when r is the first region in the list, not the last.

Compare with the existing damon_last_region() in include/linux/damon.h
which correctly uses &t->regions_list as the head:

    static inline struct damon_region *damon_last_region(struct damon_target *t)
    {
        return list_last_entry(&t->regions_list, struct damon_region, list);
    }

Should this be:

    return list_is_last(&r->list, &t->regions_list);

> +}
> +

[ ... ]

> @@ -1978,10 +1984,11 @@ static void damon_do_apply_schemes(struct damon_ctx *c,

[ ... ]

> +		if (damon_is_last_region(r, t))
> +			s->stat.nr_snapshots++;

If the list_is_last() arguments are indeed swapped, this will increment
nr_snapshots when processing the first region of each target rather than
the last, causing the stat to be counted once per target instead of once
per complete snapshot.

>  	}
>  }




  reply	other threads:[~2026-01-14 12:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-16  8:01 [PATCH 00/12] mm/damon: introduce {,max_}nr_snapshots and tracepoint for damos stats SeongJae Park
2025-12-16  8:01 ` [PATCH 01/12] mm/damon/core: introduce nr_snapshots damos stat SeongJae Park
2026-01-14 12:29   ` Chris Mason [this message]
2025-12-16  8:01 ` [PATCH 02/12] mm/damon/sysfs-schemes: introduce nr_snapshots damos stat file SeongJae Park
2025-12-16  8:01 ` [PATCH 03/12] Docs/mm/damon/design: update for nr_snapshots damos stat SeongJae Park
2025-12-16  8:01 ` [PATCH 04/12] Docs/admin-guide/mm/damon/usage: " SeongJae Park
2025-12-16  8:01 ` [PATCH 05/12] Docs/ABI/damon: " SeongJae Park
2025-12-16  8:01 ` [PATCH 06/12] mm/damon: update damos kerneldoc for stat field SeongJae Park
2025-12-16  8:01 ` [PATCH 07/12] mm/damon/core: implement max_nr_snapshots SeongJae Park
2025-12-16  8:01 ` [PATCH 08/12] mm/damon/sysfs-schemes: implement max_nr_snapshots file SeongJae Park
2025-12-16  8:01 ` [PATCH 09/12] Docs/mm/damon/design: update for max_nr_snapshots SeongJae Park
2025-12-16  8:01 ` [PATCH 10/12] Docs/admin-guide/mm/damon/usage: " SeongJae Park
2025-12-16  8:01 ` [PATCH 11/12] Docs/ABI/damon: " SeongJae Park
2025-12-16  8:01 ` [PATCH 12/12] mm/damon/core: add trace point for damos stat per apply interval SeongJae Park
2025-12-17 22:48   ` Steven Rostedt
2025-12-17 23:52     ` SeongJae Park
2025-12-18  2:29       ` Andrew Morton
2025-12-18  3:04         ` SeongJae Park
2025-12-18 17:29         ` Steven Rostedt

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=20260114122959.1164957-1-clm@meta.com \
    --to=clm@meta.com \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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