Add multi-index XArray tests.
Tests were first introduced as part of '[RFC PATCH 00/11] shmem: high
order folios support in write path' [1]. I've created this new series with
Matthew Wilcox's feedback [2] regarding test 'XArray: add cmpxchg order test'.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
The full node is lost (not only the order) when using xa_cmpxchg with NULL
entry. Adding another (FIVE) entry at '1 << order' with the order information
does not keep the original node but duplicates it. I'm not sure if that's
the intention from the proposal you mentioned in [2] but please, let me know
your comments.
Changes since RFC:
* Update cmpxchg test to include another entry at 1 << order that
'keeps' the node around and order information.
* Update cmpxchg test to verify the entries and order in all tied
indexes.
* Drop previous Luis Chamberlain's review as changes are significant
from the RFC.
Daniel
Daniel Gomez (1):
XArray: add cmpxchg order test
Luis Chamberlain (1):
test_xarray: add tests for advanced multi-index use
lib/test_xarray.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 188 insertions(+)
--
2.39.2
XArray multi-index entries do not keep track of the order stored once
the entry is being marked as used with cmpxchg (conditionally replaced
with NULL). Add a test to check the order is actually lost. The test
also verifies the order and entries for all the tied indexes before and
after the NULL replacement with xa_cmpxchg.
Add another entry at 1 << order that keeps the node around and the order
information for the NULL-entry after xa_cmpxchg.
Signed-off-by: Daniel Gomez <[email protected]>
---
lib/test_xarray.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index 0572a3ec2cf8..3c19d12c1bf5 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -423,6 +423,59 @@ static noinline void check_cmpxchg(struct xarray *xa)
XA_BUG_ON(xa, !xa_empty(xa));
}
+static noinline void check_cmpxchg_order(struct xarray *xa)
+{
+#ifdef CONFIG_XARRAY_MULTI
+ void *FIVE = xa_mk_value(5);
+ unsigned int i, order = 3;
+
+ XA_BUG_ON(xa, xa_store_order(xa, 0, order, FIVE, GFP_KERNEL));
+
+ /* Check entry FIVE has the order saved */
+ XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != order);
+
+ /* Check all the tied indexes have the same entry and order */
+ for (i = 0; i < (1 << order); i++) {
+ XA_BUG_ON(xa, xa_load(xa, i) != FIVE);
+ XA_BUG_ON(xa, xa_get_order(xa, i) != order);
+ }
+
+ /* Ensure that nothing is stored at index '1 << order' */
+ XA_BUG_ON(xa, xa_load(xa, 1 << order) != NULL);
+
+ /*
+ * Additionally, keep the node information and the order at
+ * '1 << order'
+ */
+ XA_BUG_ON(xa, xa_store_order(xa, 1 << order, order, FIVE, GFP_KERNEL));
+ for (i = (1 << order); i < (1 << order) + (1 << order) - 1; i++) {
+ XA_BUG_ON(xa, xa_load(xa, i) != FIVE);
+ XA_BUG_ON(xa, xa_get_order(xa, i) != order);
+ }
+
+ /* Conditionally replace FIVE entry at index '0' with NULL */
+ XA_BUG_ON(xa, xa_cmpxchg(xa, 0, FIVE, NULL, GFP_KERNEL) != FIVE);
+
+ /* Verify the order is lost at FIVE (and old) entries */
+ XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != 0);
+
+ /* Verify the order and entries are lost in all the tied indexes */
+ for (i = 0; i < (1 << order); i++) {
+ XA_BUG_ON(xa, xa_load(xa, i) != NULL);
+ XA_BUG_ON(xa, xa_get_order(xa, i) != 0);
+ }
+
+ /* Verify node and order are kept at '1 << order' */
+ for (i = (1 << order); i < (1 << order) + (1 << order) - 1; i++) {
+ XA_BUG_ON(xa, xa_load(xa, i) != FIVE);
+ XA_BUG_ON(xa, xa_get_order(xa, i) != order);
+ }
+
+ xa_store_order(xa, 0, BITS_PER_LONG - 1, NULL, GFP_KERNEL);
+ XA_BUG_ON(xa, !xa_empty(xa));
+#endif
+}
+
static noinline void check_reserve(struct xarray *xa)
{
void *entry;
@@ -1934,6 +1987,7 @@ static int xarray_checks(void)
check_xas_erase(&array);
check_insert(&array);
check_cmpxchg(&array);
+ check_cmpxchg_order(&array);
check_reserve(&array);
check_reserve(&xa0);
check_multi_store(&array);
--
2.39.2
On Sat, Nov 04, 2023 at 01:57:45AM +0100, Daniel Gomez wrote:
> Add multi-index XArray tests.
>
> Tests were first introduced as part of '[RFC PATCH 00/11] shmem: high
> order folios support in write path' [1]. I've created this new series with
> Matthew Wilcox's feedback [2] regarding test 'XArray: add cmpxchg order test'.
>
> [1] https://lore.kernel.org/all/[email protected]/
> [2] https://lore.kernel.org/all/[email protected]/
>
> The full node is lost (not only the order) when using xa_cmpxchg with NULL
> entry. Adding another (FIVE) entry at '1 << order' with the order information
> does not keep the original node but duplicates it. I'm not sure if that's
> the intention from the proposal you mentioned in [2] but please, let me know
> your comments.
>
> Changes since RFC:
> * Update cmpxchg test to include another entry at 1 << order that
> 'keeps' the node around and order information.
> * Update cmpxchg test to verify the entries and order in all tied
> indexes.
> * Drop previous Luis Chamberlain's review as changes are significant
> from the RFC.
* Make cmpxchg_order test conditional to CONFIG_XARRAY_MULTI.
>
> Daniel
>
> Daniel Gomez (1):
> XArray: add cmpxchg order test
>
> Luis Chamberlain (1):
> test_xarray: add tests for advanced multi-index use
>
> lib/test_xarray.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 188 insertions(+)
>
> --
> 2.39.2