Skip to content

Commit b0207d5

Browse files
committed
btrfs: remove folio ordered flag and subpage bitmap
Btrfs has an internal flag/subpage bitmap called ordered, which is to indicate that a block has corresponding ordered extent covering it. However this requires extra synchronization between the inode ordered tree, and the folio flag/subpage bitmap, not to mention we need to maintain the extra folio flag with subpage bitmap. As a step to align btrfs_folio_state more closely to iomap_folio_state, remove the btrfs specific ordered flag/bitmap. This will also save us 64 bytes for the bitmap of a huge folio. Since we're here, also update the ASCII graph of the bitmap, as there are only 3 sub-bitmaps now, show all sub-bitmaps directly. Signed-off-by: Qu Wenruo <wqu@suse.com>
1 parent bc2b85a commit b0207d5

6 files changed

Lines changed: 7 additions & 91 deletions

File tree

fs/btrfs/extent_io.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ static void process_one_folio(struct btrfs_fs_info *fs_info,
250250
ASSERT(end + 1 - start != 0 && end + 1 - start < U32_MAX);
251251
len = end + 1 - start;
252252

253-
if (page_ops & PAGE_SET_ORDERED)
254-
btrfs_folio_clamp_set_ordered(fs_info, folio, start, len);
255253
if (page_ops & PAGE_START_WRITEBACK) {
256254
btrfs_folio_clamp_clear_dirty(fs_info, folio, start, len);
257255
btrfs_folio_clamp_set_writeback(fs_info, folio, start, len);
@@ -530,7 +528,6 @@ static void end_bbio_data_write(struct btrfs_bio *bbio)
530528
u32 len = fi.length;
531529

532530
bio_size += len;
533-
btrfs_folio_clear_ordered(fs_info, folio, start, len);
534531
btrfs_folio_clear_writeback(fs_info, folio, start, len);
535532
}
536533

@@ -1629,7 +1626,6 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
16291626
u64 start = page_start + (start_bit << fs_info->sectorsize_bits);
16301627
u32 len = (end_bit - start_bit) << fs_info->sectorsize_bits;
16311628

1632-
btrfs_folio_clear_ordered(fs_info, folio, start, len);
16331629
btrfs_mark_ordered_io_finished(inode, start, len, false);
16341630
}
16351631
return ret;
@@ -1707,7 +1703,6 @@ static int submit_one_sector(struct btrfs_inode *inode,
17071703
* ordered extent.
17081704
*/
17091705
btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
1710-
btrfs_folio_clear_ordered(fs_info, folio, filepos, sectorsize);
17111706
btrfs_folio_set_writeback(fs_info, folio, filepos, sectorsize);
17121707
btrfs_folio_clear_writeback(fs_info, folio, filepos, sectorsize);
17131708

@@ -1756,7 +1751,6 @@ static int submit_one_sector(struct btrfs_inode *inode,
17561751
sectorsize, filepos - folio_pos(folio), 0);
17571752
if (unlikely(queued < sectorsize)) {
17581753
btrfs_folio_clear_writeback(fs_info, folio, filepos, sectorsize);
1759-
btrfs_folio_clear_ordered(fs_info, folio, filepos, sectorsize);
17601754
btrfs_mark_ordered_io_finished(inode, filepos, fs_info->sectorsize,
17611755
false);
17621756
return -EUCLEAN;
@@ -1821,7 +1815,6 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
18211815
spin_unlock(&inode->ordered_tree_lock);
18221816
btrfs_put_ordered_extent(ordered);
18231817

1824-
btrfs_folio_clear_ordered(fs_info, folio, cur, fs_info->sectorsize);
18251818
btrfs_mark_ordered_io_finished(inode, cur, fs_info->sectorsize, true);
18261819
/*
18271820
* This range is beyond i_size, thus we don't need to

fs/btrfs/extent_io.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ enum {
5555
/* Page starts writeback, clear dirty bit and set writeback bit */
5656
ENUM_BIT(PAGE_START_WRITEBACK),
5757
ENUM_BIT(PAGE_END_WRITEBACK),
58-
ENUM_BIT(PAGE_SET_ORDERED),
5958
};
6059

6160
/*

fs/btrfs/fs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,14 +1197,6 @@ static inline void btrfs_force_shutdown(struct btrfs_fs_info *fs_info)
11971197
}
11981198
}
11991199

1200-
/*
1201-
* We use folio flag owner_2 to indicate there is an ordered extent with
1202-
* unfinished IO.
1203-
*/
1204-
#define folio_test_ordered(folio) folio_test_owner_2(folio)
1205-
#define folio_set_ordered(folio) folio_set_owner_2(folio)
1206-
#define folio_clear_ordered(folio) folio_clear_owner_2(folio)
1207-
12081200
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
12091201

12101202
#define EXPORT_FOR_TESTS

fs/btrfs/inode.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -401,28 +401,6 @@ void btrfs_inode_unlock(struct btrfs_inode *inode, unsigned int ilock_flags)
401401
static inline void btrfs_cleanup_ordered_extents(struct btrfs_inode *inode,
402402
u64 offset, u64 bytes)
403403
{
404-
pgoff_t index = offset >> PAGE_SHIFT;
405-
const pgoff_t end_index = (offset + bytes - 1) >> PAGE_SHIFT;
406-
struct folio *folio;
407-
408-
while (index <= end_index) {
409-
folio = filemap_get_folio(inode->vfs_inode.i_mapping, index);
410-
if (IS_ERR(folio)) {
411-
index++;
412-
continue;
413-
}
414-
415-
index = folio_next_index(folio);
416-
/*
417-
* Here we just clear all Ordered bits for every page in the
418-
* range, then btrfs_mark_ordered_io_finished() will handle
419-
* the ordered extent accounting for the range.
420-
*/
421-
btrfs_folio_clamp_clear_ordered(inode->root->fs_info, folio,
422-
offset, bytes);
423-
folio_put(folio);
424-
}
425-
426404
return btrfs_mark_ordered_io_finished(inode, offset, bytes, false);
427405
}
428406

@@ -1406,7 +1384,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14061384
* setup for writepage.
14071385
*/
14081386
page_ops = ((flags & COW_FILE_RANGE_KEEP_LOCKED) ? 0 : PAGE_UNLOCK);
1409-
page_ops |= PAGE_SET_ORDERED;
14101387

14111388
/*
14121389
* Relocation relies on the relocated extents to have exactly the same
@@ -1972,8 +1949,7 @@ static int nocow_one_range(struct btrfs_inode *inode, struct folio *locked_folio
19721949
goto error;
19731950
extent_clear_unlock_delalloc(inode, file_pos, end, locked_folio, cached,
19741951
EXTENT_LOCKED | EXTENT_DELALLOC |
1975-
EXTENT_CLEAR_DATA_RESV,
1976-
PAGE_SET_ORDERED);
1952+
EXTENT_CLEAR_DATA_RESV, 0);
19771953
return ret;
19781954

19791955
error:
@@ -7600,10 +7576,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset,
76007576
* The range is dirty meaning it has not been submitted.
76017577
* Here we need to truncate the OE range as the range will never
76027578
* be submitted.
7603-
*/
7604-
btrfs_folio_clear_ordered(fs_info, folio, cur, range_len);
7605-
7606-
/*
7579+
*
76077580
* IO on this page will never be started, so we need to account
76087581
* for any ordered extents now. Don't clear EXTENT_DELALLOC_NEW
76097582
* here, must leave that up for the ordered extent completion.

fs/btrfs/subpage.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -465,35 +465,6 @@ void btrfs_subpage_clear_writeback(const struct btrfs_fs_info *fs_info,
465465
spin_unlock_irqrestore(&bfs->lock, flags);
466466
}
467467

468-
void btrfs_subpage_set_ordered(const struct btrfs_fs_info *fs_info,
469-
struct folio *folio, u64 start, u32 len)
470-
{
471-
struct btrfs_folio_state *bfs = folio_get_private(folio);
472-
unsigned int start_bit = subpage_calc_start_bit(fs_info, folio,
473-
ordered, start, len);
474-
unsigned long flags;
475-
476-
spin_lock_irqsave(&bfs->lock, flags);
477-
bitmap_set(bfs->bitmaps, start_bit, len >> fs_info->sectorsize_bits);
478-
folio_set_ordered(folio);
479-
spin_unlock_irqrestore(&bfs->lock, flags);
480-
}
481-
482-
void btrfs_subpage_clear_ordered(const struct btrfs_fs_info *fs_info,
483-
struct folio *folio, u64 start, u32 len)
484-
{
485-
struct btrfs_folio_state *bfs = folio_get_private(folio);
486-
unsigned int start_bit = subpage_calc_start_bit(fs_info, folio,
487-
ordered, start, len);
488-
unsigned long flags;
489-
490-
spin_lock_irqsave(&bfs->lock, flags);
491-
bitmap_clear(bfs->bitmaps, start_bit, len >> fs_info->sectorsize_bits);
492-
if (subpage_test_bitmap_all_zero(fs_info, folio, ordered))
493-
folio_clear_ordered(folio);
494-
spin_unlock_irqrestore(&bfs->lock, flags);
495-
}
496-
497468
/*
498469
* Unlike set/clear which is dependent on each page status, for test all bits
499470
* are tested in the same way.
@@ -517,7 +488,6 @@ bool btrfs_subpage_test_##name(const struct btrfs_fs_info *fs_info, \
517488
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(uptodate);
518489
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(dirty);
519490
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(writeback);
520-
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(ordered);
521491

522492
/*
523493
* Note that, in selftests (extent-io-tests), we can have empty fs_info passed
@@ -613,8 +583,6 @@ IMPLEMENT_BTRFS_PAGE_OPS(dirty, folio_mark_dirty, folio_clear_dirty_for_io,
613583
folio_test_dirty);
614584
IMPLEMENT_BTRFS_PAGE_OPS(writeback, folio_start_writeback, folio_end_writeback,
615585
folio_test_writeback);
616-
IMPLEMENT_BTRFS_PAGE_OPS(ordered, folio_set_ordered, folio_clear_ordered,
617-
folio_test_ordered);
618586

619587
#define GET_SUBPAGE_BITMAP(fs_info, folio, name, dst) \
620588
{ \
@@ -727,7 +695,6 @@ void __cold btrfs_subpage_dump_bitmap(const struct btrfs_fs_info *fs_info,
727695
unsigned long uptodate_bitmap;
728696
unsigned long dirty_bitmap;
729697
unsigned long writeback_bitmap;
730-
unsigned long ordered_bitmap;
731698
unsigned long flags;
732699

733700
ASSERT(folio_test_private(folio) && folio_get_private(folio));
@@ -738,17 +705,15 @@ void __cold btrfs_subpage_dump_bitmap(const struct btrfs_fs_info *fs_info,
738705
GET_SUBPAGE_BITMAP(fs_info, folio, uptodate, &uptodate_bitmap);
739706
GET_SUBPAGE_BITMAP(fs_info, folio, dirty, &dirty_bitmap);
740707
GET_SUBPAGE_BITMAP(fs_info, folio, writeback, &writeback_bitmap);
741-
GET_SUBPAGE_BITMAP(fs_info, folio, ordered, &ordered_bitmap);
742708
spin_unlock_irqrestore(&bfs->lock, flags);
743709

744710
dump_page(folio_page(folio, 0), "btrfs folio state dump");
745711
btrfs_warn(fs_info,
746-
"start=%llu len=%u page=%llu, bitmaps uptodate=%*pbl dirty=%*pbl writeback=%*pbl ordered=%*pbl",
712+
"start=%llu len=%u page=%llu, bitmaps uptodate=%*pbl dirty=%*pbl writeback=%*pbl",
747713
start, len, folio_pos(folio),
748714
blocks_per_folio, &uptodate_bitmap,
749715
blocks_per_folio, &dirty_bitmap,
750-
blocks_per_folio, &writeback_bitmap,
751-
blocks_per_folio, &ordered_bitmap);
716+
blocks_per_folio, &writeback_bitmap);
752717
}
753718

754719
void btrfs_get_subpage_dirty_bitmap(struct btrfs_fs_info *fs_info,

fs/btrfs/subpage.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ struct folio;
1414
/*
1515
* Extra info for subpage bitmap.
1616
*
17-
* For subpage we pack all uptodate/dirty/writeback/ordered bitmaps into
17+
* For subpage we pack all uptodate/dirty/writeback bitmaps into
1818
* one larger bitmap.
1919
*
2020
* This structure records how they are organized in the bitmap:
2121
*
22-
* /- uptodate /- dirty /- ordered
22+
* /- uptodate /- dirty /- writeback
2323
* | | |
2424
* v v v
25-
* |u|u|u|u|........|u|u|d|d|.......|d|d|o|o|.......|o|o|
25+
* |u|u|u|u|........|u|u|d|d|.......|d|d|w|w|.......|w|w|
2626
* |< sectors_per_page >|
2727
*
2828
* Unlike regular macro-like enums, here we do not go upper-case names, as
@@ -40,11 +40,6 @@ enum {
4040
*/
4141
btrfs_bitmap_nr_writeback,
4242

43-
/*
44-
* The ordered flags shows if the range has an ordered extent.
45-
*/
46-
btrfs_bitmap_nr_ordered,
47-
4843
btrfs_bitmap_nr_max
4944
};
5045

@@ -169,7 +164,6 @@ bool btrfs_meta_folio_test_##name(struct folio *folio, const struct extent_buffe
169164
DECLARE_BTRFS_SUBPAGE_OPS(uptodate);
170165
DECLARE_BTRFS_SUBPAGE_OPS(dirty);
171166
DECLARE_BTRFS_SUBPAGE_OPS(writeback);
172-
DECLARE_BTRFS_SUBPAGE_OPS(ordered);
173167

174168
/*
175169
* Helper for error cleanup, where a folio will have its dirty flag cleared,

0 commit comments

Comments
 (0)