Skip to content

Commit ab6eac7

Browse files
adam900710kdave
authored andcommitted
btrfs: remove btrfs_folio_end_all_writers()
The function btrfs_folio_end_all_writers() is only utilized in extent_writepage() as a way to unlock all subpage range (for both successful submission and error handling). Meanwhile we have a similar function, btrfs_folio_end_writer_lock(). The difference is, btrfs_folio_end_writer_lock() expects a range that is a subset of the already locked range. This limit on btrfs_folio_end_writer_lock() is a little overkilled, preventing it from being utilized for error paths. So here we enhance btrfs_folio_end_writer_lock() to accept a superset of the locked range, and only end the locked subset. This means we can replace btrfs_folio_end_all_writers() with btrfs_folio_end_writer_lock() instead. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ca283ea commit ab6eac7

File tree

3 files changed

+10
-51
lines changed

3 files changed

+10
-51
lines changed

fs/btrfs/extent_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,8 @@ static int extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ctrl
14661466
mapping_set_error(folio->mapping, ret);
14671467
}
14681468

1469-
btrfs_folio_end_all_writers(inode_to_fs_info(inode), folio);
1469+
btrfs_folio_end_writer_lock(inode_to_fs_info(inode), folio,
1470+
page_start, PAGE_SIZE);
14701471
ASSERT(ret <= 0);
14711472
return ret;
14721473
}

fs/btrfs/subpage.c

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
322322
const int start_bit = subpage_calc_start_bit(fs_info, folio, locked, start, len);
323323
const int nbits = (len >> fs_info->sectorsize_bits);
324324
unsigned long flags;
325+
unsigned int cleared = 0;
326+
int bit = start_bit;
325327
bool last;
326328

327329
btrfs_subpage_assert(fs_info, folio, start, len);
@@ -339,11 +341,12 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
339341
return true;
340342
}
341343

342-
ASSERT(atomic_read(&subpage->writers) >= nbits);
343-
/* The target range should have been locked. */
344-
ASSERT(bitmap_test_range_all_set(subpage->bitmaps, start_bit, nbits));
345-
bitmap_clear(subpage->bitmaps, start_bit, nbits);
346-
last = atomic_sub_and_test(nbits, &subpage->writers);
344+
for_each_set_bit_from(bit, subpage->bitmaps, start_bit + nbits) {
345+
clear_bit(bit, subpage->bitmaps);
346+
cleared++;
347+
}
348+
ASSERT(atomic_read(&subpage->writers) >= cleared);
349+
last = atomic_sub_and_test(cleared, &subpage->writers);
347350
spin_unlock_irqrestore(&subpage->lock, flags);
348351
return last;
349352
}
@@ -825,50 +828,6 @@ bool btrfs_subpage_find_writer_locked(const struct btrfs_fs_info *fs_info,
825828
return found;
826829
}
827830

828-
/*
829-
* Unlike btrfs_folio_end_writer_lock() which unlocks a specified subpage range,
830-
* this ends all writer locked ranges of a page.
831-
*
832-
* This is for the locked page of extent_writepage(), as the locked page
833-
* can contain several locked subpage ranges.
834-
*/
835-
void btrfs_folio_end_all_writers(const struct btrfs_fs_info *fs_info, struct folio *folio)
836-
{
837-
struct btrfs_subpage *subpage = folio_get_private(folio);
838-
u64 folio_start = folio_pos(folio);
839-
u64 cur = folio_start;
840-
841-
ASSERT(folio_test_locked(folio));
842-
if (!btrfs_is_subpage(fs_info, folio->mapping)) {
843-
folio_unlock(folio);
844-
return;
845-
}
846-
847-
/* The page has no new delalloc range locked on it. Just plain unlock. */
848-
if (atomic_read(&subpage->writers) == 0) {
849-
folio_unlock(folio);
850-
return;
851-
}
852-
while (cur < folio_start + PAGE_SIZE) {
853-
u64 found_start;
854-
u32 found_len;
855-
bool found;
856-
bool last;
857-
858-
found = btrfs_subpage_find_writer_locked(fs_info, folio, cur,
859-
&found_start, &found_len);
860-
if (!found)
861-
break;
862-
last = btrfs_subpage_end_and_test_writer(fs_info, folio,
863-
found_start, found_len);
864-
if (last) {
865-
folio_unlock(folio);
866-
break;
867-
}
868-
cur = found_start + found_len;
869-
}
870-
}
871-
872831
#define GET_SUBPAGE_BITMAP(subpage, fs_info, name, dst) \
873832
{ \
874833
const int sectors_per_page = fs_info->sectors_per_page; \

fs/btrfs/subpage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
109109
bool btrfs_subpage_find_writer_locked(const struct btrfs_fs_info *fs_info,
110110
struct folio *folio, u64 search_start,
111111
u64 *found_start_ret, u32 *found_len_ret);
112-
void btrfs_folio_end_all_writers(const struct btrfs_fs_info *fs_info, struct folio *folio);
113112

114113
/*
115114
* Template for subpage related operations.

0 commit comments

Comments
 (0)