btrfs: rename btrfs_subpage to btrfs_folio_state
cover btrfs: rename btrfs_subpage to btrfs_folio_state
This migration is mostly to align the naming to iomap, so btrfs_subpage is renamed to btrfs_folio_state.
But before the rename, explain why btrfs needs the following extra sub-bitmaps in the first patch.
Qu Wenruo (2):
btrfs: add comments on the extra btrfs specific subpage bitmaps
btrfs: rename btrfs_subpage structure
fs/btrfs/extent_io.c | 29 +++--- fs/btrfs/inode.c | 8 +- fs/btrfs/subpage.c | 239 +++++++++++++++++++++---------------------- fs/btrfs/subpage.h | 46 +++++++-- 4 files changed, 172 insertions(+), 150 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/2 btrfs: add comments on the extra btrfs specific subpage bitmaps
Unlike the iomap_folio_state structure, the btrfs_subpage structure has a lot of extra sub-bitmaps, namingly:
- writeback sub-bitmap
- locked sub-bitmap
iomap_folio_state uses an atomic for writeback tracking, meanwhile has no per-block locked tracking.
This is because iomap always lock a single folio, and submit dirty blocks with that folio locked.
But btrfs has async delalloc ranges (for compression), which are queued with their range locked, until the compression is done, then mark the involved range writeback and unlocked.
This means a range can be unlocked and marked writeback at seemingly random timing, thus needs the extra tracking.
This needs a huge rework on the lifespan of async delalloc range before we can remove/simplify those two sub-bitmaps.
- ordered sub-bitmap
- checked sub-bitmap
These are for COW-fixup, but as I mentioned in the past, the COW-fixup is not really needed and those two flags are already marked deprecated, and will be removed in the near-future after comprehensive tests.
Add related comments to indicate we're actively trying to align the sub-bitmaps to the iomap ones.
--- fs/btrfs/subpage.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/btrfs/subpage.h +14 -0
@@ -33,8 +33,22 @@ enum { btrfs_bitmap_nr_uptodate =0 , btrfs_bitmap_nr_dirty, btrfs_bitmap_nr_writeback, +/* +* The ordered and checked flags are for COW fixup, already marked +* deprecated, and will be removed eventually. +*/ btrfs_bitmap_nr_ordered, btrfs_bitmap_nr_checked, + +/* +* The locked bit is for async delalloc range (compression), currently +* async extent is queued with the range locked, until the compression +* is done. +* So an async extent can unlock the range at any random timing. +* +* This will need a rework on the async extent lifespan (mark writeback +* and do compression) before deprecating this flag. +*/ btrfs_bitmap_nr_locked, btrfs_bitmap_nr_max };
Signature · 1 line
2.49.0
PATCH 2/2 btrfs: rename btrfs_subpage structure
In reply to Qu WenruoWith the incoming large data folios support, the structure name btrfs_subpage is no longer correct, as for we can have multiple blocks inside a large folio, and the block size is still page size.
So to follow the schema of iomap, rename btrfs_subpage to btrfs_folio_state, along with involved enums.
There are still exported functions with "btrfs_subpage_" prefix, and I believe for metadata the name "subpage" will stay forever as we will never allocate a folio larger than nodesize anyway.
The full cleanup of the word "subpage" will happen in much smaller steps in the future.
--- fs/btrfs/extent_io.c | 29 +++--- fs/btrfs/inode.c | 8 +- fs/btrfs/subpage.c | 239 +++++++++++++++++++++---------------------- fs/btrfs/subpage.h | 32 ++++-- 4 files changed, 158 insertions(+), 150 deletions(-)
fs/btrfs/extent_io.c +15 -14
@@ -782,7 +782,7 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl,static int attach_extent_buffer_folio (struct extent_buffer *eb,struct folio *folio, -struct btrfs_subpage *prealloc) +struct btrfs_folio_state *prealloc) {struct btrfs_fs_info *fs_info = eb->fs_info;int ret =0 ;
@@ -806,7 +806,7 @@ static int attach_extent_buffer_folio(struct extent_buffer *eb,/* Already mapped, just free prealloc */ if (folio_test_private (folio)) { -btrfs_free_subpage (prealloc); +btrfs_free_folio_state (prealloc);return 0 ; }
@@ -815,7 +815,7 @@ static int attach_extent_buffer_folio(struct extent_buffer *eb,folio_attach_private (folio, prealloc); else/* Do new allocation to attach subpage */ - ret =btrfs_attach_subpage (fs_info, folio,BTRFS_SUBPAGE_METADATA ); + ret =btrfs_attach_folio_state (fs_info, folio,BTRFS_SUBPAGE_METADATA );return ret; }
@@ -831,7 +831,7 @@ int set_folio_extent_mapped(struct folio *folio) fs_info =folio_to_fs_info (folio);if (btrfs_is_subpage (fs_info, folio)) -return btrfs_attach_subpage (fs_info, folio,BTRFS_SUBPAGE_DATA ); +return btrfs_attach_folio_state (fs_info, folio,BTRFS_SUBPAGE_DATA );folio_attach_private (folio, (void *)EXTENT_FOLIO_PRIVATE );return 0 ;
@@ -848,7 +848,7 @@ void clear_folio_extent_mapped(struct folio *folio) fs_info =folio_to_fs_info (folio);if (btrfs_is_subpage (fs_info, folio)) -return btrfs_detach_subpage (fs_info, folio,BTRFS_SUBPAGE_DATA ); +return btrfs_detach_folio_state (fs_info, folio,BTRFS_SUBPAGE_DATA );folio_detach_private (folio); }
@@ -2731,13 +2731,13 @@ static int extent_buffer_under_io(const struct extent_buffer *eb)static bool folio_range_has_eb (struct folio *folio) { -struct btrfs_subpage *subpage; +struct btrfs_folio_state *bfs;lockdep_assert_held (&folio->mapping->i_private_lock);if (folio_test_private (folio)) { - subpage =folio_get_private (folio); -if (atomic_read (&subpage->eb_refs)) + bfs =folio_get_private (folio); +if (atomic_read (&bfs->eb_refs))return true; }return false;
@@ -2787,7 +2787,7 @@ static void detach_extent_buffer_folio(const struct extent_buffer *eb, struct fo* attached to one dummy eb, no sharing. */ if (!mapped) { -btrfs_detach_subpage (fs_info, folio,BTRFS_SUBPAGE_METADATA ); +btrfs_detach_folio_state (fs_info, folio,BTRFS_SUBPAGE_METADATA );return ; }
@@ -2798,7 +2798,7 @@ static void detach_extent_buffer_folio(const struct extent_buffer *eb, struct fo* page range and no unfinished IO. */ if (!folio_range_has_eb (folio)) -btrfs_detach_subpage (fs_info, folio,BTRFS_SUBPAGE_METADATA ); +btrfs_detach_folio_state (fs_info, folio,BTRFS_SUBPAGE_METADATA );spin_unlock (&mapping->i_private_lock); }
@@ -3141,7 +3141,7 @@ static bool check_eb_alignment(struct btrfs_fs_info *fs_info, u64 start)* The caller needs to free the existing folios and retry using the same order. */ static int attach_eb_folio_to_filemap (struct extent_buffer *eb,int i, -struct btrfs_subpage *prealloc, +struct btrfs_folio_state *prealloc,struct extent_buffer **found_eb_ret) {
@@ -3224,7 +3224,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,int attached =0 ;struct extent_buffer *eb;struct extent_buffer *existing_eb =NULL ; -struct btrfs_subpage *prealloc =NULL ; +struct btrfs_folio_state *prealloc =NULL ;u64 lockdep_owner = owner_root;bool page_contig = true;int uptodate =1 ;
@@ -3269,7 +3269,8 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,* manually if we exit earlier. */ if (btrfs_meta_is_subpage (fs_info)) { - prealloc =btrfs_alloc_subpage (fs_info,PAGE_SIZE ,BTRFS_SUBPAGE_METADATA ); + prealloc =btrfs_alloc_folio_state (fs_info,PAGE_SIZE , +BTRFS_SUBPAGE_METADATA );if (IS_ERR (prealloc)) { ret =PTR_ERR (prealloc); goto out;
@@ -3280,7 +3281,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,/* Allocate all pages first. */ ret =alloc_eb_folio_array (eb, true);if (ret <0 ) { -btrfs_free_subpage (prealloc); +btrfs_free_folio_state (prealloc); goto out; }
fs/btrfs/inode.c +4 -4
@@ -7368,13 +7368,13 @@ struct extent_map *btrfs_create_io_em(struct btrfs_inode *inode, u64 start,static void wait_subpage_spinlock (struct folio *folio) {struct btrfs_fs_info *fs_info =folio_to_fs_info (folio); -struct btrfs_subpage *subpage; +struct btrfs_folio_state *bfs;if (!btrfs_is_subpage (fs_info, folio))return ;ASSERT (folio_test_private (folio) &&folio_get_private (folio)); - subpage =folio_get_private (folio); + bfs =folio_get_private (folio);/* * This may look insane as we just acquire the spinlock and release it,
@@ -7387,8 +7387,8 @@ static void wait_subpage_spinlock(struct folio *folio)* Here we just acquire the spinlock so that all existing callers * should exit and we're safe to release/invalidate the page. */ -spin_lock_irq (&subpage->lock); -spin_unlock_irq (&subpage->lock); +spin_lock_irq (&bfs->lock); +spin_unlock_irq (&bfs->lock); }static int btrfs_launder_folio (struct folio *folio)
fs/btrfs/subpage.c +117 -122
566 lines not on this page · raw message
fs/btrfs/subpage.h +22 -10
@@ -32,7 +32,16 @@ struct folio;enum { btrfs_bitmap_nr_uptodate =0 , btrfs_bitmap_nr_dirty, + +/* +* This can be changed to atomic eventually. +* But this change will rely on the async delalloc range rework for +* locked bitmap. +* As async delalloc can unlock its range and mark blocks writeback +* at random timing. +*/ btrfs_bitmap_nr_writeback, +/* * The ordered and checked flags are for COW fixup, already marked * deprecated, and will be removed eventually.
@@ -57,7 +66,7 @@ enum {* Structure to trace status of each sector inside a page, attached to * page::private for both data and metadata inodes. */ -struct btrfs_subpage { +struct btrfs_folio_state {/* Common members for both data and metadata pages */ spinlock_t lock;union {
@@ -65,7 +74,7 @@ struct btrfs_subpage {* Structures only used by metadata * * @eb_refs should only be operated under private_lock, as it -* manages whether the subpage can be detached. +* manages whether the btrfs_folio_state can be detached. */ atomic_t eb_refs;
@@ -79,7 +88,7 @@ struct btrfs_subpage {unsigned long bitmaps[]; }; -enum btrfs_subpage_type { +enum btrfs_folio_type {BTRFS_SUBPAGE_METADATA ,BTRFS_SUBPAGE_DATA , };
@@ -119,15 +128,18 @@ static inline bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info, }#endif -int btrfs_attach_subpage (const struct btrfs_fs_info *fs_info, -struct folio *folio,enum btrfs_subpage_type type); -void btrfs_detach_subpage (const struct btrfs_fs_info *fs_info,struct folio *folio, -enum btrfs_subpage_type type); +int btrfs_attach_folio_state (const struct btrfs_fs_info *fs_info, +struct folio *folio,enum btrfs_folio_type type); +void btrfs_detach_folio_state (const struct btrfs_fs_info *fs_info,struct folio *folio, +enum btrfs_folio_type type);/* Allocate additional data where page represents more than one sector */ -struct btrfs_subpage *btrfs_alloc_subpage (const struct btrfs_fs_info *fs_info, -size_t fsize,enum btrfs_subpage_type type); -void btrfs_free_subpage (struct btrfs_subpage *subpage); +struct btrfs_folio_state *btrfs_alloc_folio_state (const struct btrfs_fs_info *fs_info, +size_t fsize,enum btrfs_folio_type type); +static inline void btrfs_free_folio_state (struct btrfs_folio_state *bfs) +{ +kfree (bfs); +}void btrfs_folio_inc_eb_refs (const struct btrfs_fs_info *fs_info,struct folio *folio);void btrfs_folio_dec_eb_refs (const struct btrfs_fs_info *fs_info,struct folio *folio);
Signature · 1 line
2.49.0
Quoted 9 lines · Qu Wenruo
This migration is mostly to align the naming to iomap, so
btrfs_subpageis renamed tobtrfs_folio_state.But before the rename, explain why btrfs needs the following extra sub-bitmaps in the first patch.
Qu Wenruo (2):
btrfs: add comments on the extra btrfs specific subpage bitmaps
btrfs: renamebtrfs_subpagestructure
Re: [PATCH 2/2] btrfs: rename btrfs_subpage structure
In reply to Qu WenruoQuoted 7 lines · Qu Wenruo
With the incoming large data folios support, the structure name
btrfs_subpageis no longer correct, as for we can have multiple blocks inside a large folio, and the block size is still page size.So to follow the schema of iomap, rename
btrfs_subpagetobtrfs_folio_state, along with involved enums.
Quoted 6 lines
There are still exported functions with "
btrfs_subpage_" prefix, and I believe for metadata the name "subpage" will stay forever as we will never allocate a folio larger than nodesize anyway.The full cleanup of the word "subpage" will happen in much smaller steps in the future.
That's a good plan. We still have some mentions of 'page' in the context of folios too, so we'll be clening that up for some time.