Skip to content

btrfs: Refactor find_free_extent()

Qu Wenruo linux-btrfs 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest4 patches 1 replyIn review
  2. v44 patches 4 repliesSuperseded
  3. v34 patches 6 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v24 patches7 repliesSuperseded
v1 RFC1 patch2 repliesSuperseded

Changes in v5 from the cover letter

Fix all warning reported by checkpatch.pl
Rebase to misc-4.20.
Solve conflicts with fb5c39d7a887 ("btrfs: don't use ctl->free_space for max_extent_size"). This results:
* New member find_free_extent_ctl::total_free_space
* New comment for find_free_extent_ctl::total_free_space
* New comment for falling back to total_free_space if we can't find
valid find_free_extent_ctl::max_extent_size.

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4btrfs: Introduce find_free_extent_ctl structure for later reworkfs/btrfs/extent-tree.c+170 -950 replies
2/4btrfs: Refactor clustered extent allocation into find_free_extent_clustered()fs/btrfs/extent-tree.c+122 -1230 replies
3/4btrfs: Refactor unclustered extent allocation into find_free_extent_unclustered()fs/btrfs/extent-tree.c+68 -460 replies
4/4btrfs: Refactor find_free_extent() loops update into find_free_extent_update_loop()fs/btrfs/extent-tree.c+117 -1000 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchSu YueJosef Bacik
1/4R-b R-b
2/4R-b R-b
3/4R-b R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 0/4] btrfs: Refactor find_free_extent()

Can be fetched from github:
https://github.com/adam900710/linux/tree/refactor_find_free_extent

Which is based on david's misc-4.20 branch.
The base head is:

commit 9084cb6a24bf5838a665af92ded1af8363f9e563 (david/misc-4.20)

Author: Filipe Manana <[email protected]>
Date:   Mon Oct 22 10:43:06 2018 +0100

Btrfs: fix use-after-free when dumping free space

extent-tree.c::find_free_extent() could be one of the most ill-structured functions, it has at least 6 non-exit tags and jumps between them.

Refactor it into 4 parts:

1) find_free_extent()
The main entrance, does the main work of block group iteration and block group selection.
Now this function doesn't care nor handles free extent search by itself.

2) find_free_extent_clustered()
Do clustered free extent search.
May try to build/re-fill cluster.

3) find_free_extent_unclustered()
Do unclustered free extent search.
May try to fill free space cache.

4) find_free_extent_update_loop()
Do the loop based black magic.
May allocate new chunk.

With this patch, at least we should make find_free_extent() a little easier to read, and provides the basis for later work on this function.

Current refactor is trying not to touch the original functionality, thus the helper structure find_free_extent_ctl still contains a lot of unrelated members.
But it should not change how find_free_extent() works at all.

changelog:
v2:
Split into 4 patches.
Minor comment newline change.
v3:
Mostly cosmetic update.
Rebased to v4.19-rc1
Rename find_free_extent_ctrl to find_free_extent_ctl to keep the
naming scheme the same.
Fix some comment spelling error.
Enhance comment for find_free_extent_unclustered().
Add reviewed-by tag.
v4:
Move the (ins->objectid) check to proper location of the last patch,
so all (!ins->objectid) branches are in the same code block.
Add reviewed-by tags from Josef.
v5:
Fix all warning reported by checkpatch.pl
Rebase to misc-4.20.
Solve conflicts with fb5c39d7a887 ("btrfs: don't use ctl->free_space for max_extent_size"). This results:
* New member find_free_extent_ctl::total_free_space
* New comment for find_free_extent_ctl::total_free_space
* New comment for falling back to total_free_space if we can't find
valid find_free_extent_ctl::max_extent_size.

Qu Wenruo (4):
btrfs: Introduce find_free_extent_ctl structure for later rework
btrfs: Refactor clustered extent allocation into
find_free_extent_clustered()
btrfs: Refactor unclustered extent allocation into
find_free_extent_unclustered()
btrfs: Refactor find_free_extent() loops update into
find_free_extent_update_loop()

 fs/btrfs/extent-tree.c | 715 ++++++++++++++++++++++++-----------------
 1 file changed, 414 insertions(+), 301 deletions(-)
Signature · 1 line
2.19.1