btrfs: remove the ->lowest and ->leaves members from struct btrfs_backref_node
authorJosef Bacik <josef@toxicpanda.com>
Thu, 3 Oct 2024 15:43:11 +0000 (11:43 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Jan 2025 13:53:15 +0000 (14:53 +0100)
Before we were keeping all of our nodes on various lists in order to
make sure everything got cleaned up correctly.  We used node->lowest to
indicate that node->lower was linked into the cache->leaves list.  Now
that we do cleanup based on the rb-tree both the list and the flag are
useless, so delete them both.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c
fs/btrfs/backref.h
fs/btrfs/relocation.c

index 1a21ff2a86f9f1e7debba90e4940460253911063..597d1d5f44ec557560b4ea813c7825fe3703c820 100644 (file)
@@ -3023,7 +3023,6 @@ void btrfs_backref_init_cache(struct btrfs_fs_info *fs_info,
        for (i = 0; i < BTRFS_MAX_LEVEL; i++)
                INIT_LIST_HEAD(&cache->pending[i]);
        INIT_LIST_HEAD(&cache->detached);
-       INIT_LIST_HEAD(&cache->leaves);
        INIT_LIST_HEAD(&cache->pending_edge);
        INIT_LIST_HEAD(&cache->useless_node);
        cache->fs_info = fs_info;
@@ -3131,29 +3130,17 @@ void btrfs_backref_drop_node(struct btrfs_backref_cache *tree,
 void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache,
                                struct btrfs_backref_node *node)
 {
-       struct btrfs_backref_node *upper;
        struct btrfs_backref_edge *edge;
 
        if (!node)
                return;
 
-       BUG_ON(!node->lowest && !node->detached);
        while (!list_empty(&node->upper)) {
                edge = list_entry(node->upper.next, struct btrfs_backref_edge,
                                  list[LOWER]);
-               upper = edge->node[UPPER];
                list_del(&edge->list[LOWER]);
                list_del(&edge->list[UPPER]);
                btrfs_backref_free_edge(cache, edge);
-
-               /*
-                * Add the node to leaf node list if no other child block
-                * cached.
-                */
-               if (list_empty(&upper->lower)) {
-                       list_add_tail(&upper->lower, &cache->leaves);
-                       upper->lowest = 1;
-               }
        }
 
        btrfs_backref_drop_node(cache, node);
@@ -3589,7 +3576,6 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
        rb_node = rb_simple_insert(&cache->rb_root, start->bytenr, &start->rb_node);
        if (rb_node)
                btrfs_backref_panic(cache->fs_info, start->bytenr, -EEXIST);
-       list_add_tail(&start->lower, &cache->leaves);
 
        /*
         * Use breadth first search to iterate all related edges.
@@ -3628,11 +3614,6 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
                 * parents have already been linked.
                 */
                if (!RB_EMPTY_NODE(&upper->rb_node)) {
-                       if (upper->lowest) {
-                               list_del_init(&upper->lower);
-                               upper->lowest = 0;
-                       }
-
                        list_add_tail(&edge->list[UPPER], &upper->lower);
                        continue;
                }
index c52bc5f450414c146f1d64a47f4a04dfc260bd95..bf47f7ad08be9e957a7e285ad5136137f1ab55ca 100644 (file)
@@ -341,8 +341,6 @@ struct btrfs_backref_node {
        struct extent_buffer *eb;
        /* Level of the tree block */
        unsigned int level:8;
-       /* 1 if no child node is in the cache */
-       unsigned int lowest:1;
        /* Is the extent buffer locked */
        unsigned int locked:1;
        /* Has the block been processed */
@@ -395,8 +393,6 @@ struct btrfs_backref_cache {
         * level blocks may not reflect the new location
         */
        struct list_head pending[BTRFS_MAX_LEVEL];
-       /* List of backref nodes with no child node */
-       struct list_head leaves;
        /* List of detached backref node. */
        struct list_head detached;
 
index fe4e2528c8061d6e1061d544901cc550f67e4a04..0f94dea8e3290cb1afeae6b37b4710f9dd634392 100644 (file)
@@ -342,12 +342,6 @@ static bool handle_useless_nodes(struct reloc_control *rc,
                if (cur == node)
                        ret = true;
 
-               /* The node is the lowest node */
-               if (cur->lowest) {
-                       list_del_init(&cur->lower);
-                       cur->lowest = 0;
-               }
-
                /* Cleanup the lower edges */
                while (!list_empty(&cur->lower)) {
                        struct btrfs_backref_edge *edge;
@@ -426,7 +420,6 @@ static noinline_for_stack struct btrfs_backref_node *build_backref_tree(
                goto out;
        }
 
-       node->lowest = 1;
        cur = node;
 
        /* Breadth-first search to build backref cache */