Skip to content

Commit 49a9907

Browse files
adam900710kdave
authored andcommitted
btrfs: merge btrfs_folio_unlock_writer() into btrfs_folio_end_writer_lock()
The function btrfs_folio_unlock_writer() is already calling btrfs_folio_end_writer_lock() to do the heavy lifting work, the only missing 0 writer check. Thus there is no need to keep two different functions, move the 0 writer check into btrfs_folio_end_writer_lock(), and remove btrfs_folio_unlock_writer(). Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 68f32b9 commit 49a9907

File tree

3 files changed

+35
-50
lines changed

3 files changed

+35
-50
lines changed

fs/btrfs/extent_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
22202220
cur, cur_len, !ret);
22212221
mapping_set_error(mapping, ret);
22222222
}
2223-
btrfs_folio_unlock_writer(fs_info, folio, cur, cur_len);
2223+
btrfs_folio_end_writer_lock(fs_info, folio, cur, cur_len);
22242224
if (ret < 0)
22252225
found_error = true;
22262226
next_page:

fs/btrfs/subpage.c

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,47 @@ int btrfs_folio_start_writer_lock(const struct btrfs_fs_info *fs_info,
378378
return 0;
379379
}
380380

381+
/*
382+
* Handle different locked folios:
383+
*
384+
* - Non-subpage folio
385+
* Just unlock it.
386+
*
387+
* - folio locked but without any subpage locked
388+
* This happens either before writepage_delalloc() or the delalloc range is
389+
* already handled by previous folio.
390+
* We can simple unlock it.
391+
*
392+
* - folio locked with subpage range locked.
393+
* We go through the locked sectors inside the range and clear their locked
394+
* bitmap, reduce the writer lock number, and unlock the page if that's
395+
* the last locked range.
396+
*/
381397
void btrfs_folio_end_writer_lock(const struct btrfs_fs_info *fs_info,
382398
struct folio *folio, u64 start, u32 len)
383399
{
400+
struct btrfs_subpage *subpage = folio_get_private(folio);
401+
402+
ASSERT(folio_test_locked(folio));
403+
384404
if (unlikely(!fs_info) || !btrfs_is_subpage(fs_info, folio->mapping)) {
385405
folio_unlock(folio);
386406
return;
387407
}
408+
409+
/*
410+
* For subpage case, there are two types of locked page. With or
411+
* without writers number.
412+
*
413+
* Since we own the page lock, no one else could touch subpage::writers
414+
* and we are safe to do several atomic operations without spinlock.
415+
*/
416+
if (atomic_read(&subpage->writers) == 0) {
417+
/* No writers, locked by plain lock_page(). */
418+
folio_unlock(folio);
419+
return;
420+
}
421+
388422
btrfs_subpage_clamp_range(folio, &start, &len);
389423
if (btrfs_subpage_end_and_test_writer(fs_info, folio, start, len))
390424
folio_unlock(folio);
@@ -702,53 +736,6 @@ void btrfs_folio_assert_not_dirty(const struct btrfs_fs_info *fs_info,
702736
spin_unlock_irqrestore(&subpage->lock, flags);
703737
}
704738

705-
/*
706-
* Handle different locked pages with different page sizes:
707-
*
708-
* - Page locked by plain lock_page()
709-
* It should not have any subpage::writers count.
710-
* Can be unlocked by unlock_page().
711-
* This is the most common locked page for extent_writepage() called
712-
* inside extent_write_cache_pages().
713-
* Rarer cases include the @locked_page from extent_write_locked_range().
714-
*
715-
* - Page locked by lock_delalloc_pages()
716-
* There is only one caller, all pages except @locked_page for
717-
* extent_write_locked_range().
718-
* In this case, we have to call subpage helper to handle the case.
719-
*/
720-
void btrfs_folio_unlock_writer(struct btrfs_fs_info *fs_info,
721-
struct folio *folio, u64 start, u32 len)
722-
{
723-
struct btrfs_subpage *subpage;
724-
725-
ASSERT(folio_test_locked(folio));
726-
/* For non-subpage case, we just unlock the page */
727-
if (!btrfs_is_subpage(fs_info, folio->mapping)) {
728-
folio_unlock(folio);
729-
return;
730-
}
731-
732-
ASSERT(folio_test_private(folio) && folio_get_private(folio));
733-
subpage = folio_get_private(folio);
734-
735-
/*
736-
* For subpage case, there are two types of locked page. With or
737-
* without writers number.
738-
*
739-
* Since we own the page lock, no one else could touch subpage::writers
740-
* and we are safe to do several atomic operations without spinlock.
741-
*/
742-
if (atomic_read(&subpage->writers) == 0) {
743-
/* No writers, locked by plain lock_page() */
744-
folio_unlock(folio);
745-
return;
746-
}
747-
748-
/* Have writers, use proper subpage helper to end it */
749-
btrfs_folio_end_writer_lock(fs_info, folio, start, len);
750-
}
751-
752739
/*
753740
* This is for folio already locked by plain lock_page()/folio_lock(), which
754741
* doesn't have any subpage awareness.

fs/btrfs/subpage.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
155155

156156
void btrfs_folio_assert_not_dirty(const struct btrfs_fs_info *fs_info,
157157
struct folio *folio, u64 start, u32 len);
158-
void btrfs_folio_unlock_writer(struct btrfs_fs_info *fs_info,
159-
struct folio *folio, u64 start, u32 len);
160158
void btrfs_get_subpage_dirty_bitmap(struct btrfs_fs_info *fs_info,
161159
struct folio *folio,
162160
unsigned long *ret_bitmap);

0 commit comments

Comments
 (0)