From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v4 0/2] btrfs: defrag: better handling for extents which can not be merged with adjacent ones
Date: Tue, 12 Mar 2024 13:54:09 +1030 [thread overview]
Message-ID: <cover.1710213625.git.wqu@suse.com> (raw)
[CHANGELOG]
v4:
- Remove the "*_LONE_*" mentioning in uapi
- Add extra initialization for the two new members
This is to avoid fuzz tests to set those two new members without
setting the coresponding flags.
v3:
- Use div_u64() for percentage usage_ratio calculation
v1 uses "/ 65536" which compiler just optimized to right shift, and
avoided u64 division.
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 | 13 +++++++++++
include/uapi/linux/btrfs.h | 40 ++++++++++++++++++++++++++++-----
3 files changed, 91 insertions(+), 8 deletions(-)
--
2.44.0
next reply other threads:[~2024-03-12 3:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 3:24 Qu Wenruo [this message]
2024-03-12 3:24 ` [PATCH v4 1/2] btrfs: defrag: add under utilized extent to defrag target list Qu Wenruo
2024-03-12 3:24 ` [PATCH v4 2/2] btrfs: defrag: allow fine-tuning defrag behavior based on file extent usage Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1710213625.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox