public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: defrag: better lone extent handling
@ 2024-02-05 23:45 Qu Wenruo
  2024-02-05 23:45 ` [PATCH 1/2] btrfs: defrag: add under utilized extent to defrag target list Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Qu Wenruo @ 2024-02-05 23:45 UTC (permalink / raw)
  To: linux-btrfs

When a lone file extent (a file extent without any adjacent non-hole
file extent) is involved, it would haven no chance to be touched by
defrag.

This would mean that, if we have some lone 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 lone file extents.
Lone file extents meeting either 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 (4069 / 65536)
(aka, 1/16 of the on-disk file extent size), and 16MiB (if freeing up
the extent can free more than 16MiB, excluding the lone extent size).

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

 fs/btrfs/defrag.c          | 68 +++++++++++++++++++++++++++++++++-----
 fs/btrfs/ioctl.c           |  9 +++++
 include/uapi/linux/btrfs.h | 28 +++++++++++++---
 3 files changed, 92 insertions(+), 13 deletions(-)

-- 
2.43.0


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

end of thread, other threads:[~2024-02-07 18:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 23:45 [PATCH 0/2] btrfs: defrag: better lone extent handling Qu Wenruo
2024-02-05 23:45 ` [PATCH 1/2] btrfs: defrag: add under utilized extent to defrag target list Qu Wenruo
2024-02-06 16:23   ` Filipe Manana
2024-02-06 20:41     ` Qu Wenruo
2024-02-06 22:26       ` Qu Wenruo
2024-02-07 12:19       ` Filipe Manana
2024-02-05 23:45 ` [PATCH 2/2] btrfs: defrag: allow fine-tuning on lone extent defrag behavior Qu Wenruo
2024-02-06 17:03   ` Filipe Manana
2024-02-06 20:50     ` Qu Wenruo
2024-02-07 12:27       ` Filipe Manana
2024-02-07 17:40         ` Christoph Anton Mitterer
2024-02-06 20:27 ` [PATCH 0/2] btrfs: defrag: better lone extent handling Christoph Anton Mitterer

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