Re: [PATCH 1/2] mm/damon/core: Use only installed probe in damon_merge_two_regions()

From: SJ Park

Date: Thu Oct 08 2026 - 06:47:41 EST


Hello Suhaas,

On Wed, 7 Oct 2026 21:18:45 +0530 Suhaas Joshi <suhaas@xxxxxxxxxx> wrote:

> While merging 2 regions, we iterate over the entire probe_hits[] array,
> whose size is determined by the DAMON_MAX_PROBES macro. It is possible,
> however, that we have fewer probes installed than DAMON_MAX_PROBES. In such
> cases, we end up making redundant iterations. Therefore, to remedy this,
> iterate over the list of installed probes instead of iterating over the
> entire array. For doing this, start accepting a struct damon_ctx in
> damon_merge_two_regions(), and update calling functions to pass this
> argument.
>
> Update the damon_test_merge_two() test to use this new signature for
> damon_merge_two_regions() as well.

Thank you for this patch.

[...]
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -182,13 +182,27 @@ static void damon_test_merge_two(struct kunit *test)
> {
> struct damon_target *t;
> struct damon_region *r, *r2, *r3;
> + struct damon_probe *p;
> + struct damon_ctx *ctx;
> int i;
>
> + p = damon_new_probe();
> + if (!p)
> + kunit_skip(test, "probe alloc fail");
> + ctx = damon_new_ctx();
> + if (!ctx) {
> + damon_destroy_probe(p);
> + kunit_skip(test, "context alloc fail");
> + }
> + damon_add_probe(ctx, p);
> t = damon_new_target();
> - if (!t)
> + if (!t) {
> + damon_destroy_ctx(ctx);
> kunit_skip(test, "target alloc fail");
> + }
> r = damon_new_region(0, 100);
> if (!r) {
> + damon_destroy_ctx(ctx);
> damon_free_target(t);
> kunit_skip(test, "region alloc fail");
> }
> @@ -206,7 +220,7 @@ static void damon_test_merge_two(struct kunit *test)
> r2->age = 21;
> damon_add_region(r2, t);

As also found [1] by Sashiko, seems this patch mistakenly not calling
damon_destroy_ctx() for r2 allocation failure. Could you please add that?

[1] https://lore.kernel.org/sashiko-outbox-163177@xxxxxxxxxx


Thanks,
SJ