public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: defrag: don't try to defrag extent which is going to be written back
@ 2022-02-07  5:17 Qu Wenruo
  2022-02-07 10:35 ` Filipe Manana
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2022-02-07  5:17 UTC (permalink / raw)
  To: linux-btrfs

In defrag_collect_targets() if we hit an extent map which is created by
create_io_em(), it will be considered as target as its generation is
(u64)-1, thus will pass the generation check.

Furthermore since all delalloc functions will clear EXTENT_DELALLOC,
such extent map will also pass the EXTENT_DELALLOC check.

Defragging such extent will make no sense, in fact this will cause extra
IO as we will just re-dirty the range and submit it for writeback again,
causing wasted IO.

Unfortunately this behavior seems to exist in older kernels too (v5.15
and older), but I don't have a solid test case to prove it nor test the
patched behavior.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/ioctl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 133e3e2e2e79..0ba98e1d9329 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1353,6 +1353,10 @@ static int defrag_collect_targets(struct btrfs_inode *inode,
 		if (em->generation < ctrl->newer_than)
 			goto next;
 
+		/* This em is goging to be written back, no need to defrag */
+		if (em->generation == (u64)-1)
+			goto next;
+
 		/*
 		 * Our start offset might be in the middle of an existing extent
 		 * map, so take that into account.
-- 
2.35.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-07 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-07  5:17 [PATCH] btrfs: defrag: don't try to defrag extent which is going to be written back Qu Wenruo
2022-02-07 10:35 ` Filipe Manana
2022-02-07 11:06   ` Qu Wenruo
2022-02-07 12:53     ` Filipe Manana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox