aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_xarray.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2017-11-24 14:24:59 -0500
committerMatthew Wilcox <willy@infradead.org>2018-10-21 10:46:36 -0400
commita97e7904c0806309fd77103005bb7820c3f1c5e4 (patch)
tree8cfe89076cd837e7efee4e36a7904b5040eb9442 /lib/test_xarray.c
parentff9c745b81ff1e482167fd73558450e66ad43a33 (diff)
mm: Convert workingset to XArray
We construct an XA_STATE and use it to delete the node with xas_store() rather than adding a special function for this unique use case. Includes a test that simulates this usage for the test suite. Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r--lib/test_xarray.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index a752e6a37e6f..128c6489082f 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -863,6 +863,67 @@ static noinline void check_create_range(struct xarray *xa)
863 check_create_range_3(); 863 check_create_range_3();
864} 864}
865 865
866static LIST_HEAD(shadow_nodes);
867
868static void test_update_node(struct xa_node *node)
869{
870 if (node->count && node->count == node->nr_values) {
871 if (list_empty(&node->private_list))
872 list_add(&shadow_nodes, &node->private_list);
873 } else {
874 if (!list_empty(&node->private_list))
875 list_del_init(&node->private_list);
876 }
877}
878
879static noinline void shadow_remove(struct xarray *xa)
880{
881 struct xa_node *node;
882
883 xa_lock(xa);
884 while ((node = list_first_entry_or_null(&shadow_nodes,
885 struct xa_node, private_list))) {
886 XA_STATE(xas, node->array, 0);
887 XA_BUG_ON(xa, node->array != xa);
888 list_del_init(&node->private_list);
889 xas.xa_node = xa_parent_locked(node->array, node);
890 xas.xa_offset = node->offset;
891 xas.xa_shift = node->shift + XA_CHUNK_SHIFT;
892 xas_set_update(&xas, test_update_node);
893 xas_store(&xas, NULL);
894 }
895 xa_unlock(xa);
896}
897
898static noinline void check_workingset(struct xarray *xa, unsigned long index)
899{
900 XA_STATE(xas, xa, index);
901 xas_set_update(&xas, test_update_node);
902
903 do {
904 xas_lock(&xas);
905 xas_store(&xas, xa_mk_value(0));
906 xas_next(&xas);
907 xas_store(&xas, xa_mk_value(1));
908 xas_unlock(&xas);
909 } while (xas_nomem(&xas, GFP_KERNEL));
910
911 XA_BUG_ON(xa, list_empty(&shadow_nodes));
912
913 xas_lock(&xas);
914 xas_next(&xas);
915 xas_store(&xas, &xas);
916 XA_BUG_ON(xa, !list_empty(&shadow_nodes));
917
918 xas_store(&xas, xa_mk_value(2));
919 xas_unlock(&xas);
920 XA_BUG_ON(xa, list_empty(&shadow_nodes));
921
922 shadow_remove(xa);
923 XA_BUG_ON(xa, !list_empty(&shadow_nodes));
924 XA_BUG_ON(xa, !xa_empty(xa));
925}
926
866static noinline void check_destroy(struct xarray *xa) 927static noinline void check_destroy(struct xarray *xa)
867{ 928{
868 unsigned long index; 929 unsigned long index;
@@ -916,6 +977,10 @@ static int xarray_checks(void)
916 check_create_range(&array); 977 check_create_range(&array);
917 check_store_iter(&array); 978 check_store_iter(&array);
918 979
980 check_workingset(&array, 0);
981 check_workingset(&array, 64);
982 check_workingset(&array, 4096);
983
919 printk("XArray: %u of %u tests passed\n", tests_passed, tests_run); 984 printk("XArray: %u of %u tests passed\n", tests_passed, tests_run);
920 return (tests_run == tests_passed) ? 0 : -EINVAL; 985 return (tests_run == tests_passed) ? 0 : -EINVAL;
921} 986}