]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/damon/core: add damon_nr_regions() debug_sanity check
authorSeongJae Park <sj@kernel.org>
Fri, 6 Mar 2026 15:29:07 +0000 (07:29 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 5 Apr 2026 20:53:20 +0000 (13:53 -0700)
damon_target->nr_regions is introduced to get the number quickly without
having to iterate regions always.  Add a sanity check for that under
CONFIG_DAMON_DEBUG_SANITY.

Link: https://lkml.kernel.org/r/20260306152914.86303-5-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/core.c

index c499a02ac44eb22dbe43423563b6d17c4efc47f5..16bedde920f037825d4ab53e03095d3afae4e4a9 100644 (file)
@@ -545,8 +545,27 @@ void damon_destroy_target(struct damon_target *t, struct damon_ctx *ctx)
        damon_free_target(t);
 }
 
+#ifdef CONFIG_DAMON_DEBUG_SANITY
+static void damon_verify_nr_regions(struct damon_target *t)
+{
+       struct damon_region *r;
+       unsigned int count = 0;
+
+       damon_for_each_region(r, t)
+               count++;
+       WARN_ONCE(count != t->nr_regions, "t->nr_regions (%u) != count (%u)\n",
+                       t->nr_regions, count);
+}
+#else
+static void damon_verify_nr_regions(struct damon_target *t)
+{
+}
+#endif
+
 unsigned int damon_nr_regions(struct damon_target *t)
 {
+       damon_verify_nr_regions(t);
+
        return t->nr_regions;
 }