Skip to content

Commit 79a29de

Browse files
fdmananagregkh
authored andcommitted
Btrfs: make deduplication with range including the last block work
commit 831d2fa upstream. 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/[email protected]/ CC: [email protected] # 5.1+ Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ddb36ab commit 79a29de

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3244,14 +3244,15 @@ static void btrfs_double_extent_lock(struct inode *inode1, u64 loff1,
32443244
static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 len,
32453245
struct inode *dst, u64 dst_loff)
32463246
{
3247+
const u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize;
32473248
int ret;
32483249

32493250
/*
32503251
* Lock destination range to serialize with concurrent readpages() and
32513252
* source range to serialize with relocation.
32523253
*/
32533254
btrfs_double_extent_lock(src, loff, dst, dst_loff, len);
3254-
ret = btrfs_clone(src, dst, loff, len, len, dst_loff, 1);
3255+
ret = btrfs_clone(src, dst, loff, len, ALIGN(len, bs), dst_loff, 1);
32553256
btrfs_double_extent_unlock(src, loff, dst, dst_loff, len);
32563257

32573258
return ret;

0 commit comments

Comments
 (0)