radix-tree.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. * Copyright (C) 2001 Momchil Velikov
  3. * Portions Copyright (C) 2001 Christoph Hellwig
  4. * Copyright (C) 2006 Nick Piggin
  5. * Copyright (C) 2012 Konstantin Khlebnikov
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2, or (at
  10. * your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef _LINUX_RADIX_TREE_H
  22. #define _LINUX_RADIX_TREE_H
  23. #include <linux/bitops.h>
  24. #include <linux/preempt.h>
  25. #include <linux/types.h>
  26. #include <linux/bug.h>
  27. #include <linux/kernel.h>
  28. #include <linux/rcupdate.h>
  29. /*
  30. * The bottom two bits of the slot determine how the remaining bits in the
  31. * slot are interpreted:
  32. *
  33. * 00 - data pointer
  34. * 01 - internal entry
  35. * 10 - exceptional entry
  36. * 11 - this bit combination is currently unused/reserved
  37. *
  38. * The internal entry may be a pointer to the next level in the tree, a
  39. * sibling entry, or an indicator that the entry in this slot has been moved
  40. * to another location in the tree and the lookup should be restarted. While
  41. * NULL fits the 'data pointer' pattern, it means that there is no entry in
  42. * the tree for this index (no matter what level of the tree it is found at).
  43. * This means that you cannot store NULL in the tree as a value for the index.
  44. */
  45. #define RADIX_TREE_ENTRY_MASK 3UL
  46. #define RADIX_TREE_INTERNAL_NODE 1UL
  47. /*
  48. * Most users of the radix tree store pointers but shmem/tmpfs stores swap
  49. * entries in the same tree. They are marked as exceptional entries to
  50. * distinguish them from pointers to struct page.
  51. * EXCEPTIONAL_ENTRY tests the bit, EXCEPTIONAL_SHIFT shifts content past it.
  52. */
  53. #define RADIX_TREE_EXCEPTIONAL_ENTRY 2
  54. #define RADIX_TREE_EXCEPTIONAL_SHIFT 2
  55. static inline bool radix_tree_is_internal_node(void *ptr)
  56. {
  57. return ((unsigned long)ptr & RADIX_TREE_ENTRY_MASK) ==
  58. RADIX_TREE_INTERNAL_NODE;
  59. }
  60. /*** radix-tree API starts here ***/
  61. #define RADIX_TREE_MAX_TAGS 3
  62. #ifndef RADIX_TREE_MAP_SHIFT
  63. #define RADIX_TREE_MAP_SHIFT (CONFIG_BASE_SMALL ? 4 : 6)
  64. #endif
  65. #define RADIX_TREE_MAP_SIZE (1UL << RADIX_TREE_MAP_SHIFT)
  66. #define RADIX_TREE_MAP_MASK (RADIX_TREE_MAP_SIZE-1)
  67. #define RADIX_TREE_TAG_LONGS \
  68. ((RADIX_TREE_MAP_SIZE + BITS_PER_LONG - 1) / BITS_PER_LONG)
  69. #define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
  70. #define RADIX_TREE_MAX_PATH (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \
  71. RADIX_TREE_MAP_SHIFT))
  72. /* Internally used bits of node->count */
  73. #define RADIX_TREE_COUNT_SHIFT (RADIX_TREE_MAP_SHIFT + 1)
  74. #define RADIX_TREE_COUNT_MASK ((1UL << RADIX_TREE_COUNT_SHIFT) - 1)
  75. struct radix_tree_node {
  76. unsigned char shift; /* Bits remaining in each slot */
  77. unsigned char offset; /* Slot offset in parent */
  78. unsigned int count;
  79. union {
  80. struct {
  81. /* Used when ascending tree */
  82. struct radix_tree_node *parent;
  83. /* For tree user */
  84. void *private_data;
  85. };
  86. /* Used when freeing node */
  87. struct rcu_head rcu_head;
  88. };
  89. /* For tree user */
  90. struct list_head private_list;
  91. void __rcu *slots[RADIX_TREE_MAP_SIZE];
  92. unsigned long tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS];
  93. };
  94. /* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */
  95. struct radix_tree_root {
  96. gfp_t gfp_mask;
  97. struct radix_tree_node __rcu *rnode;
  98. };
  99. #define RADIX_TREE_INIT(mask) { \
  100. .gfp_mask = (mask), \
  101. .rnode = NULL, \
  102. }
  103. #define RADIX_TREE(name, mask) \
  104. struct radix_tree_root name = RADIX_TREE_INIT(mask)
  105. #define INIT_RADIX_TREE(root, mask) \
  106. do { \
  107. (root)->gfp_mask = (mask); \
  108. (root)->rnode = NULL; \
  109. } while (0)
  110. static inline bool radix_tree_empty(struct radix_tree_root *root)
  111. {
  112. return root->rnode == NULL;
  113. }
  114. /**
  115. * Radix-tree synchronization
  116. *
  117. * The radix-tree API requires that users provide all synchronisation (with
  118. * specific exceptions, noted below).
  119. *
  120. * Synchronization of access to the data items being stored in the tree, and
  121. * management of their lifetimes must be completely managed by API users.
  122. *
  123. * For API usage, in general,
  124. * - any function _modifying_ the tree or tags (inserting or deleting
  125. * items, setting or clearing tags) must exclude other modifications, and
  126. * exclude any functions reading the tree.
  127. * - any function _reading_ the tree or tags (looking up items or tags,
  128. * gang lookups) must exclude modifications to the tree, but may occur
  129. * concurrently with other readers.
  130. *
  131. * The notable exceptions to this rule are the following functions:
  132. * __radix_tree_lookup
  133. * radix_tree_lookup
  134. * radix_tree_lookup_slot
  135. * radix_tree_tag_get
  136. * radix_tree_gang_lookup
  137. * radix_tree_gang_lookup_slot
  138. * radix_tree_gang_lookup_tag
  139. * radix_tree_gang_lookup_tag_slot
  140. * radix_tree_tagged
  141. *
  142. * The first 8 functions are able to be called locklessly, using RCU. The
  143. * caller must ensure calls to these functions are made within rcu_read_lock()
  144. * regions. Other readers (lock-free or otherwise) and modifications may be
  145. * running concurrently.
  146. *
  147. * It is still required that the caller manage the synchronization and lifetimes
  148. * of the items. So if RCU lock-free lookups are used, typically this would mean
  149. * that the items have their own locks, or are amenable to lock-free access; and
  150. * that the items are freed by RCU (or only freed after having been deleted from
  151. * the radix tree *and* a synchronize_rcu() grace period).
  152. *
  153. * (Note, rcu_assign_pointer and rcu_dereference are not needed to control
  154. * access to data items when inserting into or looking up from the radix tree)
  155. *
  156. * Note that the value returned by radix_tree_tag_get() may not be relied upon
  157. * if only the RCU read lock is held. Functions to set/clear tags and to
  158. * delete nodes running concurrently with it may affect its result such that
  159. * two consecutive reads in the same locked section may return different
  160. * values. If reliability is required, modification functions must also be
  161. * excluded from concurrency.
  162. *
  163. * radix_tree_tagged is able to be called without locking or RCU.
  164. */
  165. /**
  166. * radix_tree_deref_slot - dereference a slot
  167. * @pslot: pointer to slot, returned by radix_tree_lookup_slot
  168. * Returns: item that was stored in that slot with any direct pointer flag
  169. * removed.
  170. *
  171. * For use with radix_tree_lookup_slot(). Caller must hold tree at least read
  172. * locked across slot lookup and dereference. Not required if write lock is
  173. * held (ie. items cannot be concurrently inserted).
  174. *
  175. * radix_tree_deref_retry must be used to confirm validity of the pointer if
  176. * only the read lock is held.
  177. */
  178. static inline void *radix_tree_deref_slot(void **pslot)
  179. {
  180. return rcu_dereference(*pslot);
  181. }
  182. /**
  183. * radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held
  184. * @pslot: pointer to slot, returned by radix_tree_lookup_slot
  185. * Returns: item that was stored in that slot with any direct pointer flag
  186. * removed.
  187. *
  188. * Similar to radix_tree_deref_slot but only used during migration when a pages
  189. * mapping is being moved. The caller does not hold the RCU read lock but it
  190. * must hold the tree lock to prevent parallel updates.
  191. */
  192. static inline void *radix_tree_deref_slot_protected(void **pslot,
  193. spinlock_t *treelock)
  194. {
  195. return rcu_dereference_protected(*pslot, lockdep_is_held(treelock));
  196. }
  197. /**
  198. * radix_tree_deref_retry - check radix_tree_deref_slot
  199. * @arg: pointer returned by radix_tree_deref_slot
  200. * Returns: 0 if retry is not required, otherwise retry is required
  201. *
  202. * radix_tree_deref_retry must be used with radix_tree_deref_slot.
  203. */
  204. static inline int radix_tree_deref_retry(void *arg)
  205. {
  206. return unlikely(radix_tree_is_internal_node(arg));
  207. }
  208. /**
  209. * radix_tree_exceptional_entry - radix_tree_deref_slot gave exceptional entry?
  210. * @arg: value returned by radix_tree_deref_slot
  211. * Returns: 0 if well-aligned pointer, non-0 if exceptional entry.
  212. */
  213. static inline int radix_tree_exceptional_entry(void *arg)
  214. {
  215. /* Not unlikely because radix_tree_exception often tested first */
  216. return (unsigned long)arg & RADIX_TREE_EXCEPTIONAL_ENTRY;
  217. }
  218. /**
  219. * radix_tree_exception - radix_tree_deref_slot returned either exception?
  220. * @arg: value returned by radix_tree_deref_slot
  221. * Returns: 0 if well-aligned pointer, non-0 if either kind of exception.
  222. */
  223. static inline int radix_tree_exception(void *arg)
  224. {
  225. return unlikely((unsigned long)arg & RADIX_TREE_ENTRY_MASK);
  226. }
  227. /**
  228. * radix_tree_replace_slot - replace item in a slot
  229. * @pslot: pointer to slot, returned by radix_tree_lookup_slot
  230. * @item: new item to store in the slot.
  231. *
  232. * For use with radix_tree_lookup_slot(). Caller must hold tree write locked
  233. * across slot lookup and replacement.
  234. */
  235. static inline void radix_tree_replace_slot(void **pslot, void *item)
  236. {
  237. BUG_ON(radix_tree_is_internal_node(item));
  238. rcu_assign_pointer(*pslot, item);
  239. }
  240. int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
  241. unsigned order, struct radix_tree_node **nodep,
  242. void ***slotp);
  243. int __radix_tree_insert(struct radix_tree_root *, unsigned long index,
  244. unsigned order, void *);
  245. static inline int radix_tree_insert(struct radix_tree_root *root,
  246. unsigned long index, void *entry)
  247. {
  248. return __radix_tree_insert(root, index, 0, entry);
  249. }
  250. void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index,
  251. struct radix_tree_node **nodep, void ***slotp);
  252. void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
  253. void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
  254. bool __radix_tree_delete_node(struct radix_tree_root *root,
  255. struct radix_tree_node *node);
  256. void *radix_tree_delete_item(struct radix_tree_root *, unsigned long, void *);
  257. void *radix_tree_delete(struct radix_tree_root *, unsigned long);
  258. void radix_tree_clear_tags(struct radix_tree_root *root,
  259. struct radix_tree_node *node,
  260. void **slot);
  261. unsigned int radix_tree_gang_lookup(struct radix_tree_root *root,
  262. void **results, unsigned long first_index,
  263. unsigned int max_items);
  264. unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
  265. void ***results, unsigned long *indices,
  266. unsigned long first_index, unsigned int max_items);
  267. int radix_tree_preload(gfp_t gfp_mask);
  268. int radix_tree_maybe_preload(gfp_t gfp_mask);
  269. int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order);
  270. void radix_tree_init(void);
  271. void *radix_tree_tag_set(struct radix_tree_root *root,
  272. unsigned long index, unsigned int tag);
  273. void *radix_tree_tag_clear(struct radix_tree_root *root,
  274. unsigned long index, unsigned int tag);
  275. int radix_tree_tag_get(struct radix_tree_root *root,
  276. unsigned long index, unsigned int tag);
  277. unsigned int
  278. radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
  279. unsigned long first_index, unsigned int max_items,
  280. unsigned int tag);
  281. unsigned int
  282. radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results,
  283. unsigned long first_index, unsigned int max_items,
  284. unsigned int tag);
  285. unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
  286. unsigned long *first_indexp, unsigned long last_index,
  287. unsigned long nr_to_tag,
  288. unsigned int fromtag, unsigned int totag);
  289. int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
  290. unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item);
  291. static inline void radix_tree_preload_end(void)
  292. {
  293. preempt_enable();
  294. }
  295. /**
  296. * struct radix_tree_iter - radix tree iterator state
  297. *
  298. * @index: index of current slot
  299. * @next_index: one beyond the last index for this chunk
  300. * @tags: bit-mask for tag-iterating
  301. * @shift: shift for the node that holds our slots
  302. *
  303. * This radix tree iterator works in terms of "chunks" of slots. A chunk is a
  304. * subinterval of slots contained within one radix tree leaf node. It is
  305. * described by a pointer to its first slot and a struct radix_tree_iter
  306. * which holds the chunk's position in the tree and its size. For tagged
  307. * iteration radix_tree_iter also holds the slots' bit-mask for one chosen
  308. * radix tree tag.
  309. */
  310. struct radix_tree_iter {
  311. unsigned long index;
  312. unsigned long next_index;
  313. unsigned long tags;
  314. #ifdef CONFIG_RADIX_TREE_MULTIORDER
  315. unsigned int shift;
  316. #endif
  317. };
  318. static inline unsigned int iter_shift(struct radix_tree_iter *iter)
  319. {
  320. #ifdef CONFIG_RADIX_TREE_MULTIORDER
  321. return iter->shift;
  322. #else
  323. return 0;
  324. #endif
  325. }
  326. #define RADIX_TREE_ITER_TAG_MASK 0x00FF /* tag index in lower byte */
  327. #define RADIX_TREE_ITER_TAGGED 0x0100 /* lookup tagged slots */
  328. #define RADIX_TREE_ITER_CONTIG 0x0200 /* stop at first hole */
  329. /**
  330. * radix_tree_iter_init - initialize radix tree iterator
  331. *
  332. * @iter: pointer to iterator state
  333. * @start: iteration starting index
  334. * Returns: NULL
  335. */
  336. static __always_inline void **
  337. radix_tree_iter_init(struct radix_tree_iter *iter, unsigned long start)
  338. {
  339. /*
  340. * Leave iter->tags uninitialized. radix_tree_next_chunk() will fill it
  341. * in the case of a successful tagged chunk lookup. If the lookup was
  342. * unsuccessful or non-tagged then nobody cares about ->tags.
  343. *
  344. * Set index to zero to bypass next_index overflow protection.
  345. * See the comment in radix_tree_next_chunk() for details.
  346. */
  347. iter->index = 0;
  348. iter->next_index = start;
  349. return NULL;
  350. }
  351. /**
  352. * radix_tree_next_chunk - find next chunk of slots for iteration
  353. *
  354. * @root: radix tree root
  355. * @iter: iterator state
  356. * @flags: RADIX_TREE_ITER_* flags and tag index
  357. * Returns: pointer to chunk first slot, or NULL if there no more left
  358. *
  359. * This function looks up the next chunk in the radix tree starting from
  360. * @iter->next_index. It returns a pointer to the chunk's first slot.
  361. * Also it fills @iter with data about chunk: position in the tree (index),
  362. * its end (next_index), and constructs a bit mask for tagged iterating (tags).
  363. */
  364. void **radix_tree_next_chunk(struct radix_tree_root *root,
  365. struct radix_tree_iter *iter, unsigned flags);
  366. /**
  367. * radix_tree_iter_retry - retry this chunk of the iteration
  368. * @iter: iterator state
  369. *
  370. * If we iterate over a tree protected only by the RCU lock, a race
  371. * against deletion or creation may result in seeing a slot for which
  372. * radix_tree_deref_retry() returns true. If so, call this function
  373. * and continue the iteration.
  374. */
  375. static inline __must_check
  376. void **radix_tree_iter_retry(struct radix_tree_iter *iter)
  377. {
  378. iter->next_index = iter->index;
  379. iter->tags = 0;
  380. return NULL;
  381. }
  382. static inline unsigned long
  383. __radix_tree_iter_add(struct radix_tree_iter *iter, unsigned long slots)
  384. {
  385. return iter->index + (slots << iter_shift(iter));
  386. }
  387. /**
  388. * radix_tree_iter_next - resume iterating when the chunk may be invalid
  389. * @iter: iterator state
  390. *
  391. * If the iterator needs to release then reacquire a lock, the chunk may
  392. * have been invalidated by an insertion or deletion. Call this function
  393. * to continue the iteration from the next index.
  394. */
  395. static inline __must_check
  396. void **radix_tree_iter_next(struct radix_tree_iter *iter)
  397. {
  398. iter->next_index = __radix_tree_iter_add(iter, 1);
  399. iter->tags = 0;
  400. return NULL;
  401. }
  402. /**
  403. * radix_tree_chunk_size - get current chunk size
  404. *
  405. * @iter: pointer to radix tree iterator
  406. * Returns: current chunk size
  407. */
  408. static __always_inline long
  409. radix_tree_chunk_size(struct radix_tree_iter *iter)
  410. {
  411. return (iter->next_index - iter->index) >> iter_shift(iter);
  412. }
  413. static inline struct radix_tree_node *entry_to_node(void *ptr)
  414. {
  415. return (void *)((unsigned long)ptr & ~RADIX_TREE_INTERNAL_NODE);
  416. }
  417. /**
  418. * radix_tree_next_slot - find next slot in chunk
  419. *
  420. * @slot: pointer to current slot
  421. * @iter: pointer to interator state
  422. * @flags: RADIX_TREE_ITER_*, should be constant
  423. * Returns: pointer to next slot, or NULL if there no more left
  424. *
  425. * This function updates @iter->index in the case of a successful lookup.
  426. * For tagged lookup it also eats @iter->tags.
  427. *
  428. * There are several cases where 'slot' can be passed in as NULL to this
  429. * function. These cases result from the use of radix_tree_iter_next() or
  430. * radix_tree_iter_retry(). In these cases we don't end up dereferencing
  431. * 'slot' because either:
  432. * a) we are doing tagged iteration and iter->tags has been set to 0, or
  433. * b) we are doing non-tagged iteration, and iter->index and iter->next_index
  434. * have been set up so that radix_tree_chunk_size() returns 1 or 0.
  435. */
  436. static __always_inline void **
  437. radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags)
  438. {
  439. if (flags & RADIX_TREE_ITER_TAGGED) {
  440. void *canon = slot;
  441. iter->tags >>= 1;
  442. if (unlikely(!iter->tags))
  443. return NULL;
  444. while (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) &&
  445. radix_tree_is_internal_node(slot[1])) {
  446. if (entry_to_node(slot[1]) == canon) {
  447. iter->tags >>= 1;
  448. iter->index = __radix_tree_iter_add(iter, 1);
  449. slot++;
  450. continue;
  451. }
  452. iter->next_index = __radix_tree_iter_add(iter, 1);
  453. return NULL;
  454. }
  455. if (likely(iter->tags & 1ul)) {
  456. iter->index = __radix_tree_iter_add(iter, 1);
  457. return slot + 1;
  458. }
  459. if (!(flags & RADIX_TREE_ITER_CONTIG)) {
  460. unsigned offset = __ffs(iter->tags);
  461. iter->tags >>= offset;
  462. iter->index = __radix_tree_iter_add(iter, offset + 1);
  463. return slot + offset + 1;
  464. }
  465. } else {
  466. long count = radix_tree_chunk_size(iter);
  467. void *canon = slot;
  468. while (--count > 0) {
  469. slot++;
  470. iter->index = __radix_tree_iter_add(iter, 1);
  471. if (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) &&
  472. radix_tree_is_internal_node(*slot)) {
  473. if (entry_to_node(*slot) == canon)
  474. continue;
  475. iter->next_index = iter->index;
  476. break;
  477. }
  478. if (likely(*slot))
  479. return slot;
  480. if (flags & RADIX_TREE_ITER_CONTIG) {
  481. /* forbid switching to the next chunk */
  482. iter->next_index = 0;
  483. break;
  484. }
  485. }
  486. }
  487. return NULL;
  488. }
  489. /**
  490. * radix_tree_for_each_slot - iterate over non-empty slots
  491. *
  492. * @slot: the void** variable for pointer to slot
  493. * @root: the struct radix_tree_root pointer
  494. * @iter: the struct radix_tree_iter pointer
  495. * @start: iteration starting index
  496. *
  497. * @slot points to radix tree slot, @iter->index contains its index.
  498. */
  499. #define radix_tree_for_each_slot(slot, root, iter, start) \
  500. for (slot = radix_tree_iter_init(iter, start) ; \
  501. slot || (slot = radix_tree_next_chunk(root, iter, 0)) ; \
  502. slot = radix_tree_next_slot(slot, iter, 0))
  503. /**
  504. * radix_tree_for_each_contig - iterate over contiguous slots
  505. *
  506. * @slot: the void** variable for pointer to slot
  507. * @root: the struct radix_tree_root pointer
  508. * @iter: the struct radix_tree_iter pointer
  509. * @start: iteration starting index
  510. *
  511. * @slot points to radix tree slot, @iter->index contains its index.
  512. */
  513. #define radix_tree_for_each_contig(slot, root, iter, start) \
  514. for (slot = radix_tree_iter_init(iter, start) ; \
  515. slot || (slot = radix_tree_next_chunk(root, iter, \
  516. RADIX_TREE_ITER_CONTIG)) ; \
  517. slot = radix_tree_next_slot(slot, iter, \
  518. RADIX_TREE_ITER_CONTIG))
  519. /**
  520. * radix_tree_for_each_tagged - iterate over tagged slots
  521. *
  522. * @slot: the void** variable for pointer to slot
  523. * @root: the struct radix_tree_root pointer
  524. * @iter: the struct radix_tree_iter pointer
  525. * @start: iteration starting index
  526. * @tag: tag index
  527. *
  528. * @slot points to radix tree slot, @iter->index contains its index.
  529. */
  530. #define radix_tree_for_each_tagged(slot, root, iter, start, tag) \
  531. for (slot = radix_tree_iter_init(iter, start) ; \
  532. slot || (slot = radix_tree_next_chunk(root, iter, \
  533. RADIX_TREE_ITER_TAGGED | tag)) ; \
  534. slot = radix_tree_next_slot(slot, iter, \
  535. RADIX_TREE_ITER_TAGGED))
  536. #endif /* _LINUX_RADIX_TREE_H */