[RFC PATCH v3 2/2] XArray tests: Verify xa_erase behavior in check_split

Ackerley Tng
2026-02-23T07:34:31Z

Both __xa_store() and xa_erase() use xas_store() under the hood, but when
the entry being stored is NULL (as in the case of xa_erase()),
xas->xa_sibs (and max) is only checked if the next entry is not a sibling,
hence allowing xas_store() to keep iterating, hence updating
node->nr_values correctly.

Add xa_erase() to check_split tests that verify functionality, with the
added intent to illustrate the usage differences between __xa_store(),
xas_store() and xa_erase() with regard to multi-index XArrays.

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
lib/test_xarray.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index e71e8ff76900b..bb9471a3df65c 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -1874,6 +1874,10 @@ static void check_split_1(struct xarray *xa, unsigned long index,
rcu_read_unlock();
XA_BUG_ON(xa, found != 1 << (order - new_order));

+ for (i = 0; i < (1 << order); i += (1 << new_order))
+ xa_erase(xa, index + i);
+ XA_BUG_ON(xa, !xa_empty(xa));
+
xa_destroy(xa);
}

@@ -1926,6 +1930,10 @@ static void check_split_2(struct xarray *xa, unsigned long index,
}
rcu_read_unlock();
XA_BUG_ON(xa, found != 1 << (order - new_order));
+
+ for (i = 0; i < (1 << order); i += (1 << new_order))
+ xa_erase(xa, index + i);
+ XA_BUG_ON(xa, !xa_empty(xa));
out:
xas_destroy(&xas);
xa_destroy(xa);
--
2.53.0.345.g96ddfc5eaa-goog