aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/radix-tree.h
diff options
context:
space:
mode:
authorHugh Dickins <hughd@google.com>2011-08-03 19:21:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-08-03 20:25:22 -0400
commit6328650bb4d854a7dc1498d1c0048b838b0d340c (patch)
tree0e265dc86f7c4451647c1e227843cdd1530f9651 /include/linux/radix-tree.h
parent70d327198a434edb95b3d858bc8010b8add28e3e (diff)
radix_tree: exceptional entries and indices
A patchset to extend tmpfs to MAX_LFS_FILESIZE by abandoning its peculiar swap vector, instead keeping a file's swap entries in the same radix tree as its struct page pointers: thus saving memory, and simplifying its code and locking. This patch: The radix_tree is used by several subsystems for different purposes. A major use is to store the struct page pointers of a file's pagecache for memory management. But what if mm wanted to store something other than page pointers there too? The low bit of a radix_tree entry is already used to denote an indirect pointer, for internal use, and the unlikely radix_tree_deref_retry() case. Define the next bit as denoting an exceptional entry, and supply inline functions radix_tree_exception() to return non-0 in either unlikely case, and radix_tree_exceptional_entry() to return non-0 in the second case. If a subsystem already uses radix_tree with that bit set, no problem: it does not affect internal workings at all, but is defined for the convenience of those storing well-aligned pointers in the radix_tree. The radix_tree_gang_lookups have an implicit assumption that the caller can deduce the offset of each entry returned e.g. by the page->index of a struct page. But that may not be feasible for some kinds of item to be stored there. radix_tree_gang_lookup_slot() allow for an optional indices argument, output array in which to return those offsets. The same could be added to other radix_tree_gang_lookups, but for now keep it to the only one for which we need it. Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/radix-tree.h')
-rw-r--r--include/linux/radix-tree.h36
1 files changed, 33 insertions, 3 deletions
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index 23241c2fecce..b7edf8251455 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -39,7 +39,15 @@
39 * when it is shrunk, before we rcu free the node. See shrink code for 39 * when it is shrunk, before we rcu free the node. See shrink code for
40 * details. 40 * details.
41 */ 41 */
42#define RADIX_TREE_INDIRECT_PTR 1 42#define RADIX_TREE_INDIRECT_PTR 1
43/*
44 * A common use of the radix tree is to store pointers to struct pages;
45 * but shmem/tmpfs needs also to store swap entries in the same tree:
46 * those are marked as exceptional entries to distinguish them.
47 * EXCEPTIONAL_ENTRY tests the bit, EXCEPTIONAL_SHIFT shifts content past it.
48 */
49#define RADIX_TREE_EXCEPTIONAL_ENTRY 2
50#define RADIX_TREE_EXCEPTIONAL_SHIFT 2
43 51
44#define radix_tree_indirect_to_ptr(ptr) \ 52#define radix_tree_indirect_to_ptr(ptr) \
45 radix_tree_indirect_to_ptr((void __force *)(ptr)) 53 radix_tree_indirect_to_ptr((void __force *)(ptr))
@@ -174,6 +182,28 @@ static inline int radix_tree_deref_retry(void *arg)
174} 182}
175 183
176/** 184/**
185 * radix_tree_exceptional_entry - radix_tree_deref_slot gave exceptional entry?
186 * @arg: value returned by radix_tree_deref_slot
187 * Returns: 0 if well-aligned pointer, non-0 if exceptional entry.
188 */
189static inline int radix_tree_exceptional_entry(void *arg)
190{
191 /* Not unlikely because radix_tree_exception often tested first */
192 return (unsigned long)arg & RADIX_TREE_EXCEPTIONAL_ENTRY;
193}
194
195/**
196 * radix_tree_exception - radix_tree_deref_slot returned either exception?
197 * @arg: value returned by radix_tree_deref_slot
198 * Returns: 0 if well-aligned pointer, non-0 if either kind of exception.
199 */
200static inline int radix_tree_exception(void *arg)
201{
202 return unlikely((unsigned long)arg &
203 (RADIX_TREE_INDIRECT_PTR | RADIX_TREE_EXCEPTIONAL_ENTRY));
204}
205
206/**
177 * radix_tree_replace_slot - replace item in a slot 207 * radix_tree_replace_slot - replace item in a slot
178 * @pslot: pointer to slot, returned by radix_tree_lookup_slot 208 * @pslot: pointer to slot, returned by radix_tree_lookup_slot
179 * @item: new item to store in the slot. 209 * @item: new item to store in the slot.
@@ -194,8 +224,8 @@ void *radix_tree_delete(struct radix_tree_root *, unsigned long);
194unsigned int 224unsigned int
195radix_tree_gang_lookup(struct radix_tree_root *root, void **results, 225radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
196 unsigned long first_index, unsigned int max_items); 226 unsigned long first_index, unsigned int max_items);
197unsigned int 227unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
198radix_tree_gang_lookup_slot(struct radix_tree_root *root, void ***results, 228 void ***results, unsigned long *indices,
199 unsigned long first_index, unsigned int max_items); 229 unsigned long first_index, unsigned int max_items);
200unsigned long radix_tree_next_hole(struct radix_tree_root *root, 230unsigned long radix_tree_next_hole(struct radix_tree_root *root,
201 unsigned long index, unsigned long max_scan); 231 unsigned long index, unsigned long max_scan);