summaryrefslogtreecommitdiffstats
path: root/lib/radix-tree.c
diff options
context:
space:
mode:
authorMatthew Wilcox <mawilcox@microsoft.com>2016-12-14 18:08:52 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-14 19:04:10 -0500
commit478922e2b0f41567e4a530771bfb3f693f857d45 (patch)
tree61a6204f2983f8b864a82b4f255127897df351cb /lib/radix-tree.c
parent148deab223b23734069abcacb5c7118b0e7deadc (diff)
radix-tree: delete radix_tree_locate_item()
This rather complicated function can be better implemented as an iterator. It has only one caller, so move the functionality to the only place that needs it. Update the test suite to follow the same pattern. Link: http://lkml.kernel.org/r/1480369871-5271-56-git-send-email-mawilcox@linuxonhyperv.com Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com> Acked-by: Konstantin Khlebnikov <koct9i@gmail.com> Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: Matthew Wilcox <mawilcox@microsoft.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/radix-tree.c')
-rw-r--r--lib/radix-tree.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 0a7ac0fb4a65..5bdf1bdbca00 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1579,105 +1579,6 @@ radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results,
1579} 1579}
1580EXPORT_SYMBOL(radix_tree_gang_lookup_tag_slot); 1580EXPORT_SYMBOL(radix_tree_gang_lookup_tag_slot);
1581 1581
1582#if defined(CONFIG_SHMEM) && defined(CONFIG_SWAP)
1583#include <linux/sched.h> /* for cond_resched() */
1584
1585struct locate_info {
1586 unsigned long found_index;
1587 bool stop;
1588};
1589
1590/*
1591 * This linear search is at present only useful to shmem_unuse_inode().
1592 */
1593static unsigned long __locate(struct radix_tree_node *slot, void *item,
1594 unsigned long index, struct locate_info *info)
1595{
1596 unsigned long i;
1597
1598 do {
1599 unsigned int shift = slot->shift;
1600
1601 for (i = (index >> shift) & RADIX_TREE_MAP_MASK;
1602 i < RADIX_TREE_MAP_SIZE;
1603 i++, index += (1UL << shift)) {
1604 struct radix_tree_node *node =
1605 rcu_dereference_raw(slot->slots[i]);
1606 if (node == RADIX_TREE_RETRY)
1607 goto out;
1608 if (!radix_tree_is_internal_node(node)) {
1609 if (node == item) {
1610 info->found_index = index;
1611 info->stop = true;
1612 goto out;
1613 }
1614 continue;
1615 }
1616 node = entry_to_node(node);
1617 if (is_sibling_entry(slot, node))
1618 continue;
1619 slot = node;
1620 break;
1621 }
1622 } while (i < RADIX_TREE_MAP_SIZE);
1623
1624out:
1625 if ((index == 0) && (i == RADIX_TREE_MAP_SIZE))
1626 info->stop = true;
1627 return index;
1628}
1629
1630/**
1631 * radix_tree_locate_item - search through radix tree for item
1632 * @root: radix tree root
1633 * @item: item to be found
1634 *
1635 * Returns index where item was found, or -1 if not found.
1636 * Caller must hold no lock (since this time-consuming function needs
1637 * to be preemptible), and must check afterwards if item is still there.
1638 */
1639unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item)
1640{
1641 struct radix_tree_node *node;
1642 unsigned long max_index;
1643 unsigned long cur_index = 0;
1644 struct locate_info info = {
1645 .found_index = -1,
1646 .stop = false,
1647 };
1648
1649 do {
1650 rcu_read_lock();
1651 node = rcu_dereference_raw(root->rnode);
1652 if (!radix_tree_is_internal_node(node)) {
1653 rcu_read_unlock();
1654 if (node == item)
1655 info.found_index = 0;
1656 break;
1657 }
1658
1659 node = entry_to_node(node);
1660
1661 max_index = node_maxindex(node);
1662 if (cur_index > max_index) {
1663 rcu_read_unlock();
1664 break;
1665 }
1666
1667 cur_index = __locate(node, item, cur_index, &info);
1668 rcu_read_unlock();
1669 cond_resched();
1670 } while (!info.stop && cur_index <= max_index);
1671
1672 return info.found_index;
1673}
1674#else
1675unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item)
1676{
1677 return -1;
1678}
1679#endif /* CONFIG_SHMEM && CONFIG_SWAP */
1680
1681/** 1582/**
1682 * __radix_tree_delete_node - try to free node after clearing a slot 1583 * __radix_tree_delete_node - try to free node after clearing a slot
1683 * @root: radix tree root 1584 * @root: radix tree root