mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
@ 2026-09-08  6:36 Kunwu Chan
  2026-09-08  6:48 ` Lian Wang
  2026-09-08 13:36 ` SJ Park
  0 siblings, 2 replies; 4+ messages in thread
From: Kunwu Chan @ 2026-09-08  6:36 UTC (permalink / raw)
  To: sj, akpm; +Cc: lianux.mm, damon, linux-mm, linux-kernel, Kunwu Chan

The damon_nr_samples_per_aggr() test sets both intervals to zero,
which exercises two different fallback paths at once.

Use separate compound initializers for each case so that each case
tests one fallback path independently. Also make the overflow case
use an explicit non-zero sample interval so that it does not depend
on the zero sample interval fallback.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 mm/damon/tests/core-kunit.h | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index c01e6a75cad..ff23208c181 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -627,12 +627,20 @@ static void damon_test_set_regions(struct kunit *test)
 
 static void damon_test_nr_samples_per_aggr(struct kunit *test)
 {
-	struct damon_attrs attrs = {
+	struct damon_attrs attrs;
+
+	/* Zero sample interval is treated as one. */
+	attrs = (struct damon_attrs){
 		.sample_interval = 0,
-		.aggr_interval = 0,
+		.aggr_interval = 5000,
 	};
+	KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 5000);
 
-	/* Zero aggregation interval doesn't cause division by zero */
+	/* Zero samples per aggregation is treated as one. */
+	attrs = (struct damon_attrs){
+		.sample_interval = 5000,
+		.aggr_interval = 0,
+	};
 	KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 1);
 
 	/*
@@ -640,7 +648,10 @@ static void damon_test_nr_samples_per_aggr(struct kunit *test)
 	 * overflow
 	 */
 	if (ULONG_MAX > UINT_MAX) {
-		attrs.aggr_interval = (unsigned long)UINT_MAX + 1;
+		attrs = (struct damon_attrs){
+			.sample_interval = 1,
+			.aggr_interval = (unsigned long)UINT_MAX + 1,
+		};
 		KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs),
 				UINT_MAX);
 	}

base-commit: d118502628f8b673be9023db8bdf878f64a7ed45
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
  2026-09-08  6:36 [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation Kunwu Chan
@ 2026-09-08  6:48 ` Lian Wang
  2026-09-08 13:36 ` SJ Park
  1 sibling, 0 replies; 4+ messages in thread
From: Lian Wang @ 2026-09-08  6:48 UTC (permalink / raw)
  To: Kunwu Chan; +Cc: sj, akpm, lianux.mm, damon, linux-mm, linux-kernel

On Tue,  8 Sep 2026 14:36:35 +0800 Kunwu Chan <kunwu.chan@gmail.com> wrote:

> The damon_nr_samples_per_aggr() test sets both intervals to zero,
> which exercises two different fallback paths at once.
>
> Use separate compound initializers for each case so that each case
> tests one fallback path independently. Also make the overflow case
> use an explicit non-zero sample interval so that it does not depend
> on the zero sample interval fallback.

Hi Kunwu,

The separate initializers now exercise the zero sample-interval fallback,
the zero samples-per-aggregation fallback, and the 64-bit UINT_MAX saturation
path independently.  Using a sample interval of one for the last case also
keeps it independent from the zero sample-interval fallback.

Looks good to me.

Reviewed-by: Lian Wang <lianux.mm@gmail.com>

Thanks,
Lian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
  2026-09-08  6:36 [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation Kunwu Chan
  2026-09-08  6:48 ` Lian Wang
@ 2026-09-08 13:36 ` SJ Park
  2026-09-09  3:54   ` Kunwu Chan
  1 sibling, 1 reply; 4+ messages in thread
From: SJ Park @ 2026-09-08 13:36 UTC (permalink / raw)
  To: Kunwu Chan; +Cc: SJ Park, akpm, lianux.mm, damon, linux-mm, linux-kernel

Hi Kunwu,

On Tue,  8 Sep 2026 14:36:35 +0800 Kunwu Chan <kunwu.chan@gmail.com> wrote:

> The damon_nr_samples_per_aggr() test sets both intervals to zero,
> which exercises two different fallback paths at once.
> 
> Use separate compound initializers for each case so that each case
> tests one fallback path independently. Also make the overflow case
> use an explicit non-zero sample interval so that it does not depend
> on the zero sample interval fallback.

Thank you for sharing this patch!

> 
> Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
> ---
>  mm/damon/tests/core-kunit.h | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> index c01e6a75cad..ff23208c181 100644
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -627,12 +627,20 @@ static void damon_test_set_regions(struct kunit *test)
>  
>  static void damon_test_nr_samples_per_aggr(struct kunit *test)
>  {
> -	struct damon_attrs attrs = {
> +	struct damon_attrs attrs;
> +
> +	/* Zero sample interval is treated as one. */
> +	attrs = (struct damon_attrs){
>  		.sample_interval = 0,
> -		.aggr_interval = 0,
> +		.aggr_interval = 5000,
>  	};
> +	KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 5000);

Thank you for adding this test case.

>  
> -	/* Zero aggregation interval doesn't cause division by zero */
> +	/* Zero samples per aggregation is treated as one. */
> +	attrs = (struct damon_attrs){
> +		.sample_interval = 5000,
> +		.aggr_interval = 0,
> +	};
>  	KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 1);

But damon_set_attrs() disallows sample intervals that are larger than the
aggregation intervals.  Hence this setup is somewhat unrealistic.  Should we
set sample_interval zero?

>  
>  	/*
> @@ -640,7 +648,10 @@ static void damon_test_nr_samples_per_aggr(struct kunit *test)
>  	 * overflow
>  	 */
>  	if (ULONG_MAX > UINT_MAX) {
> -		attrs.aggr_interval = (unsigned long)UINT_MAX + 1;
> +		attrs = (struct damon_attrs){
> +			.sample_interval = 1,
> +			.aggr_interval = (unsigned long)UINT_MAX + 1,
> +		};
>  		KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs),
>  				UINT_MAX);
>  	}
> 
> base-commit: d118502628f8b673be9023db8bdf878f64a7ed45
> -- 
> 2.43.0


Thanks,
SJ

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
  2026-09-08 13:36 ` SJ Park
@ 2026-09-09  3:54   ` Kunwu Chan
  0 siblings, 0 replies; 4+ messages in thread
From: Kunwu Chan @ 2026-09-09  3:54 UTC (permalink / raw)
  To: SJ Park; +Cc: Kunwu Chan, akpm, lianux.mm, damon, linux-mm, linux-kernel

On Tue,  8 Sep 2026 06:36:50 -0700 SJ Park <sj@kernel.org> wrote:

> Hi Kunwu,
> 
> On Tue,  8 Sep 2026 14:36:35 +0800 Kunwu Chan <kunwu.chan@gmail.com> wrote:
> 
> > The damon_nr_samples_per_aggr() test sets both intervals to zero,
> > which exercises two different fallback paths at once.
> > 
> > Use separate compound initializers for each case so that each case
> > tests one fallback path independently. Also make the overflow case
> > use an explicit non-zero sample interval so that it does not depend
> > on the zero sample interval fallback.
> 
> Thank you for sharing this patch!
> 
> > 
> > Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
> > ---
> >  mm/damon/tests/core-kunit.h | 19 +++++++++++++++----
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> > 
> > diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> > index c01e6a75cad..ff23208c181 100644
> > --- a/mm/damon/tests/core-kunit.h
> > +++ b/mm/damon/tests/core-kunit.h
> > @@ -627,12 +627,20 @@ static void damon_test_set_regions(struct kunit *test)
> >  
> >  static void damon_test_nr_samples_per_aggr(struct kunit *test)
> >  {
> > -	struct damon_attrs attrs = {
> > +	struct damon_attrs attrs;
> > +
> > +	/* Zero sample interval is treated as one. */
> > +	attrs = (struct damon_attrs){
> >  		.sample_interval = 0,
> > -		.aggr_interval = 0,
> > +		.aggr_interval = 5000,
> >  	};
> > +	KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 5000);
> 
> Thank you for adding this test case.
> 
> >  
> > -	/* Zero aggregation interval doesn't cause division by zero */
> > +	/* Zero samples per aggregation is treated as one. */
> > +	attrs = (struct damon_attrs){
> > +		.sample_interval = 5000,
> > +		.aggr_interval = 0,
> > +	};
> >  	KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 1);
> 
> But damon_set_attrs() disallows sample intervals that are larger than the
> aggregation intervals.  Hence this setup is somewhat unrealistic.  Should we
> set sample_interval zero?

Good point. 
I checked damon_set_attrs() as well, and the `sample_interval <= aggr_interval` 
constraint makes `0/0` the consistent boundary case here.

I'll update the second case accordingly.

Thanks,
KunWu

> 
> >  
> >  	/*
> > @@ -640,7 +648,10 @@ static void damon_test_nr_samples_per_aggr(struct kunit *test)
> >  	 * overflow
> >  	 */
> >  	if (ULONG_MAX > UINT_MAX) {
> > -		attrs.aggr_interval = (unsigned long)UINT_MAX + 1;
> > +		attrs = (struct damon_attrs){
> > +			.sample_interval = 1,
> > +			.aggr_interval = (unsigned long)UINT_MAX + 1,
> > +		};
> >  		KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs),
> >  				UINT_MAX);
> >  	}
> > 
> > base-commit: d118502628f8b673be9023db8bdf878f64a7ed45
> > -- 
> > 2.43.0
> 
> 
> Thanks,
> SJ
> 

Sent using hkml (https://github.com/sjp38/hackermail)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-09  3:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08  6:36 [PATCH] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation Kunwu Chan
2026-09-08  6:48 ` Lian Wang
2026-09-08 13:36 ` SJ Park
2026-09-09  3:54   ` Kunwu Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®