radix-tree.h 19 KB

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