On Tue,  1 Sep 2026 22:47:42 -0700 SJ Park <[email protected]> wrote:

> damon_max_nr_accesses(), which is a previous version of
> damon_nr_samples_per_aggr() before the renaming, was wrongly returning
> zero or random overflowed values for extreme intervals setup.  Commit
> 35d4a3cf70a8 ("mm/damon/ops-common: handle extreme intervals in
> damon_hot_score()") updated the function to return correct or more valid
> values.  Add a kunit test to ensure it is working as expected.
> 
> Signed-off-by: SJ Park <[email protected]>
> ---
>  mm/damon/tests/core-kunit.h | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> index a4164ac489a61..d0bed01a5b7fe 100644
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -625,6 +625,27 @@ static void damon_test_set_regions(struct kunit *test)
>                       (struct damon_addr_range[]){}, 0, -EINVAL);
>  }
>  
> +static void damon_test_nr_samples_per_aggr(struct kunit *test)
> +{
> +     struct damon_attrs attrs = {
> +             .sample_interval = 0,
> +             .aggr_interval = 0,
> +     };
> +

Hi SJ,

A small question about the first test case.

Both `sample_interval` and `aggr_interval` are zero here.  Since
`sample_interval` is the denominator in `damon_nr_samples_per_aggr()`,
would it be better to keep `aggr_interval` non-zero when testing the
zero `sample_interval` case?

This would make the test explicitly cover the divide-by-zero protection.
If the `aggr_interval == 0` behavior is also worth covering, perhaps it
could be tested separately.

Thanks,
Kunwu


> +     /* Zero aggregation interval doesn't cause division by zero */
> +     KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs), 1);
> +
> +     /*
> +      * Too large aggregation interval on 64 bit system doesn't cause
> +      * overflow
> +      */
> +     if (ULONG_MAX > UINT_MAX) {
> +             attrs.aggr_interval = (unsigned long)UINT_MAX + 1;
> +             KUNIT_EXPECT_EQ(test, damon_nr_samples_per_aggr(&attrs),
> +                             UINT_MAX);
> +     }
> +}
> +
>  static void damon_test_update_monitoring_result(struct kunit *test)
>  {
>       struct damon_attrs old_attrs = {
> @@ -1736,6 +1757,7 @@ static struct kunit_case damon_test_cases[] = {
>       KUNIT_CASE(damon_test_split_above_half_progresses),
>       KUNIT_CASE(damon_test_ops_registration),
>       KUNIT_CASE(damon_test_set_regions),
> +     KUNIT_CASE(damon_test_nr_samples_per_aggr),
>       KUNIT_CASE(damon_test_update_monitoring_result),
>       KUNIT_CASE(damon_test_set_attrs),
>       KUNIT_CASE(damon_test_mvsum),
> -- 
> 2.47.3
> 

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

Reply via email to