Commit 339e6353 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

radix_tree: tag all internal tree nodes as indirect pointers

Set the 'indirect_ptr' bit on all the pointers to internal nodes, not
just on the root node.  This enables the following patches to support
multi-order entries in the radix tree.  This patch is split out for ease
of bisection.
Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1366c37e
...@@ -368,9 +368,10 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index) ...@@ -368,9 +368,10 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
node->count = 1; node->count = 1;
node->parent = NULL; node->parent = NULL;
slot = root->rnode; slot = root->rnode;
if (newheight > 1) { if (radix_tree_is_indirect_ptr(slot) && newheight > 1) {
slot = indirect_to_ptr(slot); slot = indirect_to_ptr(slot);
slot->parent = node; slot->parent = node;
slot = ptr_to_indirect(slot);
} }
node->slots[0] = slot; node->slots[0] = slot;
node = ptr_to_indirect(node); node = ptr_to_indirect(node);
...@@ -425,17 +426,20 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index, ...@@ -425,17 +426,20 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
slot->path = height; slot->path = height;
slot->parent = node; slot->parent = node;
if (node) { if (node) {
rcu_assign_pointer(node->slots[offset], slot); rcu_assign_pointer(node->slots[offset],
ptr_to_indirect(slot));
node->count++; node->count++;
slot->path |= offset << RADIX_TREE_HEIGHT_SHIFT; slot->path |= offset << RADIX_TREE_HEIGHT_SHIFT;
} else } else
rcu_assign_pointer(root->rnode, ptr_to_indirect(slot)); rcu_assign_pointer(root->rnode,
ptr_to_indirect(slot));
} }
/* Go a level down */ /* Go a level down */
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
node = slot; node = slot;
slot = node->slots[offset]; slot = node->slots[offset];
slot = indirect_to_ptr(slot);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
height--; height--;
} }
...@@ -533,6 +537,7 @@ void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index, ...@@ -533,6 +537,7 @@ void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index,
node = rcu_dereference_raw(*slot); node = rcu_dereference_raw(*slot);
if (node == NULL) if (node == NULL)
return NULL; return NULL;
node = indirect_to_ptr(node);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
height--; height--;
...@@ -619,6 +624,7 @@ void *radix_tree_tag_set(struct radix_tree_root *root, ...@@ -619,6 +624,7 @@ void *radix_tree_tag_set(struct radix_tree_root *root,
tag_set(slot, tag, offset); tag_set(slot, tag, offset);
slot = slot->slots[offset]; slot = slot->slots[offset];
BUG_ON(slot == NULL); BUG_ON(slot == NULL);
slot = indirect_to_ptr(slot);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
height--; height--;
} }
...@@ -658,11 +664,12 @@ void *radix_tree_tag_clear(struct radix_tree_root *root, ...@@ -658,11 +664,12 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
goto out; goto out;
shift = height * RADIX_TREE_MAP_SHIFT; shift = height * RADIX_TREE_MAP_SHIFT;
slot = indirect_to_ptr(root->rnode); slot = root->rnode;
while (shift) { while (shift) {
if (slot == NULL) if (slot == NULL)
goto out; goto out;
slot = indirect_to_ptr(slot);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
...@@ -738,6 +745,7 @@ int radix_tree_tag_get(struct radix_tree_root *root, ...@@ -738,6 +745,7 @@ int radix_tree_tag_get(struct radix_tree_root *root,
if (node == NULL) if (node == NULL)
return 0; return 0;
node = indirect_to_ptr(node);
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
if (!tag_get(node, tag, offset)) if (!tag_get(node, tag, offset))
...@@ -838,6 +846,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root, ...@@ -838,6 +846,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root,
node = rcu_dereference_raw(node->slots[offset]); node = rcu_dereference_raw(node->slots[offset]);
if (node == NULL) if (node == NULL)
goto restart; goto restart;
node = indirect_to_ptr(node);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
} }
...@@ -939,6 +948,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root, ...@@ -939,6 +948,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
node = slot; node = slot;
slot = slot->slots[offset]; slot = slot->slots[offset];
slot = indirect_to_ptr(slot);
continue; continue;
} }
...@@ -1195,6 +1205,7 @@ static unsigned long __locate(struct radix_tree_node *slot, void *item, ...@@ -1195,6 +1205,7 @@ static unsigned long __locate(struct radix_tree_node *slot, void *item,
slot = rcu_dereference_raw(slot->slots[i]); slot = rcu_dereference_raw(slot->slots[i]);
if (slot == NULL) if (slot == NULL)
goto out; goto out;
slot = indirect_to_ptr(slot);
} }
/* Bottom level: check items */ /* Bottom level: check items */
...@@ -1278,7 +1289,8 @@ static inline void radix_tree_shrink(struct radix_tree_root *root) ...@@ -1278,7 +1289,8 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
*/ */
if (to_free->count != 1) if (to_free->count != 1)
break; break;
if (!to_free->slots[0]) slot = to_free->slots[0];
if (!slot)
break; break;
/* /*
...@@ -1288,8 +1300,8 @@ static inline void radix_tree_shrink(struct radix_tree_root *root) ...@@ -1288,8 +1300,8 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
* (to_free->slots[0]), it will be safe to dereference the new * (to_free->slots[0]), it will be safe to dereference the new
* one (root->rnode) as far as dependent read barriers go. * one (root->rnode) as far as dependent read barriers go.
*/ */
slot = to_free->slots[0];
if (root->height > 1) { if (root->height > 1) {
slot = indirect_to_ptr(slot);
slot->parent = NULL; slot->parent = NULL;
slot = ptr_to_indirect(slot); slot = ptr_to_indirect(slot);
} }
......
...@@ -142,6 +142,8 @@ static int verify_node(struct radix_tree_node *slot, unsigned int tag, ...@@ -142,6 +142,8 @@ static int verify_node(struct radix_tree_node *slot, unsigned int tag,
int i; int i;
int j; int j;
slot = indirect_to_ptr(slot);
/* Verify consistency at this level */ /* Verify consistency at this level */
for (i = 0; i < RADIX_TREE_TAG_LONGS; i++) { for (i = 0; i < RADIX_TREE_TAG_LONGS; i++) {
if (slot->tags[tag][i]) { if (slot->tags[tag][i]) {
...@@ -184,8 +186,7 @@ void verify_tag_consistency(struct radix_tree_root *root, unsigned int tag) ...@@ -184,8 +186,7 @@ void verify_tag_consistency(struct radix_tree_root *root, unsigned int tag)
{ {
if (!root->height) if (!root->height)
return; return;
verify_node(indirect_to_ptr(root->rnode), verify_node(root->rnode, tag, root->height, !!root_tag_get(root, tag));
tag, root->height, !!root_tag_get(root, tag));
} }
void item_kill_tree(struct radix_tree_root *root) void item_kill_tree(struct radix_tree_root *root)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment