btrfs: test that autdodefrag does not rewrite single extents
authorQu Wenruo <wqu@suse.com>
Tue, 15 Mar 2022 12:00:20 +0000 (20:00 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 20 Mar 2022 16:40:41 +0000 (00:40 +0800)
commit1ae79d2ecdac6f9ad94a660eca3d7586e34d7d6b
tree50b8a1463f2648483ec32b56a292eccdcc866108
parent7fad8609aedb4640b8a09162a630f1a10707228e
btrfs: test that autdodefrag does not rewrite single extents

There is a report that btrfs autodefrag is defragging extents which
only have one single sector.

Such defragging will not reduce the number of extents, but only
waste IO.

The fix for it is titled:

  btrfs: avoid defragging extents whose next extents are not targets

Here we add a test case, which will create an inode with the
following layout:

  0                16K   20K                  64K
  |<-- Extent A -->|<-B->|<----- Extent C --->|
  |Gen 7           |Gen 9|Gen 7               |

And we trigger autodefrag with newer_than = 8, which means it will
only defrag extents newer than or equal to generation 8.

Currently only Extent B meets the condition, but it can not be
merged with Extent A nor Extent C, as they don't meet the generation
requirement.

Unpatched kernel will defrag only Extent B, resulting no change in
fragmentation, while costs extra IO.

Patched kernel will not defrag anything.

Although this is still not the ideal case, as we can defrag the
whole 64K range, but that's not what autodefrag can do with its
generation limitation.

And such "perfect" defrag can cause way more IO than some users can
stand.

At least we should not only defrag extent B.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/263 [new file with mode: 0755]
tests/btrfs/263.out [new file with mode: 0644]