[BUG] DAMON sysfs: failed update clears tried_regions snapshot

From: Aveline Noir

Date: Thu Oct 15 2026 - 07:29:16 EST


Hi,

On mm-new commit ad9f2d463666, requesting
update_schemes_tried_regions after stopping a kdamond returns
-ECANCELED and clears the previous tried_regions snapshot. The final
result collected before "off" is then lost.

I reproduced this in an x86_64 QEMU guest running
7.3.0-rc5-1485016-gad9f2d463666. It used one PADDR context over
[0x400000, 0x800000) and one default stat scheme. The paths below are
relative to /sys/kernel/mm/damon/admin/kdamonds/0/:

../nr_kdamonds = 1
contexts/nr_contexts = 1
contexts/0/operations = paddr
contexts/0/targets/nr_targets = 1
contexts/0/targets/0/regions/nr_regions = 1
contexts/0/targets/0/regions/0/start = 4194304
contexts/0/targets/0/regions/0/end = 8388608
contexts/0/schemes/nr_schemes = 1
contexts/0/schemes/0/access_pattern/{sz,nr_accesses,age}/max =
4294967295 for each file

The reproducer then:

1. Wrote "on" and "update_schemes_tried_regions" to state.
2. Read contexts/0/schemes/0/tried_regions/total_bytes and counted
the region directories there.
3. Wrote "off" to state, then requested
"update_schemes_tried_regions" again and read the same results.

The guest output was:

BEFORE_OFF bytes=4194304 dirs=10
STATE_OFF bytes=4194304 dirs=10
FAILED_UPDATE ret=-1 errno=125 bytes_after=0 dirs_after=0

errno 125 is ECANCELED. The snapshot survives "off", but the failed
update removes all 10 directories and resets total_bytes. There is a
separate clear_schemes_tried_regions command for clearing a snapshot;
a failed update should leave the last successful one available.

damon_sysfs_turn_damon_off() retains damon_ctx for final results. But
damon_sysfs_update_schemes_tried_regions() calls
damon_sysfs_schemes_clear_regions() before damos_walk(). Once the
context is stopped, damos_walk() returns -ECANCELED because its walk
control is obsolete, leaving the sysfs results cleared.

The guest completed with RESULT exit=0. Reproducer, kernel config,
serial log, and build/run steps:

https://github.com/jm5905938/kernel-mail/tree/195d7017352a3d0f4a0475b98f3b03650f5c14ea/cases/2026/damon/2026-10-15-bug-reports/01-sysfs-tried-regions-snapshot

Thanks,
Aveline Noir