[PATCH 3/3] tools/testing/radix-tree: Test maple tree chaining mas_preallocate() calls

Liam R. Howlett posted 3 patches 3 months, 3 weeks ago
[PATCH 3/3] tools/testing/radix-tree: Test maple tree chaining mas_preallocate() calls
Posted by Liam R. Howlett 3 months, 3 weeks ago
Testing calling multiple mas_preallocate() calls in a row after
adjusting the maple state.  Ensures new calls to mas_preallocate() will
change the number of allocated nodes.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
 tools/testing/radix-tree/maple.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c
index 6a5b0342941c4..49e89dfad950c 100644
--- a/tools/testing/radix-tree/maple.c
+++ b/tools/testing/radix-tree/maple.c
@@ -35693,6 +35693,18 @@ static noinline void __init check_prealloc(struct maple_tree *mt)
 	allocated = mas_allocated(&mas);
 	height = mas_mt_height(&mas);
 	MT_BUG_ON(mt, allocated != 0);
+
+	/* Chaining multiple preallocations */
+	mt_set_in_rcu(mt);
+	mas_set_range(&mas, 800, 805); /* Slot store, should be 0 allocations */
+	MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
+	allocated = mas_allocated(&mas);
+	MT_BUG_ON(mt, allocated != 0);
+	mas.last = 809; /* Node store */
+	MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
+	allocated = mas_allocated(&mas);
+	MT_BUG_ON(mt, allocated != 1);
+	mas_store_prealloc(&mas, ptr);
 }
 /* End of preallocation testing */
 
-- 
2.47.2
Re: [PATCH 3/3] tools/testing/radix-tree: Test maple tree chaining mas_preallocate() calls
Posted by Lorenzo Stoakes 3 months, 3 weeks ago
On Mon, Jun 16, 2025 at 02:45:21PM -0400, Liam R. Howlett wrote:
> Testing calling multiple mas_preallocate() calls in a row after
> adjusting the maple state.  Ensures new calls to mas_preallocate() will
> change the number of allocated nodes.

Really helpful to have a regression test for such a fiddly thing!

>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>

Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  tools/testing/radix-tree/maple.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c
> index 6a5b0342941c4..49e89dfad950c 100644
> --- a/tools/testing/radix-tree/maple.c
> +++ b/tools/testing/radix-tree/maple.c
> @@ -35693,6 +35693,18 @@ static noinline void __init check_prealloc(struct maple_tree *mt)
>  	allocated = mas_allocated(&mas);
>  	height = mas_mt_height(&mas);
>  	MT_BUG_ON(mt, allocated != 0);
> +
> +	/* Chaining multiple preallocations */
> +	mt_set_in_rcu(mt);
> +	mas_set_range(&mas, 800, 805); /* Slot store, should be 0 allocations */
> +	MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
> +	allocated = mas_allocated(&mas);
> +	MT_BUG_ON(mt, allocated != 0);
> +	mas.last = 809; /* Node store */
> +	MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
> +	allocated = mas_allocated(&mas);
> +	MT_BUG_ON(mt, allocated != 1);
> +	mas_store_prealloc(&mas, ptr);
>  }
>  /* End of preallocation testing */
>
> --
> 2.47.2
>