Skip to content

Commit 2a0f7f5

Browse files
Li Zefanchrismason-xx
authored andcommitted
Btrfs: fix recursive auto-defrag
Follow those steps: # mount -o autodefrag /dev/sda7 /mnt # dd if=/dev/urandom of=/mnt/tmp bs=200K count=1 # sync # dd if=/dev/urandom of=/mnt/tmp bs=8K count=1 conv=notrunc and then it'll go into a loop: writeback -> defrag -> writeback ... It's because writeback writes [8K, 200K] and then writes [0, 8K]. I tried to make writeback know if the pages are dirtied by defrag, but the patch was a bit intrusive. Here I simply set writeback_index when we defrag a file. Signed-off-by: Li Zefan <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent b631642 commit 2a0f7f5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/btrfs/ioctl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
10551055
if (!max_to_defrag)
10561056
max_to_defrag = last_index - 1;
10571057

1058+
/*
1059+
* make writeback starts from i, so the defrag range can be
1060+
* written sequentially.
1061+
*/
1062+
if (i < inode->i_mapping->writeback_index)
1063+
inode->i_mapping->writeback_index = i;
1064+
10581065
while (i <= last_index && defrag_count < max_to_defrag) {
10591066
/*
10601067
* make sure we stop running if someone unmounts

0 commit comments

Comments
 (0)