From: SeongJae Park <sj@kernel.org>
To: Vineet Agarwal <agarwal.vineet2006@gmail.com>
Cc: SeongJae Park <sj@kernel.org>,
akpm@linux-foundation.org, damon@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] mm/damon/sysfs-schemes: fix double increment of nr_regions
Date: Mon, 11 May 2026 17:45:37 -0700 [thread overview]
Message-ID: <20260512004538.1005-1-sj@kernel.org> (raw)
In-Reply-To: <20260511191218.98881-1-agarwal.vineet2006@gmail.com>
On Tue, 12 May 2026 00:42:15 +0530 Vineet Agarwal <agarwal.vineet2006@gmail.com> wrote:
> damos_sysfs_populate_region_dir() increments
> sysfs_regions->nr_regions twice when adding a new region:
> once explicitly before kobject_init_and_add(), and once
> again through the post-increment used for the kobject name.
Nice catch!
>
> As a result, nr_regions no longer matches the actual
> number of live regions,
Nonetheless, this is not causing real issues. The the nr_regions is not
exposed to the user space. Similar data structures in the file use arrays for
managing sub-directories and use the number field as the size of the array. If
that's the case for these region directory data, the code might allocating
more-than-needed memory or having some problems. But luckily region
directories are managed using linked list. I find no real problems here.
> and region directory names skip
> numbers (1, 3, 5, ...).
This is also not causing any real issue. This could arguably make users
confused. But still user space could work with this in a reasonable way, by
sorting the regions based on the index and/or the address of regions. Actually
DAMON user-space tool is handling this. That's why I didn't realize this issue
by myself. We recommend human beings to use tools rather than directly
interacting with the sysfs interface.
The admin usage document is also not giving wrong assumptions about the names.
It only says the names will be integers starting from 0. The real names start
from 1, but arguably that doesn't break something, becuase the document doesn't
say there will be directory of name '0'...?
>
> Use the already incremented value for naming instead of
> incrementing nr_regions a second time.
So, there is no real problems. Please let me know if I'm missing something.
But it is also super clear that this is not an intended behavior but a bug.
That needs to be fixed unless it causes unnecessary overhead. Meanwhile, this
fix is simple and nice.
So, nice finding and fix! Thank you for sharing, Vineet!
>
> Signed-off-by: Vineet Agarwal <agarwal.vineet2006@gmail.com>
Seems the current behavior has started since commit 66178e4ec30a
("mm/damon/sysfs: use damos_walk() for update_schemes_tried_{bytes,regions}").
I think it might deserve 'Fixes:' tag if someone claims, but Cc: stable@ may
not really needed because this is not causing any real user issue, as I
mentioned above.
So, this looks good to me. Vineet, is there anything that you want to sort out
before dropping the RFC tag? If not, please feel free to post this again
without the RFC tag.
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-05-12 0:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 19:12 [RFC PATCH] mm/damon/sysfs-schemes: fix double increment of nr_regions Vineet Agarwal
2026-05-12 0:45 ` SeongJae Park [this message]
2026-05-12 4:13 ` Vineet Agarwal
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=20260512004538.1005-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=agarwal.vineet2006@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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