Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] btrfs: defrag: better lone extent handling
@ 2024-03-11  6:08 Qu Wenruo
  2024-03-11  6:08 ` [PATCH v2 1/2] btrfs: defrag: add under utilized extent to defrag target list Qu Wenruo
  2024-03-11  6:08 ` [PATCH v2 2/2] btrfs: defrag: allow fine-tuning defrag behavior based on file extent usage Qu Wenruo
  0 siblings, 2 replies; 5+ messages in thread
From: Qu Wenruo @ 2024-03-11  6:08 UTC (permalink / raw)
  To: linux-btrfs

[CHANGELOG]
v2:
- Remove the "lone" naming
  Now the two new members would be named "usage_ratio" and
  "wasted_bytes".
  
- Make "usage_ratio" to be in range [0, 100]
  This should be much easier to understand.

When a file extent which can not be merged with any adjacent ones (e.g.
created by truncating a large file extent) is involved, it would haven no
chance to be touched by defrag.

This would mean that, if we have some truncated extents with very low
utilization ratio, or defragging it can free up a lot of space, defrag
would not touch them no matter what.

This is not ideal for some situations, e.g.:

  # mkfs.btrfs -f $dev
  # mount $dev $mnt
  # xfs_io -f -c "pwrite 0 128M" $mnt/foobar
  # sync
  # truncate -s 4k $mnt/foobar
  # btrfs filesystem defrag $mnt/foobar
  # sync

In above case, if defrag touches the 4k extent, it would free up the
whole 128M extent, which should be a good win.

This patchset would address the problem by introducing a special
entrance for such file extents.
Those file extents meeting either usage ratio or wasted bytes threshold
would be considered as a defrag target, allowing end uesrs to address
above situation.

This change requires progs support (or direct ioctl() calling), by
default they would be disabled.

And my personal recommendation for the ratio would be 5%, and 16MiB.

Qu Wenruo (2):
  btrfs: defrag: add under utilized extent to defrag target list
  btrfs: defrag: allow fine-tuning defrag behavior based on file extent
    usage

 fs/btrfs/defrag.c          | 46 +++++++++++++++++++++++++++++++++++---
 fs/btrfs/ioctl.c           |  6 +++++
 include/uapi/linux/btrfs.h | 40 ++++++++++++++++++++++++++++-----
 3 files changed, 84 insertions(+), 8 deletions(-)

-- 
2.44.0


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

end of thread, other threads:[~2024-03-12  3:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-11  6:08 [PATCH v2 0/2] btrfs: defrag: better lone extent handling Qu Wenruo
2024-03-11  6:08 ` [PATCH v2 1/2] btrfs: defrag: add under utilized extent to defrag target list Qu Wenruo
2024-03-11  6:08 ` [PATCH v2 2/2] btrfs: defrag: allow fine-tuning defrag behavior based on file extent usage Qu Wenruo
2024-03-11 13:54   ` kernel test robot
2024-03-12  3:06     ` Qu Wenruo

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