Skip to content

Commit 0d1ffa2

Browse files
adam900710kdave
authored andcommitted
btrfs: defrag: don't try to defrag extents which are under writeback
Once we start writeback (have called btrfs_run_delalloc_range()), we allocate an extent, create an extent map point to that extent, with a generation of (u64)-1, created the ordered extent and then clear the DELALLOC bit from the range in the inode's io tree. Such extent map can pass the first call of defrag_collect_targets(), as its generation is (u64)-1, meets any possible minimal generation check. And the range will not have DELALLOC bit, also passing the DELALLOC bit check. It will only be re-checked in the second call of defrag_collect_targets(), which will wait for writeback. But at that stage we have already spent our time waiting for some IO we may or may not want to defrag. Let's reject such extents early so we won't waste our time. CC: [email protected] # 5.16 Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ea0eba6 commit 0d1ffa2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/btrfs/ioctl.c

+4
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,10 @@ static int defrag_collect_targets(struct btrfs_inode *inode,
12101210
if (em->generation < newer_than)
12111211
goto next;
12121212

1213+
/* This em is under writeback, no need to defrag */
1214+
if (em->generation == (u64)-1)
1215+
goto next;
1216+
12131217
/*
12141218
* Our start offset might be in the middle of an existing extent
12151219
* map, so take that into account.

0 commit comments

Comments
 (0)