]> git.hungrycats.org Git - linux/commitdiff
btrfs: defrag: fix check to see if next extent can be defragged too
authorFilipe Manana <fdmanana@suse.com>
Wed, 7 Oct 2026 15:08:50 +0000 (16:08 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 12 Oct 2026 17:16:25 +0000 (19:16 +0200)
We want to check if the next extent is at maximum capacity but we are
passing the current extent map to get_extent_max_capacity() and not
the next extent map. For example if the current extent is compressed (its
maximum capacity is 128K) and the next extent is uncompressed (its
maximum capacity is 128M), then we can bail out and not defrag the next
extent too - when for example the next extent as a size of 128K, is
uncompressed, and the extent threshold is >= 256K.

Fixes: 979b25c300db ("btrfs: defrag: don't defrag extents which are already at max capacity")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/defrag.c

index 75c87aee5de94c937c375dcf255290b0b92272f5..7010d714cfe100d673a95bad364571e04136c098 100644 (file)
@@ -811,7 +811,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em,
         * If the next extent is at its max capacity, defragging current extent
         * makes no sense, as the total number of extents won't change.
         */
-       if (next->len >= get_extent_max_capacity(fs_info, em))
+       if (next->len >= get_extent_max_capacity(fs_info, next))
                goto out;
        /* Skip older extent */
        if (next->generation < newer_than)