[RFC PATCH 00/10] mm/damon: add optional debugging-purpose sanity checks

0 views
Skip to first unread message

SeongJae Park

unread,
Feb 21, 2026, 2:36:36 PMFeb 21
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
DAMON code has a few assumptions that can be critical if violated.
Validating the assumptions in code can be useful at finding such
critical bugs. I was actually adding some such additional sanity checks
in my personal tree, and those were useful at finding bugs that I made
during the development of new patches. We also found [1] sometimes the
assumptions are misunderstood. The validation can work as good
documentation for such cases.

Add some of such debugging purpose sanity checks. Because those
additional checks can impose more overhead, make those only optional via
new config, CONFIG_DAMON_DEBUG_SANITY, that is recommended for only
development and test setups. And as recommended, enable it for DAMON
kunit tests and selftests.

[1] https://lore.kernel.org/202512310700...@kernel.org

SeongJae Park (10):
mm/damon: add CONFIG_DAMON_DEBUG_SANITY
mm/damon/core: add damon_new_region() debug_sanity check
mm/damon/core: add damon_del_region() debug_sanity check
mm/damon/core: add damon_nr_regions() debug_sanity check
mm/damon/core: add damon_merge_two_regions() debug_sanity check
mm/damon/core: add damon_merge_regions_of() debug_sanity check
mm/damon/core: add damon_split_region_at() debug_sanity check
mm/damon/core: add damon_reset_aggregated() debug_sanity check
mm/damon/tests/.kunitconifg: enable DAMON_DEBUG_SANITY
tools/testing/selftests/damon/config: enable DAMON_DEBUG_SANITY

mm/damon/Kconfig | 11 +++
mm/damon/core.c | 139 +++++++++++++++++++++++++++
mm/damon/tests/.kunitconfig | 3 +
tools/testing/selftests/damon/config | 1 +
4 files changed, 154 insertions(+)


base-commit: e059221c54896e36c8fc320029648e9013b382ea
--
2.47.3

SeongJae Park

unread,
Feb 21, 2026, 2:36:39 PMFeb 21
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
CONFIG_DAMON_DEBUG_SANITY is recommended for DAMON development and test
setups. Enable it on the default configurations for DAMON kunit test
run.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/.kunitconfig | 3 +++
1 file changed, 3 insertions(+)

diff --git a/mm/damon/tests/.kunitconfig b/mm/damon/tests/.kunitconfig
index 36a450f57b581..144d27e6ecc5c 100644
--- a/mm/damon/tests/.kunitconfig
+++ b/mm/damon/tests/.kunitconfig
@@ -13,3 +13,6 @@ CONFIG_DAMON_VADDR_KUNIT_TEST=y
CONFIG_SYSFS=y
CONFIG_DAMON_SYSFS=y
CONFIG_DAMON_SYSFS_KUNIT_TEST=y
+
+# enable DAMON_DEBUG_SANITY to catch any bug
+CONFIG_DAMON_DEBUG_SANITY=y
--
2.47.3

SeongJae Park

unread,
Feb 21, 2026, 3:15:54 PMFeb 21
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
And this makes kunit for DAMON fails, like below.

'''
$ ./tools/testing/kunit/kunit.py run --kunitconfig mm/damon/tests/
[11:57:20] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[11:57:24] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=8
ERROR:root:In file included from ../include/asm-generic/bug.h:7,
from ./arch/um/include/generated/asm/bug.h:1,
from ../arch/x86/include/asm/alternative.h:9,
from ../arch/x86/um/asm/barrier.h:6,
from ../include/linux/list.h:11,
from ../arch/um/include/linux/time-internal.h:9,
from ../arch/x86/um/asm/processor.h:4,
from ../include/linux/sched.h:13,
from ../include/linux/cgroup.h:12,
from ../include/linux/memcontrol.h:13,
from ../include/linux/damon.h:11,
from ../mm/damon/core.c:10:
../mm/damon/core.c: In function ‘damon_verify_new_region’:
../include/linux/once_lite.h:28:50: error: expected expression before ‘)’ token
28 | bool __ret_do_once = !!(condition); \
| ^
../include/asm-generic/bug.h:185:9: note: in expansion of macro ‘DO_ONCE_LITE_IF’
185 | DO_ONCE_LITE_IF(condition, WARN, 1, format)
| ^~~~~~~~~~~~~~~
../mm/damon/core.c:127:9: note: in expansion of macro ‘WARN_ONCE’
127 | WARN_ONCE();
| ^~~~~~~~~
'''

I changed BUG() to WARN_ONCE() on the last moment of this patch posting, so I
missed this failure. I will fix this on the next revision.


Thanks,
SJ

[...]

SeongJae Park

unread,
Mar 1, 2026, 12:43:33 PMMar 1
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
DAMON code has a few assumptions that can be critical if violated.
Validating the assumptions in code can be useful at finding such
critical bugs. I was actually adding some such additional sanity checks
in my personal tree, and those were useful at finding bugs that I made
during the development of new patches. We also found [1] sometimes the
assumptions are misunderstood. The validation can work as good
documentation for such cases.

Add some of such debugging purpose sanity checks. Because those
additional checks can impose more overhead, make those only optional via
new config, CONFIG_DAMON_DEBUG_SANITY, that is recommended for only
development and test setups. And as recommended, enable it for DAMON
kunit tests and selftests.

Note that the verification only WARN_ON() for each of the insanity. The
developer or tester may better to set panic_on_oops together, like
damon-tests/corr did [2].

[1] https://lore.kernel.org/202512310700...@kernel.org
[2] https://github.com/damonitor/damon-tests/commit/a80fbee55e272f151b4e5809ee85898aea33e6ff

Changes from RFC v1
(https://lore.kernel.org/202602211936...@kernel.org)
- Fix WARN_ON() failure on kunit UML build
- Fix Wformat-zero-length issue
(https://lore.kernel.org/oe-kbuild-all/202602221352...@intel.com/)
- Rebase to latest mm-new
- Make warning message less verbose
- Use WARN_ONCE() condition
- Do the verification asap
- Minor cleanups

SeongJae Park (10):
mm/damon: add CONFIG_DAMON_DEBUG_SANITY
mm/damon/core: add damon_new_region() debug_sanity check
mm/damon/core: add damon_del_region() debug_sanity check
mm/damon/core: add damon_nr_regions() debug_sanity check
mm/damon/core: add damon_merge_two_regions() debug_sanity check
mm/damon/core: add damon_merge_regions_of() debug_sanity check
mm/damon/core: add damon_split_region_at() debug_sanity check
mm/damon/core: add damon_reset_aggregated() debug_sanity check
mm/damon/tests/.kunitconifg: enable DAMON_DEBUG_SANITY
selftests/damon/config: enable DAMON_DEBUG_SANITY

mm/damon/Kconfig | 11 +++
mm/damon/core.c | 109 +++++++++++++++++++++++++++
mm/damon/tests/.kunitconfig | 3 +
tools/testing/selftests/damon/config | 1 +
4 files changed, 124 insertions(+)


base-commit: b511f483f5fc7e85ad60679181503f16937feb6e
--
2.47.3

SeongJae Park

unread,
Mar 1, 2026, 12:43:36 PMMar 1
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
CONFIG_DAMON_DEBUG_SANITY is recommended for DAMON development and test
setups. Enable it on the default configurations for DAMON kunit test
run.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/.kunitconfig | 3 +++
1 file changed, 3 insertions(+)

diff --git a/mm/damon/tests/.kunitconfig b/mm/damon/tests/.kunitconfig
index 36a450f57b581..144d27e6ecc5c 100644
--- a/mm/damon/tests/.kunitconfig
+++ b/mm/damon/tests/.kunitconfig
@@ -13,3 +13,6 @@ CONFIG_DAMON_VADDR_KUNIT_TEST=y
CONFIG_SYSFS=y
CONFIG_DAMON_SYSFS=y
CONFIG_DAMON_SYSFS_KUNIT_TEST=y
+
+# enable DAMON_DEBUG_SANITY to catch any bug
+CONFIG_DAMON_DEBUG_SANITY=y
--
2.47.3

SeongJae Park

unread,
Mar 6, 2026, 10:29:24 AMMar 6
to Andrew Morton, SeongJae Park, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
DAMON code has a few assumptions that can be critical if violated.
Validating the assumptions in code can be useful at finding such
critical bugs. I was actually adding some such additional sanity checks
in my personal tree, and those were useful at finding bugs that I made
during the development of new patches. We also found [1] sometimes the
assumptions are misunderstood. The validation can work as good
documentation for such cases.

Add some of such debugging purpose sanity checks. Because those
additional checks can impose more overhead, make those only optional via
new config, CONFIG_DAMON_DEBUG_SANITY, that is recommended for only
development and test setups. And as recommended, enable it for DAMON
kunit tests and selftests.

Note that the verification only WARN_ON() for each of the insanity. The
developer or tester may better to set panic_on_oops together, like
damon-tests/corr did [2].

[1] https://lore.kernel.org/202512310700...@kernel.org
[2] https://github.com/damonitor/damon-tests/commit/a80fbee55e272f151b4e5809ee85898aea33e6ff

Changes from RFC v2
(https://lore.kernel.org/202603011743...@kernel.org)
base-commit: b2de0f05a00142f219d8f6e96b22c8f19fe0446f
--
2.47.3

SeongJae Park

unread,
Mar 6, 2026, 10:29:26 AMMar 6
to Andrew Morton, SeongJae Park, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
Reply all
Reply to author
Forward
0 new messages