aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWu Fengguang <fengguang.wu@intel.com>2009-06-16 18:31:32 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-16 22:47:30 -0400
commitdc566127dd161b6c997466a2349ac179527ea89b (patch)
tree2973018dd4a89f0b20eaa0838eb654b6eff06f68
parentd30a11004e3411909f2448546f036a011978062e (diff)
radix-tree: add radix_tree_prev_hole()
The counterpart of radix_tree_next_hole(). To be used by context readahead. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Cc: Vladislav Bolkhovitin <vst@vlnb.net> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Jeff Moyer <jmoyer@redhat.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Cc: Ying Han <yinghan@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/radix-tree.h2
-rw-r--r--lib/radix-tree.c37
2 files changed, 39 insertions, 0 deletions
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index 355f6e80db0d..c5da74918096 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -167,6 +167,8 @@ radix_tree_gang_lookup_slot(struct radix_tree_root *root, void ***results,
167 unsigned long first_index, unsigned int max_items); 167 unsigned long first_index, unsigned int max_items);
168unsigned long radix_tree_next_hole(struct radix_tree_root *root, 168unsigned long radix_tree_next_hole(struct radix_tree_root *root,
169 unsigned long index, unsigned long max_scan); 169 unsigned long index, unsigned long max_scan);
170unsigned long radix_tree_prev_hole(struct radix_tree_root *root,
171 unsigned long index, unsigned long max_scan);
170int radix_tree_preload(gfp_t gfp_mask); 172int radix_tree_preload(gfp_t gfp_mask);
171void radix_tree_init(void); 173void radix_tree_init(void);
172void *radix_tree_tag_set(struct radix_tree_root *root, 174void *radix_tree_tag_set(struct radix_tree_root *root,
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 4bb42a0344ec..5301a52cdb4d 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -666,6 +666,43 @@ unsigned long radix_tree_next_hole(struct radix_tree_root *root,
666} 666}
667EXPORT_SYMBOL(radix_tree_next_hole); 667EXPORT_SYMBOL(radix_tree_next_hole);
668 668
669/**
670 * radix_tree_prev_hole - find the prev hole (not-present entry)
671 * @root: tree root
672 * @index: index key
673 * @max_scan: maximum range to search
674 *
675 * Search backwards in the range [max(index-max_scan+1, 0), index]
676 * for the first hole.
677 *
678 * Returns: the index of the hole if found, otherwise returns an index
679 * outside of the set specified (in which case 'index - return >= max_scan'
680 * will be true). In rare cases of wrap-around, LONG_MAX will be returned.
681 *
682 * radix_tree_next_hole may be called under rcu_read_lock. However, like
683 * radix_tree_gang_lookup, this will not atomically search a snapshot of
684 * the tree at a single point in time. For example, if a hole is created
685 * at index 10, then subsequently a hole is created at index 5,
686 * radix_tree_prev_hole covering both indexes may return 5 if called under
687 * rcu_read_lock.
688 */
689unsigned long radix_tree_prev_hole(struct radix_tree_root *root,
690 unsigned long index, unsigned long max_scan)
691{
692 unsigned long i;
693
694 for (i = 0; i < max_scan; i++) {
695 if (!radix_tree_lookup(root, index))
696 break;
697 index--;
698 if (index == LONG_MAX)
699 break;
700 }
701
702 return index;
703}
704EXPORT_SYMBOL(radix_tree_prev_hole);
705
669static unsigned int 706static unsigned int
670__lookup(struct radix_tree_node *slot, void ***results, unsigned long index, 707__lookup(struct radix_tree_node *slot, void ***results, unsigned long index,
671 unsigned int max_items, unsigned long *next_index) 708 unsigned int max_items, unsigned long *next_index)