]> git.hungrycats.org Git - linux/commitdiff
Btrfs: make deduplication with range including the last block work
authorFilipe Manana <fdmanana@suse.com>
Mon, 16 Dec 2019 18:26:56 +0000 (18:26 +0000)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 17 Dec 2019 22:54:35 +0000 (17:54 -0500)
Since btrfs was migrated to use the generic VFS helpers for clone and
deduplication, it stopped allowing for the last block of a file to be
deduplicated when the source file size is not sector size aligned (when
eof is somewhere in the middle of the last block). There are two reasons
for that:

1) The generic code always rounds down, to a multiple of the block size,
   the range's length for deduplications. This means we end up never
   deduplicating the last block when the eof is not block size aligned,
   even for the safe case where the destination range's end offset matches
   the destination file's size. That rounding down operation is done at
   generic_remap_check_len();

2) Because of that, the btrfs specific code does not expect anymore any
   non-aligned range length's for deduplication and therefore does not
   work if such nona-aligned length is given.

This patch addresses that second part, and it depends on a patch that
fixes generic_remap_check_len(), in the VFS, which was submitted ealier
and has the following subject:

  "fs: allow deduplication of eof block into the end of the destination file"

These two patches address reports from users that started seeing lower
deduplication rates due to the last block never being deduplicated when
the file size is not aligned to the filesystem's block size.

Link: https://lore.kernel.org/linux-btrfs/2019-1576167349.500456@svIo.N5dq.dFFD/
Signed-off-by: Filipe Manana <fdmanana@suse.com>
(cherry picked from commit f14e449df755c55056aea004d696d0ac7b317812)

fs/btrfs/ioctl.c

index 679303bf8e7414a828538aee793ad202047e34f3..361fd14695b15f05da11538eac4d3d212e027daa 100644 (file)
@@ -3239,7 +3239,7 @@ static void btrfs_double_extent_lock(struct inode *inode1, u64 loff1,
 static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 olen,
                                   struct inode *dst, u64 dst_loff)
 {
-       u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize;
+       const u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize;
        int ret;
        u64 len = olen;
 
@@ -3261,7 +3261,7 @@ static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 olen,
         * source range to serialize with relocation.
         */
        btrfs_double_extent_lock(src, loff, dst, dst_loff, len);
-       ret = btrfs_clone(src, dst, loff, olen, len, dst_loff, 1);
+       ret = btrfs_clone(src, dst, loff, len, ALIGN(len, bs), dst_loff, 1);
        btrfs_double_extent_unlock(src, loff, dst, dst_loff, len);
 
        return ret;