Lines Matching +full:filter +full:- +full:order
1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright (c) 2017-2018 Microsoft Corporation
5 * Copyright (c) 2018-2020 Oracle
33 return (__force unsigned int)xa->xa_flags & 3; in xa_lock_type()
58 return xa->xa_flags & XA_FLAGS_TRACK_FREE; in xa_track_free()
63 return xa->xa_flags & XA_FLAGS_ZERO_BUSY; in xa_zero_busy()
68 if (!(xa->xa_flags & XA_FLAGS_MARK(mark))) in xa_mark_set()
69 xa->xa_flags |= XA_FLAGS_MARK(mark); in xa_mark_set()
74 if (xa->xa_flags & XA_FLAGS_MARK(mark)) in xa_mark_clear()
75 xa->xa_flags &= ~(XA_FLAGS_MARK(mark)); in xa_mark_clear()
80 return node->marks[(__force unsigned)mark]; in node_marks()
118 * xas_squash_marks() - Merge all marks to the first entry
127 unsigned int limit = xas->xa_offset + xas->xa_sibs + 1; in xas_squash_marks()
129 if (!xas->xa_sibs) in xas_squash_marks()
133 unsigned long *marks = xas->xa_node->marks[mark]; in xas_squash_marks()
134 if (find_next_bit(marks, limit, xas->xa_offset + 1) == limit) in xas_squash_marks()
136 __set_bit(xas->xa_offset, marks); in xas_squash_marks()
137 bitmap_clear(marks, xas->xa_offset + 1, xas->xa_sibs); in xas_squash_marks()
144 return (index >> node->shift) & XA_CHUNK_MASK; in get_offset()
149 xas->xa_offset = get_offset(xas->xa_index, xas->xa_node); in xas_set_offset()
155 unsigned int shift = xas->xa_node->shift; in xas_move_index()
156 xas->xa_index &= ~XA_CHUNK_MASK << shift; in xas_move_index()
157 xas->xa_index += offset << shift; in xas_move_index()
162 xas->xa_offset++; in xas_advance()
163 xas_move_index(xas, xas->xa_offset); in xas_advance()
168 xas->xa_node = XAS_BOUNDS; in set_bounds()
176 * of the xarray, return NULL without changing @xas->xa_node. Otherwise
177 * set @xas->xa_node to NULL and return the current head of the array.
188 entry = xa_head(xas->xa); in xas_start()
190 if (xas->xa_index) in xas_start()
193 if ((xas->xa_index >> xa_to_node(entry)->shift) > XA_CHUNK_MASK) in xas_start()
197 xas->xa_node = NULL; in xas_start()
203 unsigned int offset = get_offset(xas->xa_index, node); in xas_descend()
204 void *entry = xa_entry(xas->xa, node, offset); in xas_descend()
206 xas->xa_node = node; in xas_descend()
209 entry = xa_entry(xas->xa, node, offset); in xas_descend()
212 xas->xa_offset = offset; in xas_descend()
217 * xas_load() - Load an entry from the XArray (advanced).
224 * If the xa_state is set up to operate on a multi-index entry, xas_load()
238 if (xas->xa_shift > node->shift) in xas_load()
241 if (node->shift == 0) in xas_load()
256 XA_NODE_BUG_ON(node, !list_empty(&node->private_list)); in xa_node_free()
257 node->array = XA_RCU_FREE; in xa_node_free()
258 call_rcu(&node->rcu_head, radix_tree_node_rcu_free); in xa_node_free()
262 * xas_destroy() - Free any resources allocated during the XArray operation.
265 * This function is now internal-only.
269 struct xa_node *next, *node = xas->xa_alloc; in xas_destroy()
272 XA_NODE_BUG_ON(node, !list_empty(&node->private_list)); in xas_destroy()
273 next = rcu_dereference_raw(node->parent); in xas_destroy()
274 radix_tree_node_rcu_free(&node->rcu_head); in xas_destroy()
275 xas->xa_alloc = node = next; in xas_destroy()
280 * xas_nomem() - Allocate memory if needed.
299 if (xas->xa_node != XA_ERROR(-ENOMEM)) { in xas_nomem()
303 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in xas_nomem()
305 xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp); in xas_nomem()
306 if (!xas->xa_alloc) in xas_nomem()
308 xas->xa_alloc->parent = NULL; in xas_nomem()
309 XA_NODE_BUG_ON(xas->xa_alloc, !list_empty(&xas->xa_alloc->private_list)); in xas_nomem()
310 xas->xa_node = XAS_RESTART; in xas_nomem()
316 * __xas_nomem() - Drop locks and allocate memory if needed.
325 __must_hold(xas->xa->xa_lock) in __xas_nomem()
327 unsigned int lock_type = xa_lock_type(xas->xa); in __xas_nomem()
329 if (xas->xa_node != XA_ERROR(-ENOMEM)) { in __xas_nomem()
333 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in __xas_nomem()
337 xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp); in __xas_nomem()
340 xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp); in __xas_nomem()
342 if (!xas->xa_alloc) in __xas_nomem()
344 xas->xa_alloc->parent = NULL; in __xas_nomem()
345 XA_NODE_BUG_ON(xas->xa_alloc, !list_empty(&xas->xa_alloc->private_list)); in __xas_nomem()
346 xas->xa_node = XAS_RESTART; in __xas_nomem()
352 if (xas->xa_update) in xas_update()
353 xas->xa_update(node); in xas_update()
355 XA_NODE_BUG_ON(node, !list_empty(&node->private_list)); in xas_update()
360 struct xa_node *parent = xas->xa_node; in xas_alloc()
361 struct xa_node *node = xas->xa_alloc; in xas_alloc()
367 xas->xa_alloc = NULL; in xas_alloc()
371 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in xas_alloc()
376 xas_set_err(xas, -ENOMEM); in xas_alloc()
382 node->offset = xas->xa_offset; in xas_alloc()
383 parent->count++; in xas_alloc()
384 XA_NODE_BUG_ON(node, parent->count > XA_CHUNK_SIZE); in xas_alloc()
388 XA_NODE_BUG_ON(node, !list_empty(&node->private_list)); in xas_alloc()
389 node->shift = shift; in xas_alloc()
390 node->count = 0; in xas_alloc()
391 node->nr_values = 0; in xas_alloc()
392 RCU_INIT_POINTER(node->parent, xas->xa_node); in xas_alloc()
393 node->array = xas->xa; in xas_alloc()
402 return (xas->xa_sibs + 1UL) << xas->xa_shift; in xas_size()
408 * in order to add the entry described by @xas. Because we cannot store a
409 * multi-index entry at index 0, the calculation is a little more complex
414 unsigned long max = xas->xa_index; in xas_max()
417 if (xas->xa_shift || xas->xa_sibs) { in xas_max()
418 unsigned long mask = xas_size(xas) - 1; in xas_max()
433 return (XA_CHUNK_SIZE << xa_to_node(entry)->shift) - 1; in max_index()
438 struct xarray *xa = xas->xa; in xas_shrink()
439 struct xa_node *node = xas->xa_node; in xas_shrink()
444 XA_NODE_BUG_ON(node, node->count > XA_CHUNK_SIZE); in xas_shrink()
445 if (node->count != 1) in xas_shrink()
450 if (!xa_is_node(entry) && node->shift) in xas_shrink()
454 xas->xa_node = XAS_BOUNDS; in xas_shrink()
456 RCU_INIT_POINTER(xa->xa_head, entry); in xas_shrink()
460 node->count = 0; in xas_shrink()
461 node->nr_values = 0; in xas_shrink()
463 RCU_INIT_POINTER(node->slots[0], XA_RETRY_ENTRY); in xas_shrink()
469 node->parent = NULL; in xas_shrink()
474 * xas_delete_node() - Attempt to delete an xa_node
477 * Attempts to delete the @xas->xa_node. This will fail if xa->node has
478 * a non-zero reference count.
482 struct xa_node *node = xas->xa_node; in xas_delete_node()
487 XA_NODE_BUG_ON(node, node->count > XA_CHUNK_SIZE); in xas_delete_node()
488 if (node->count) in xas_delete_node()
491 parent = xa_parent_locked(xas->xa, node); in xas_delete_node()
492 xas->xa_node = parent; in xas_delete_node()
493 xas->xa_offset = node->offset; in xas_delete_node()
497 xas->xa->xa_head = NULL; in xas_delete_node()
498 xas->xa_node = XAS_BOUNDS; in xas_delete_node()
502 parent->slots[xas->xa_offset] = NULL; in xas_delete_node()
503 parent->count--; in xas_delete_node()
504 XA_NODE_BUG_ON(parent, parent->count > XA_CHUNK_SIZE); in xas_delete_node()
509 if (!node->parent) in xas_delete_node()
514 * xas_free_nodes() - Free this node and all nodes that it references
528 void *entry = xa_entry_locked(xas->xa, node, offset); in xas_free_nodes()
530 if (node->shift && xa_is_node(entry)) { in xas_free_nodes()
536 RCU_INIT_POINTER(node->slots[offset], XA_RETRY_ENTRY); in xas_free_nodes()
541 parent = xa_parent_locked(xas->xa, node); in xas_free_nodes()
542 offset = node->offset + 1; in xas_free_nodes()
543 node->count = 0; in xas_free_nodes()
544 node->nr_values = 0; in xas_free_nodes()
556 * sufficient height to be able to contain @xas->xa_index
560 struct xarray *xa = xas->xa; in xas_expand()
573 shift = node->shift + XA_CHUNK_SHIFT; in xas_expand()
575 xas->xa_node = NULL; in xas_expand()
583 return -ENOMEM; in xas_expand()
585 node->count = 1; in xas_expand()
587 node->nr_values = 1; in xas_expand()
588 RCU_INIT_POINTER(node->slots[0], head); in xas_expand()
611 xa_to_node(head)->offset = 0; in xas_expand()
612 rcu_assign_pointer(xa_to_node(head)->parent, node); in xas_expand()
615 rcu_assign_pointer(xa->xa_head, head); in xas_expand()
621 xas->xa_node = node; in xas_expand()
626 * xas_create() - Create a slot to store an entry in.
640 struct xarray *xa = xas->xa; in xas_create()
643 struct xa_node *node = xas->xa_node; in xas_create()
645 unsigned int order = xas->xa_shift; in xas_create() local
649 xas->xa_node = NULL; in xas_create()
658 slot = &xa->xa_head; in xas_create()
662 unsigned int offset = xas->xa_offset; in xas_create()
664 shift = node->shift; in xas_create()
666 slot = &node->slots[offset]; in xas_create()
670 slot = &xa->xa_head; in xas_create()
673 while (shift > order) { in xas_create()
674 shift -= XA_CHUNK_SHIFT; in xas_create()
688 slot = &node->slots[xas->xa_offset]; in xas_create()
695 * xas_create_range() - Ensure that stores to this range will succeed
699 * create single-index entries and positions it at the beginning of the
701 * converted to use multi-index entries.
705 unsigned long index = xas->xa_index; in xas_create_range()
706 unsigned char shift = xas->xa_shift; in xas_create_range()
707 unsigned char sibs = xas->xa_sibs; in xas_create_range()
709 xas->xa_index |= ((sibs + 1UL) << shift) - 1; in xas_create_range()
710 if (xas_is_node(xas) && xas->xa_node->shift == xas->xa_shift) in xas_create_range()
711 xas->xa_offset |= sibs; in xas_create_range()
712 xas->xa_shift = 0; in xas_create_range()
713 xas->xa_sibs = 0; in xas_create_range()
719 if (xas->xa_index <= (index | XA_CHUNK_MASK)) in xas_create_range()
721 xas->xa_index -= XA_CHUNK_SIZE; in xas_create_range()
724 struct xa_node *node = xas->xa_node; in xas_create_range()
725 xas->xa_node = xa_parent_locked(xas->xa, node); in xas_create_range()
726 xas->xa_offset = node->offset - 1; in xas_create_range()
727 if (node->offset != 0) in xas_create_range()
733 xas->xa_shift = shift; in xas_create_range()
734 xas->xa_sibs = sibs; in xas_create_range()
735 xas->xa_index = index; in xas_create_range()
738 xas->xa_index = index; in xas_create_range()
739 if (xas->xa_node) in xas_create_range()
750 node->count += count; in update_node()
751 node->nr_values += values; in update_node()
752 XA_NODE_BUG_ON(node, node->count > XA_CHUNK_SIZE); in update_node()
753 XA_NODE_BUG_ON(node, node->nr_values > XA_CHUNK_SIZE); in update_node()
760 * xas_store() - Store this entry in the XArray.
764 * If @xas is operating on a multi-index entry, the entry returned by this
766 * may be %NULL, even if there are non-NULL entries at some of the indices
775 void __rcu **slot = &xas->xa->xa_head; in xas_store()
791 node = xas->xa_node; in xas_store()
792 if (node && (xas->xa_shift < node->shift)) in xas_store()
793 xas->xa_sibs = 0; in xas_store()
794 if ((first == entry) && !xas->xa_sibs) in xas_store()
798 offset = xas->xa_offset; in xas_store()
799 max = xas->xa_offset + xas->xa_sibs; in xas_store()
801 slot = &node->slots[offset]; in xas_store()
802 if (xas->xa_sibs) in xas_store()
817 if (xa_is_node(next) && (!node || node->shift)) in xas_store()
821 count += !next - !entry; in xas_store()
822 values += !xa_is_value(first) - !value; in xas_store()
827 entry = xa_mk_sibling(xas->xa_offset); in xas_store()
832 next = xa_entry_locked(xas->xa, node, ++offset); in xas_store()
847 * xas_get_mark() - Returns the state of this mark.
858 if (!xas->xa_node) in xas_get_mark()
859 return xa_marked(xas->xa, mark); in xas_get_mark()
860 return node_get_mark(xas->xa_node, xas->xa_offset, mark); in xas_get_mark()
865 * xas_set_mark() - Sets the mark on this entry and its parents.
875 struct xa_node *node = xas->xa_node; in xas_set_mark()
876 unsigned int offset = xas->xa_offset; in xas_set_mark()
884 offset = node->offset; in xas_set_mark()
885 node = xa_parent_locked(xas->xa, node); in xas_set_mark()
888 if (!xa_marked(xas->xa, mark)) in xas_set_mark()
889 xa_mark_set(xas->xa, mark); in xas_set_mark()
894 * xas_clear_mark() - Clears the mark on this entry and its parents.
904 struct xa_node *node = xas->xa_node; in xas_clear_mark()
905 unsigned int offset = xas->xa_offset; in xas_clear_mark()
916 offset = node->offset; in xas_clear_mark()
917 node = xa_parent_locked(xas->xa, node); in xas_clear_mark()
920 if (xa_marked(xas->xa, mark)) in xas_clear_mark()
921 xa_mark_clear(xas->xa, mark); in xas_clear_mark()
926 * xas_init_marks() - Initialise all marks for the entry
941 if (xa_track_free(xas->xa) && mark == XA_FREE_MARK) in xas_init_marks()
987 * xas_split_alloc() - Allocate memory for splitting an entry.
990 * @order: New entry order.
995 * to prepare for the upcoming split of an entry of @order size into
996 * entries of the order stored in the @xas.
1000 void xas_split_alloc(struct xa_state *xas, void *entry, unsigned int order, in xas_split_alloc() argument
1003 unsigned int sibs = (1 << (order % XA_CHUNK_SHIFT)) - 1; in xas_split_alloc()
1004 unsigned int mask = xas->xa_sibs; in xas_split_alloc()
1007 if (WARN_ON(xas->xa_shift + 2 * XA_CHUNK_SHIFT < order)) in xas_split_alloc()
1009 if (xas->xa_shift + XA_CHUNK_SHIFT > order) in xas_split_alloc()
1020 node->array = xas->xa; in xas_split_alloc()
1023 RCU_INIT_POINTER(node->slots[i], entry); in xas_split_alloc()
1026 RCU_INIT_POINTER(node->slots[i], sibling); in xas_split_alloc()
1029 RCU_INIT_POINTER(node->parent, xas->xa_alloc); in xas_split_alloc()
1030 xas->xa_alloc = node; in xas_split_alloc()
1031 } while (sibs-- > 0); in xas_split_alloc()
1036 xas_set_err(xas, -ENOMEM); in xas_split_alloc()
1041 * xas_split() - Split a multi-index entry into smaller entries.
1044 * @order: New entry order.
1050 void xas_split(struct xa_state *xas, void *entry, unsigned int order) in xas_split() argument
1052 unsigned int sibs = (1 << (order % XA_CHUNK_SHIFT)) - 1; in xas_split()
1058 node = xas->xa_node; in xas_split()
1062 marks = node_get_marks(node, xas->xa_offset); in xas_split()
1064 offset = xas->xa_offset + sibs; in xas_split()
1066 if (xas->xa_shift < node->shift) { in xas_split()
1067 struct xa_node *child = xas->xa_alloc; in xas_split()
1069 xas->xa_alloc = rcu_dereference_raw(child->parent); in xas_split()
1070 child->shift = node->shift - XA_CHUNK_SHIFT; in xas_split()
1071 child->offset = offset; in xas_split()
1072 child->count = XA_CHUNK_SIZE; in xas_split()
1073 child->nr_values = xa_is_value(entry) ? in xas_split()
1075 RCU_INIT_POINTER(child->parent, node); in xas_split()
1077 rcu_assign_pointer(node->slots[offset], in xas_split()
1080 values--; in xas_split()
1082 unsigned int canon = offset - xas->xa_sibs; in xas_split()
1085 rcu_assign_pointer(node->slots[canon], entry); in xas_split()
1087 rcu_assign_pointer(node->slots[offset--], in xas_split()
1089 values += (xa_is_value(entry) - xa_is_value(curr)) * in xas_split()
1090 (xas->xa_sibs + 1); in xas_split()
1092 } while (offset-- > xas->xa_offset); in xas_split()
1094 node->nr_values += values; in xas_split()
1100 * xas_pause() - Pause a walk to drop a lock.
1104 * order to yield to a higher priority thread or carry out an operation
1116 struct xa_node *node = xas->xa_node; in xas_pause()
1121 xas->xa_node = XAS_RESTART; in xas_pause()
1123 unsigned long offset = xas->xa_offset; in xas_pause()
1125 if (!xa_is_sibling(xa_entry(xas->xa, node, offset))) in xas_pause()
1128 xas->xa_index += (offset - xas->xa_offset) << node->shift; in xas_pause()
1129 if (xas->xa_index == 0) in xas_pause()
1130 xas->xa_node = XAS_BOUNDS; in xas_pause()
1132 xas->xa_index++; in xas_pause()
1138 * __xas_prev() - Find the previous entry in the XArray.
1148 if (!xas_frozen(xas->xa_node)) in __xas_prev()
1149 xas->xa_index--; in __xas_prev()
1150 if (!xas->xa_node) in __xas_prev()
1152 if (xas_not_node(xas->xa_node)) in __xas_prev()
1155 if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) in __xas_prev()
1156 xas->xa_offset--; in __xas_prev()
1158 while (xas->xa_offset == 255) { in __xas_prev()
1159 xas->xa_offset = xas->xa_node->offset - 1; in __xas_prev()
1160 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_prev()
1161 if (!xas->xa_node) in __xas_prev()
1166 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_prev()
1170 xas->xa_node = xa_to_node(entry); in __xas_prev()
1177 * __xas_next() - Find the next entry in the XArray.
1187 if (!xas_frozen(xas->xa_node)) in __xas_next()
1188 xas->xa_index++; in __xas_next()
1189 if (!xas->xa_node) in __xas_next()
1191 if (xas_not_node(xas->xa_node)) in __xas_next()
1194 if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) in __xas_next()
1195 xas->xa_offset++; in __xas_next()
1197 while (xas->xa_offset == XA_CHUNK_SIZE) { in __xas_next()
1198 xas->xa_offset = xas->xa_node->offset + 1; in __xas_next()
1199 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_next()
1200 if (!xas->xa_node) in __xas_next()
1205 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_next()
1209 xas->xa_node = xa_to_node(entry); in __xas_next()
1216 * xas_find() - Find the next present entry in the XArray.
1235 if (xas_error(xas) || xas->xa_node == XAS_BOUNDS) in xas_find()
1237 if (xas->xa_index > max) in xas_find()
1240 if (!xas->xa_node) { in xas_find()
1241 xas->xa_index = 1; in xas_find()
1243 } else if (xas->xa_node == XAS_RESTART) { in xas_find()
1245 if (entry || xas_not_node(xas->xa_node)) in xas_find()
1247 } else if (!xas->xa_node->shift && in xas_find()
1248 xas->xa_offset != (xas->xa_index & XA_CHUNK_MASK)) { in xas_find()
1249 xas->xa_offset = ((xas->xa_index - 1) & XA_CHUNK_MASK) + 1; in xas_find()
1254 while (xas->xa_node && (xas->xa_index <= max)) { in xas_find()
1255 if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { in xas_find()
1256 xas->xa_offset = xas->xa_node->offset + 1; in xas_find()
1257 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find()
1261 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find()
1263 xas->xa_node = xa_to_node(entry); in xas_find()
1264 xas->xa_offset = 0; in xas_find()
1273 if (!xas->xa_node) in xas_find()
1274 xas->xa_node = XAS_BOUNDS; in xas_find()
1280 * xas_find_marked() - Find the next marked entry in the XArray.
1291 * set to the bounds state and xas->xa_index is set to the smallest index
1308 if (xas->xa_index > max) in xas_find_marked()
1311 if (!xas->xa_node) { in xas_find_marked()
1312 xas->xa_index = 1; in xas_find_marked()
1314 } else if (xas_top(xas->xa_node)) { in xas_find_marked()
1316 entry = xa_head(xas->xa); in xas_find_marked()
1317 xas->xa_node = NULL; in xas_find_marked()
1318 if (xas->xa_index > max_index(entry)) in xas_find_marked()
1321 if (xa_marked(xas->xa, mark)) in xas_find_marked()
1323 xas->xa_index = 1; in xas_find_marked()
1326 xas->xa_node = xa_to_node(entry); in xas_find_marked()
1327 xas->xa_offset = xas->xa_index >> xas->xa_node->shift; in xas_find_marked()
1330 while (xas->xa_index <= max) { in xas_find_marked()
1331 if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { in xas_find_marked()
1332 xas->xa_offset = xas->xa_node->offset + 1; in xas_find_marked()
1333 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find_marked()
1334 if (!xas->xa_node) in xas_find_marked()
1341 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1343 xas->xa_offset = xa_to_sibling(entry); in xas_find_marked()
1344 xas_move_index(xas, xas->xa_offset); in xas_find_marked()
1349 if (offset > xas->xa_offset) { in xas_find_marked()
1353 if ((xas->xa_index - 1) >= max) in xas_find_marked()
1355 xas->xa_offset = offset; in xas_find_marked()
1360 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1361 if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK)) in xas_find_marked()
1365 xas->xa_node = xa_to_node(entry); in xas_find_marked()
1370 if (xas->xa_index > max) in xas_find_marked()
1374 xas->xa_node = XAS_RESTART; in xas_find_marked()
1380 * xas_find_conflict() - Find the next present entry in a range.
1395 if (!xas->xa_node) in xas_find_conflict()
1398 if (xas_top(xas->xa_node)) { in xas_find_conflict()
1410 if (xas->xa_node->shift > xas->xa_shift) in xas_find_conflict()
1414 if (xas->xa_node->shift == xas->xa_shift) { in xas_find_conflict()
1415 if ((xas->xa_offset & xas->xa_sibs) == xas->xa_sibs) in xas_find_conflict()
1417 } else if (xas->xa_offset == XA_CHUNK_MASK) { in xas_find_conflict()
1418 xas->xa_offset = xas->xa_node->offset; in xas_find_conflict()
1419 xas->xa_node = xa_parent_locked(xas->xa, xas->xa_node); in xas_find_conflict()
1420 if (!xas->xa_node) in xas_find_conflict()
1424 curr = xa_entry_locked(xas->xa, xas->xa_node, ++xas->xa_offset); in xas_find_conflict()
1428 xas->xa_node = xa_to_node(curr); in xas_find_conflict()
1429 xas->xa_offset = 0; in xas_find_conflict()
1430 curr = xa_entry_locked(xas->xa, xas->xa_node, 0); in xas_find_conflict()
1435 xas->xa_offset -= xas->xa_sibs; in xas_find_conflict()
1441 * xa_load() - Load an entry from an XArray.
1470 curr = xas->xa_node; in xas_result()
1475 * __xa_erase() - Erase this entry from the XArray while locked.
1480 * If the index is part of a multi-index entry, all indices will be erased
1481 * and none of the entries will be part of a multi-index entry.
1494 * xa_erase() - Erase this entry from the XArray.
1499 * If the index is part of a multi-index entry, all indices will be erased
1500 * and none of the entries will be part of a multi-index entry.
1518 * __xa_store() - Store this entry in the XArray.
1538 return XA_ERROR(-EINVAL); in __xa_store()
1553 * xa_store() - Store this entry in the XArray.
1560 * Storing into an existing multi-index entry updates the entry of every index.
1565 * Return: The old entry at this index on success, xa_err(-EINVAL) if @entry
1566 * cannot be stored in an XArray, or xa_err(-ENOMEM) if memory allocation
1582 * __xa_cmpxchg() - Store this entry in the XArray.
1604 return XA_ERROR(-EINVAL); in __xa_cmpxchg()
1620 * __xa_insert() - Store this entry in the XArray if no entry is present.
1632 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
1633 * -ENOMEM if memory could not be allocated.
1641 return -EINVAL; in __xa_insert()
1652 xas_set_err(&xas, -EBUSY); in __xa_insert()
1665 unsigned long sibs = last - first; in xas_set_range()
1684 sibs = XA_CHUNK_MASK - offset; in xas_set_range()
1685 if ((((first + sibs + 1) << shift) - 1) > last) in xas_set_range()
1686 sibs -= 1; in xas_set_range()
1688 xas->xa_shift = shift; in xas_set_range()
1689 xas->xa_sibs = sibs; in xas_set_range()
1693 * xa_store_range() - Store this entry at a range of indices in the XArray.
1702 * Storing into an existing multi-index entry updates the entry of every index.
1707 * Return: %NULL on success, xa_err(-EINVAL) if @entry cannot be stored in
1708 * an XArray, or xa_err(-ENOMEM) if memory allocation failed.
1716 return XA_ERROR(-EINVAL); in xa_store_range()
1718 return XA_ERROR(-EINVAL); in xa_store_range()
1723 unsigned int order = BITS_PER_LONG; in xa_store_range() local
1725 order = __ffs(last + 1); in xa_store_range()
1726 xas_set_order(&xas, last, order); in xa_store_range()
1747 * xa_get_order() - Get the order of an entry.
1751 * Return: A number between 0 and 63 indicating the order of the entry.
1757 int order = 0; in xa_get_order() local
1769 unsigned int slot = xas.xa_offset + (1 << order); in xa_get_order()
1773 if (!xa_is_sibling(xas.xa_node->slots[slot])) in xa_get_order()
1775 order++; in xa_get_order()
1778 order += xas.xa_node->shift; in xa_get_order()
1782 return order; in xa_get_order()
1788 * __xa_alloc() - Find somewhere to store this entry in the XArray.
1801 * Return: 0 on success, -ENOMEM if memory could not be allocated or
1802 * -EBUSY if there are no free entries in @limit.
1810 return -EINVAL; in __xa_alloc()
1812 return -EINVAL; in __xa_alloc()
1821 xas_set_err(&xas, -EBUSY); in __xa_alloc()
1833 * __xa_alloc_cyclic() - Find somewhere to store this entry in the XArray.
1850 * allocation succeeded after wrapping, -ENOMEM if memory could not be
1851 * allocated or -EBUSY if there are no free entries in @limit.
1861 if ((xa->xa_flags & XA_FLAGS_ALLOC_WRAPPED) && ret == 0) { in __xa_alloc_cyclic()
1862 xa->xa_flags &= ~XA_FLAGS_ALLOC_WRAPPED; in __xa_alloc_cyclic()
1876 xa->xa_flags |= XA_FLAGS_ALLOC_WRAPPED; in __xa_alloc_cyclic()
1883 * __xa_set_mark() - Set this mark on this entry while locked.
1903 * __xa_clear_mark() - Clear this mark on this entry while locked.
1921 * xa_get_mark() - Inquire whether this mark is set on this entry.
1953 * xa_set_mark() - Set this mark on this entry.
1971 * xa_clear_mark() - Clear this mark on this entry.
1989 * xa_find() - Search the XArray for an entry.
1993 * @filter: Selection criterion.
1995 * Finds the entry in @xa which matches the @filter, and has the lowest
2006 unsigned long max, xa_mark_t filter) in xa_find() argument
2013 if ((__force unsigned int)filter < XA_MAX_MARKS) in xa_find()
2014 entry = xas_find_marked(&xas, max, filter); in xa_find()
2028 struct xa_node *node = xas->xa_node; in xas_sibling()
2033 mask = (XA_CHUNK_SIZE << node->shift) - 1; in xas_sibling()
2034 return (xas->xa_index & mask) > in xas_sibling()
2035 ((unsigned long)xas->xa_offset << node->shift); in xas_sibling()
2039 * xa_find_after() - Search the XArray for a present entry.
2043 * @filter: Selection criterion.
2045 * Finds the entry in @xa which matches the @filter and has the lowest
2056 unsigned long max, xa_mark_t filter) in xa_find_after() argument
2066 if ((__force unsigned int)filter < XA_MAX_MARKS) in xa_find_after()
2067 entry = xas_find_marked(&xas, max, filter); in xa_find_after()
2125 * xa_extract() - Copy selected entries from the XArray into a normal array.
2131 * @filter: Selection criterion.
2133 * Copies up to @n entries that match @filter from the XArray. The
2136 * The @filter may be an XArray mark value, in which case entries which are
2153 unsigned long max, unsigned int n, xa_mark_t filter) in xa_extract() argument
2160 if ((__force unsigned int)filter < XA_MAX_MARKS) in xa_extract()
2161 return xas_extract_marked(&xas, dst, max, n, filter); in xa_extract()
2167 * xa_delete_node() - Private interface for workingset code.
2176 .xa = node->array, in xa_delete_node()
2177 .xa_index = (unsigned long)node->offset << in xa_delete_node()
2178 (node->shift + XA_CHUNK_SHIFT), in xa_delete_node()
2179 .xa_shift = node->shift + XA_CHUNK_SHIFT, in xa_delete_node()
2180 .xa_offset = node->offset, in xa_delete_node()
2181 .xa_node = xa_parent_locked(node->array, node), in xa_delete_node()
2190 * xa_destroy() - Free all internal data structures.
2197 * Context: Any context. Takes and releases the xa_lock, interrupt-safe.
2208 RCU_INIT_POINTER(xa->xa_head, NULL); in xa_destroy()
2233 node, node->parent ? "offset" : "max", node->offset, in xa_dump_node()
2234 node->parent, node->shift, node->count, node->nr_values, in xa_dump_node()
2235 node->array, node->private_list.prev, node->private_list.next); in xa_dump_node()
2238 pr_cont(" %lx", node->marks[i][j]); in xa_dump_node()
2247 pr_info("0-%lu: ", ~0UL); in xa_dump_index()
2249 pr_info("%lu-%lu: ", index, index | ((1UL << shift) - 1)); in xa_dump_index()
2267 xa_dump_entry(node->slots[i], in xa_dump_entry()
2268 index + (i << node->shift), node->shift); in xa_dump_entry()
2287 void *entry = xa->xa_head; in xa_dump()
2291 xa->xa_flags, xa_marked(xa, XA_MARK_0), in xa_dump()
2294 shift = xa_to_node(entry)->shift + XA_CHUNK_SHIFT; in xa_dump()