* [PATCH] mm/damon/sysfs: make next_update_jiffies per-kdamond
@ 2026-10-17 6:31 Karthikeyan KS
2026-10-17 16:01 ` SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: Karthikeyan KS @ 2026-10-17 6:31 UTC (permalink / raw)
To: sj; +Cc: akpm, damon, linux-mm, linux-kernel, Karthikeyan KS
damon_sysfs_next_update_jiffies was a single static variable shared by
all kdamonds, so with two or more kdamonds using refresh_ms their
threads race on it in damon_sysfs_repeat_call_fn().
Signed-off-by: Karthikeyan KS <karthiproffesional@gmail.com>
---
Testing notes for review:
- Found and confirmed with KCSAN.
- Repro setup: QEMU (x86_64, 2GB RAM, multiple vCPUs), two paddr
kdamonds, both refresh_ms non-zero. kdamond.0 watching [0, 1GB),
kdamond.1 watching [1GB, 2GB).
- On the unpatched kernel, KCSAN kept reporting the race on
damon_sysfs_next_update_jiffies, again and again.
- Ran the same setup after the fix, KCSAN still on, nothing reported.
- Tried the same with vaddr kdamonds too, could not repro there.
mm/damon/sysfs.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 160292f077dd..872b89f58bd1 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1789,6 +1789,7 @@ struct damon_sysfs_kdamond {
struct damon_sysfs_contexts *contexts;
struct damon_ctx *damon_ctx;
unsigned int refresh_ms;
+ unsigned long damon_sysfs_next_update_jiffies;
};
static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc(void)
@@ -2215,18 +2216,16 @@ static struct damon_ctx *damon_sysfs_build_ctx(
return ctx;
}
-/* Tracks when the next periodic re-commit via repeat_call_fn() is due. */
-static unsigned long damon_sysfs_next_update_jiffies;
-
static int damon_sysfs_repeat_call_fn(void *data)
{
struct damon_sysfs_kdamond *sysfs_kdamond = data;
if (!sysfs_kdamond->refresh_ms)
return 0;
- if (time_before(jiffies, damon_sysfs_next_update_jiffies))
+ if (time_before(jiffies,
+ sysfs_kdamond->damon_sysfs_next_update_jiffies))
return 0;
- damon_sysfs_next_update_jiffies = jiffies +
+ sysfs_kdamond->damon_sysfs_next_update_jiffies = jiffies +
msecs_to_jiffies(sysfs_kdamond->refresh_ms);
if (!mutex_trylock(&damon_sysfs_lock))
@@ -2274,7 +2273,7 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
}
kdamond->damon_ctx = ctx;
- damon_sysfs_next_update_jiffies =
+ kdamond->damon_sysfs_next_update_jiffies =
jiffies + msecs_to_jiffies(kdamond->refresh_ms);
repeat_call_control->fn = damon_sysfs_repeat_call_fn;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mm/damon/sysfs: make next_update_jiffies per-kdamond
2026-10-17 6:31 [PATCH] mm/damon/sysfs: make next_update_jiffies per-kdamond Karthikeyan KS
@ 2026-10-17 16:01 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-10-17 16:01 UTC (permalink / raw)
To: Karthikeyan KS; +Cc: SJ Park, akpm, damon, linux-mm, linux-kernel
Hi Karthikeyan,
On Sat, 17 Oct 2026 06:31:52 +0000 Karthikeyan KS <karthiproffesional@gmail.com> wrote:
> damon_sysfs_next_update_jiffies was a single static variable shared by
> all kdamonds, so with two or more kdamonds using refresh_ms their
> threads race on it in damon_sysfs_repeat_call_fn().
Thank you for this patch. However, I think the same issue is already fixed by
another patch [1]. Could you please check?
[1] https://lore.kernel.org/20260902002725.108635-5-sj@kernel.org
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-17 16:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-17 6:31 [PATCH] mm/damon/sysfs: make next_update_jiffies per-kdamond Karthikeyan KS
2026-10-17 16:01 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox