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. * 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 - locked exceptional entry
  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. 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. iter->tags = 0;
  379. return NULL;
  380. }
  381. static inline unsigned long
  382. __radix_tree_iter_add(struct radix_tree_iter *iter, unsigned long slots)
  383. {
  384. return iter->index + (slots << iter_shift(iter));
  385. }
  386. /**
  387. * radix_tree_iter_next - resume iterating when the chunk may be invalid
  388. * @iter: iterator state
  389. *
  390. * If the iterator needs to release then reacquire a lock, the chunk may
  391. * have been invalidated by an insertion or deletion. Call this function
  392. * to continue the iteration from the next index.
  393. */
  394. static inline __must_check
  395. void **radix_tree_iter_next(struct radix_tree_iter *iter)
  396. {
  397. iter->next_index = __radix_tree_iter_add(iter, 1);
  398. iter->tags = 0;
  399. return NULL;
  400. }
  401. /**
  402. * radix_tree_chunk_size - get current chunk size
  403. *
  404. * @iter: pointer to radix tree iterator
  405. * Returns: current chunk size
  406. */
  407. static __always_inline long
  408. radix_tree_chunk_size(struct radix_tree_iter *iter)
  409. {
  410. return (iter->next_index - iter->index) >> iter_shift(iter);
  411. }
  412. static inline struct radix_tree_node *entry_to_node(void *ptr)
  413. {
  414. return (void *)((unsigned long)ptr & ~RADIX_TREE_INTERNAL_NODE);
  415. }
  416. /**
  417. * radix_tree_next_slot - find next slot in chunk
  418. *
  419. * @slot: pointer to current slot
  420. * @iter: pointer to interator state
  421. * @flags: RADIX_TREE_ITER_*, should be constant
  422. * Returns: pointer to next slot, or NULL if there no more left
  423. *
  424. * This function updates @iter->index in the case of a successful lookup.
  425. * For tagged lookup it also eats @iter->tags.
  426. */
  427. static __always_inline void **
  428. radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags)
  429. {
  430. if (flags & RADIX_TREE_ITER_TAGGED) {
  431. void *canon = slot;
  432. iter->tags >>= 1;
  433. if (unlikely(!iter->tags))
  434. return NULL;
  435. while (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) &&
  436. radix_tree_is_internal_node(slot[1])) {
  437. if (entry_to_node(slot[1]) == canon) {
  438. iter->tags >>= 1;
  439. iter->index = __radix_tree_iter_add(iter, 1);
  440. slot++;
  441. continue;
  442. }
  443. iter->next_index = __radix_tree_iter_add(iter, 1);
  444. return NULL;
  445. }
  446. if (likely(iter->tags & 1ul)) {
  447. iter->index = __radix_tree_iter_add(iter, 1);
  448. return slot + 1;
  449. }
  450. if (!(flags & RADIX_TREE_ITER_CONTIG)) {
  451. unsigned offset = __ffs(iter->tags);
  452. iter->tags >>= offset;
  453. iter->index = __radix_tree_iter_add(iter, offset + 1);
  454. return slot + offset + 1;
  455. }
  456. } else {
  457. long count = radix_tree_chunk_size(iter);
  458. void *canon = slot;
  459. while (--count > 0) {
  460. slot++;
  461. iter->index = __radix_tree_iter_add(iter, 1);
  462. if (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) &&
  463. radix_tree_is_internal_node(*slot)) {
  464. if (entry_to_node(*slot) == canon)
  465. continue;
  466. iter->next_index = iter->index;
  467. break;
  468. }
  469. if (likely(*slot))
  470. return slot;
  471. if (flags & RADIX_TREE_ITER_CONTIG) {
  472. /* forbid switching to the next chunk */
  473. iter->next_index = 0;
  474. break;
  475. }
  476. }
  477. }
  478. return NULL;
  479. }
  480. /**
  481. * radix_tree_for_each_slot - iterate over non-empty slots
  482. *
  483. * @slot: the void** variable for pointer to slot
  484. * @root: the struct radix_tree_root pointer
  485. * @iter: the struct radix_tree_iter pointer
  486. * @start: iteration starting index
  487. *
  488. * @slot points to radix tree slot, @iter->index contains its index.
  489. */
  490. #define radix_tree_for_each_slot(slot, root, iter, start) \
  491. for (slot = radix_tree_iter_init(iter, start) ; \
  492. slot || (slot = radix_tree_next_chunk(root, iter, 0)) ; \
  493. slot = radix_tree_next_slot(slot, iter, 0))
  494. /**
  495. * radix_tree_for_each_contig - iterate over contiguous slots
  496. *
  497. * @slot: the void** variable for pointer to slot
  498. * @root: the struct radix_tree_root pointer
  499. * @iter: the struct radix_tree_iter pointer
  500. * @start: iteration starting index
  501. *
  502. * @slot points to radix tree slot, @iter->index contains its index.
  503. */
  504. #define radix_tree_for_each_contig(slot, root, iter, start) \
  505. for (slot = radix_tree_iter_init(iter, start) ; \
  506. slot || (slot = radix_tree_next_chunk(root, iter, \
  507. RADIX_TREE_ITER_CONTIG)) ; \
  508. slot = radix_tree_next_slot(slot, iter, \
  509. RADIX_TREE_ITER_CONTIG))
  510. /**
  511. * radix_tree_for_each_tagged - iterate over tagged slots
  512. *
  513. * @slot: the void** variable for pointer to slot
  514. * @root: the struct radix_tree_root pointer
  515. * @iter: the struct radix_tree_iter pointer
  516. * @start: iteration starting index
  517. * @tag: tag index
  518. *
  519. * @slot points to radix tree slot, @iter->index contains its index.
  520. */
  521. #define radix_tree_for_each_tagged(slot, root, iter, start, tag) \
  522. for (slot = radix_tree_iter_init(iter, start) ; \
  523. slot || (slot = radix_tree_next_chunk(root, iter, \
  524. RADIX_TREE_ITER_TAGGED | tag)) ; \
  525. slot = radix_tree_next_slot(slot, iter, \
  526. RADIX_TREE_ITER_TAGGED))
  527. #endif /* _LINUX_RADIX_TREE_H */