btrfs: defrag: introduce helper to defrag one cluster
authorQu Wenruo <wqu@suse.com>
Fri, 6 Aug 2021 08:12:39 +0000 (16:12 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 26 Oct 2021 17:07:57 +0000 (19:07 +0200)
commitb18c3ab2343d632d186963644d1e6eae1ed4330a
tree4d153968326a7c45cc94a051f471aa3e7bf1db33
parente9eec72151e215c9bc58431c1a7e00e759c6c391
btrfs: defrag: introduce helper to defrag one cluster

This new helper, defrag_one_cluster(), will defrag one cluster (at most
256K):

- Collect all initial targets

- Kick in readahead when possible

- Call defrag_one_range() on each initial target
  With some extra range clamping.

- Update @sectors_defragged parameter

This involves one behavior change, the defragged sectors accounting is
no longer as accurate as old behavior, as the initial targets are not
consistent.

We can have new holes punched inside the initial target, and we will
skip such holes later.
But the defragged sectors accounting doesn't need to be that accurate
anyway, thus I don't want to pass those extra accounting burden into
defrag_one_range().

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c