Skip to content

Commit b672876

Browse files
nefelim4agkdave
authored andcommitted
Btrfs: dedupe_file_range ioctl: remove 16MiB restriction
Currently btrfs_dedupe_file_range silently restricts the dedupe range to to 16MiB to limit locking and working memory size and is documented in manual page as implementation specific. Let's remove that restriction by iterating over the dedup range in 16MiB steps. This is backward compatible and will not change anything for requests smaller then 16MiB. Signed-off-by: Timofey Titovets <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 3973909 commit b672876

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

fs/btrfs/ioctl.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,11 +3128,14 @@ static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 olen,
31283128
return ret;
31293129
}
31303130

3131+
#define BTRFS_MAX_DEDUPE_LEN SZ_16M
3132+
31313133
static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
31323134
struct inode *dst, u64 dst_loff)
31333135
{
31343136
int ret;
31353137
bool same_inode = (src == dst);
3138+
u64 i, tail_len, chunk_count;
31363139

31373140
if (olen == 0)
31383141
return 0;
@@ -3149,7 +3152,21 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
31493152
goto out_unlock;
31503153
}
31513154

3152-
ret = btrfs_extent_same_range(src, loff, olen, dst, dst_loff);
3155+
tail_len = olen % BTRFS_MAX_DEDUPE_LEN;
3156+
chunk_count = div_u64(olen, BTRFS_MAX_DEDUPE_LEN);
3157+
3158+
for (i = 0; i < chunk_count; i++) {
3159+
ret = btrfs_extent_same_range(src, loff, BTRFS_MAX_DEDUPE_LEN,
3160+
dst, dst_loff);
3161+
if (ret)
3162+
goto out_unlock;
3163+
3164+
loff += BTRFS_MAX_DEDUPE_LEN;
3165+
dst_loff += BTRFS_MAX_DEDUPE_LEN;
3166+
}
3167+
3168+
if (tail_len > 0)
3169+
ret = btrfs_extent_same_range(src, loff, tail_len, dst, dst_loff);
31533170

31543171
out_unlock:
31553172
if (same_inode)
@@ -3160,8 +3177,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
31603177
return ret;
31613178
}
31623179

3163-
#define BTRFS_MAX_DEDUPE_LEN SZ_16M
3164-
31653180
ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen,
31663181
struct file *dst_file, u64 dst_loff)
31673182
{
@@ -3170,9 +3185,6 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen,
31703185
u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize;
31713186
ssize_t res;
31723187

3173-
if (olen > BTRFS_MAX_DEDUPE_LEN)
3174-
olen = BTRFS_MAX_DEDUPE_LEN;
3175-
31763188
if (WARN_ON_ONCE(bs < PAGE_SIZE)) {
31773189
/*
31783190
* Btrfs does not support blocksize < page_size. As a

0 commit comments

Comments
 (0)