]> www.infradead.org Git - users/hch/misc.git/commitdiff
btrfs: send: index backref cache by node number instead of by sector number
authorFilipe Manana <fdmanana@suse.com>
Mon, 8 Sep 2025 11:19:29 +0000 (12:19 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 23 Sep 2025 06:49:21 +0000 (08:49 +0200)
We now have a nodesize_bits member in fs_info so we can index an extent
buffer in the backref cache by node number instead of by sector number.
While this allows for a denser index space with the possibility of using
less maple tree nodes, in practice it's unlikely to hit such benefits
since we currently limit the maximum number of keys in the cache to 128,
so unless all extent buffers are contiguous we are unlikely to see a
memory usage reduction in the backing maple tree due to fewer nodes.
Nevertheless it doesn't cost anything to index by node number and it's
more logical.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/send.c

index c5771df3a2c7c056782c658334504a444804095d..32653fc44a7583f731ef1fb92bd4355e5bc4c0fc 100644 (file)
@@ -1388,7 +1388,7 @@ static bool lookup_backref_cache(u64 leaf_bytenr, void *ctx,
        struct backref_ctx *bctx = ctx;
        struct send_ctx *sctx = bctx->sctx;
        struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
-       const u64 key = leaf_bytenr >> fs_info->sectorsize_bits;
+       const u64 key = leaf_bytenr >> fs_info->nodesize_bits;
        struct btrfs_lru_cache_entry *raw_entry;
        struct backref_cache_entry *entry;
 
@@ -1443,7 +1443,7 @@ static void store_backref_cache(u64 leaf_bytenr, const struct ulist *root_ids,
        if (!new_entry)
                return;
 
-       new_entry->entry.key = leaf_bytenr >> fs_info->sectorsize_bits;
+       new_entry->entry.key = leaf_bytenr >> fs_info->nodesize_bits;
        new_entry->entry.gen = 0;
        new_entry->num_roots = 0;
        ULIST_ITER_INIT(&uiter);