Skip to content

RFC btrfs: make autodefrag to defrag and only defrag small write ranges

Qu Wenruo linux-btrfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: remove an unused parameter of btrfs_add_inode_defrag()fs/btrfs/ctree.h fs/btrfs/file.c fs/btrfs/inode.c+4 -120 replies
2/3btrfs: introduce IO_TREE_AUTODEFRAG owner typefs/btrfs/extent-io-tree.h fs/btrfs/file.c+17 -10 replies
3/3btrfs: make autodefrag to defrag small writes without rescanning the whole filefs/btrfs/ctree.h fs/btrfs/disk-io.c fs/btrfs/file.c +1 more+116 -1017 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RFC 0/3] btrfs: make autodefrag to defrag and only defrag small write ranges

Previously autodefrag works by scanning the whole file with a minimal generation threshold.

Although we have various optimization to skip ranges which don't meet the generation requirement, it can still waste some time on scanning the whole file, especially if the inode got an almost full overwrite.

There is another problem, there is a gap between our small writes and defrag extent size threshold.

In fact, for compressed writes, <16K will be considered as small writes, while for uncompressed writes, <32K will be considered as small writes.

On the other hand, autodefrag uses 256K as default extent size threshold.

This means if one file has a lot of writes larger than 32K, which normally will not trigger autodefrag, but if one small write happens, all writes between 32K and 256K will be defragged.

This double standards is causing extra IO.

This patchset will address it by only defragging the small writes which trigger autodefrag.

This rework will cause the following behavior change:

- Only small write ranges will be defragged
Exactly what we want.

- Enlarged critical section for fs_info::defrag_inodes_lock Now we need to not only add the inode_defrag structure to rb tree, but also call set_extent_bits() inside the critical section.

Thus defrag_inodes_lock is upgraded to mutex.

No benchmark for the possible performance impact though.

- No inode re-queue if there are large sectors to defrag
Not sure if this will make a difference, as we no longer requeue, and only scan forward.

Reason for RFC:

I'm not sure if this is the correct way to go, but with my biased eyes, it looks very solid.

Another concern is how to backport for v5.16.

Qu Wenruo (3):
btrfs: remove an unused parameter of btrfs_add_inode_defrag()
btrfs: introduce IO_TREE_AUTODEFRAG owner type
btrfs: make autodefrag to defrag small writes without rescanning the
whole file

 fs/btrfs/ctree.h          |   5 +-
 fs/btrfs/disk-io.c        |   2 +-
 fs/btrfs/extent-io-tree.h |   1 +
 fs/btrfs/file.c           | 217 +++++++++++++++++++++-----------------
 fs/btrfs/inode.c          |   2 +-
 5 files changed, 125 insertions(+), 102 deletions(-)
Signature · 1 line
2.35.0