Commit 9498d2bb authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

radix-tree: create node_tag_set()

Similar to node_tag_clear(), factor node_tag_set() out of
radix_tree_range_tag_if_tagged().

Link: http://lkml.kernel.org/r/1480369871-5271-51-git-send-email-mawilcox@linuxonhyperv.comSigned-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Tested-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 91d9c05a
...@@ -991,6 +991,22 @@ static void node_tag_clear(struct radix_tree_root *root, ...@@ -991,6 +991,22 @@ static void node_tag_clear(struct radix_tree_root *root,
root_tag_clear(root, tag); root_tag_clear(root, tag);
} }
static void node_tag_set(struct radix_tree_root *root,
struct radix_tree_node *node,
unsigned int tag, unsigned int offset)
{
while (node) {
if (tag_get(node, tag, offset))
return;
tag_set(node, tag, offset);
offset = node->offset;
node = node->parent;
}
if (!root_tag_get(root, tag))
root_tag_set(root, tag);
}
/** /**
* radix_tree_tag_clear - clear a tag on a radix tree node * radix_tree_tag_clear - clear a tag on a radix tree node
* @root: radix tree root * @root: radix tree root
...@@ -1229,7 +1245,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root, ...@@ -1229,7 +1245,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
unsigned long nr_to_tag, unsigned long nr_to_tag,
unsigned int iftag, unsigned int settag) unsigned int iftag, unsigned int settag)
{ {
struct radix_tree_node *parent, *node, *child; struct radix_tree_node *node, *child;
unsigned long maxindex; unsigned long maxindex;
unsigned long tagged = 0; unsigned long tagged = 0;
unsigned long index = *first_indexp; unsigned long index = *first_indexp;
...@@ -1264,22 +1280,8 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root, ...@@ -1264,22 +1280,8 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
continue; continue;
} }
/* tag the leaf */
tagged++; tagged++;
tag_set(node, settag, offset); node_tag_set(root, node, settag, offset);
/* walk back up the path tagging interior nodes */
parent = node;
for (;;) {
offset = parent->offset;
parent = parent->parent;
if (!parent)
break;
/* stop if we find a node with the tag already set */
if (tag_get(parent, settag, offset))
break;
tag_set(parent, settag, offset);
}
next: next:
/* Go to next entry in node */ /* Go to next entry in node */
index = ((index >> node->shift) + 1) << node->shift; index = ((index >> node->shift) + 1) << node->shift;
...@@ -1301,12 +1303,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root, ...@@ -1301,12 +1303,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
if (tagged >= nr_to_tag) if (tagged >= nr_to_tag)
break; break;
} }
/*
* We need not to tag the root tag if there is no tag which is set with
* settag within the range from *first_indexp to last_index.
*/
if (tagged > 0)
root_tag_set(root, settag);
*first_indexp = index; *first_indexp = index;
return tagged; return tagged;
......
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