Skip to content

Commit f92e1a8

Browse files
howlettbrauner
authored andcommitted
test_maple_tree: testing the cyclic allocation
This tests the interactions of the cyclic allocations, the maple state index and last, and overflow. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Link: https://lore.kernel.org/r/170820144894.6328.13052830860966450674.stgit@91.116.238.104.host.secureserver.net Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 9b6713c commit f92e1a8

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

lib/test_maple_tree.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,45 @@ static noinline void __init check_state_handling(struct maple_tree *mt)
35993599
mas_unlock(&mas);
36003600
}
36013601

3602+
static noinline void __init alloc_cyclic_testing(struct maple_tree *mt)
3603+
{
3604+
unsigned long location;
3605+
unsigned long next;
3606+
int ret = 0;
3607+
MA_STATE(mas, mt, 0, 0);
3608+
3609+
next = 0;
3610+
mtree_lock(mt);
3611+
for (int i = 0; i < 100; i++) {
3612+
mas_alloc_cyclic(&mas, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
3613+
MAS_BUG_ON(&mas, i != location - 2);
3614+
MAS_BUG_ON(&mas, mas.index != location);
3615+
MAS_BUG_ON(&mas, mas.last != location);
3616+
MAS_BUG_ON(&mas, i != next - 3);
3617+
}
3618+
3619+
mtree_unlock(mt);
3620+
mtree_destroy(mt);
3621+
next = 0;
3622+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
3623+
for (int i = 0; i < 100; i++) {
3624+
mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
3625+
MT_BUG_ON(mt, i != location - 2);
3626+
MT_BUG_ON(mt, i != next - 3);
3627+
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
3628+
}
3629+
3630+
mtree_destroy(mt);
3631+
/* Overflow test */
3632+
next = ULONG_MAX - 1;
3633+
ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
3634+
MT_BUG_ON(mt, ret != 0);
3635+
ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
3636+
MT_BUG_ON(mt, ret != 0);
3637+
ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
3638+
MT_BUG_ON(mt, ret != 1);
3639+
}
3640+
36023641
static DEFINE_MTREE(tree);
36033642
static int __init maple_tree_seed(void)
36043643
{
@@ -3880,6 +3919,11 @@ static int __init maple_tree_seed(void)
38803919
check_state_handling(&tree);
38813920
mtree_destroy(&tree);
38823921

3922+
mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
3923+
alloc_cyclic_testing(&tree);
3924+
mtree_destroy(&tree);
3925+
3926+
38833927
#if defined(BENCH)
38843928
skip:
38853929
#endif

0 commit comments

Comments
 (0)