public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/3] btrfs: make autodefrag to defrag and only defrag small write ranges
@ 2022-02-09  9:23 Qu Wenruo
  2022-02-09  9:23 ` [PATCH RFC 1/3] btrfs: remove an unused parameter of btrfs_add_inode_defrag() Qu Wenruo
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Qu Wenruo @ 2022-02-09  9:23 UTC (permalink / raw)
  To: linux-btrfs

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(-)

-- 
2.35.0


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

end of thread, other threads:[~2022-02-15  5:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-09  9:23 [PATCH RFC 0/3] btrfs: make autodefrag to defrag and only defrag small write ranges Qu Wenruo
2022-02-09  9:23 ` [PATCH RFC 1/3] btrfs: remove an unused parameter of btrfs_add_inode_defrag() Qu Wenruo
2022-02-09  9:23 ` [PATCH RFC 2/3] btrfs: introduce IO_TREE_AUTODEFRAG owner type Qu Wenruo
2022-02-09  9:23 ` [PATCH RFC 3/3] btrfs: make autodefrag to defrag small writes without rescanning the whole file Qu Wenruo
2022-02-09 17:39   ` Filipe Manana
2022-02-10  0:31     ` Qu Wenruo
2022-02-10 15:48       ` Filipe Manana
2022-02-11  0:24         ` Qu Wenruo
2022-02-11  6:21           ` Qu Wenruo
2022-02-14 16:35           ` David Sterba
2022-02-15  5:54             ` Qu Wenruo
2022-02-09 17:48 ` [PATCH RFC 0/3] btrfs: make autodefrag to defrag and only defrag small write ranges Filipe Manana

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