btrfs: remove btrfs_folio_end_all_writers()
authorQu Wenruo <wqu@suse.com>
Fri, 30 Aug 2024 07:18:20 +0000 (16:48 +0930)
committerDavid Sterba <dsterba@suse.com>
Tue, 10 Sep 2024 14:51:22 +0000 (16:51 +0200)
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 <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c
fs/btrfs/subpage.c
fs/btrfs/subpage.h

index c079309..485d88f 100644 (file)
@@ -1466,7 +1466,8 @@ done:
                mapping_set_error(folio->mapping, ret);
        }
 
-       btrfs_folio_end_all_writers(inode_to_fs_info(inode), folio);
+       btrfs_folio_end_writer_lock(inode_to_fs_info(inode), folio,
+                                   page_start, PAGE_SIZE);
        ASSERT(ret <= 0);
        return ret;
 }
index ca7d2ae..7fe58c4 100644 (file)
@@ -322,6 +322,8 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
        const int start_bit = subpage_calc_start_bit(fs_info, folio, locked, start, len);
        const int nbits = (len >> fs_info->sectorsize_bits);
        unsigned long flags;
+       unsigned int cleared = 0;
+       int bit = start_bit;
        bool last;
 
        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
                return true;
        }
 
-       ASSERT(atomic_read(&subpage->writers) >= nbits);
-       /* The target range should have been locked. */
-       ASSERT(bitmap_test_range_all_set(subpage->bitmaps, start_bit, nbits));
-       bitmap_clear(subpage->bitmaps, start_bit, nbits);
-       last = atomic_sub_and_test(nbits, &subpage->writers);
+       for_each_set_bit_from(bit, subpage->bitmaps, start_bit + nbits) {
+               clear_bit(bit, subpage->bitmaps);
+               cleared++;
+       }
+       ASSERT(atomic_read(&subpage->writers) >= cleared);
+       last = atomic_sub_and_test(cleared, &subpage->writers);
        spin_unlock_irqrestore(&subpage->lock, flags);
        return last;
 }
@@ -825,50 +828,6 @@ out:
        return found;
 }
 
-/*
- * Unlike btrfs_folio_end_writer_lock() which unlocks a specified subpage range,
- * this ends all writer locked ranges of a page.
- *
- * This is for the locked page of extent_writepage(), as the locked page
- * can contain several locked subpage ranges.
- */
-void btrfs_folio_end_all_writers(const struct btrfs_fs_info *fs_info, struct folio *folio)
-{
-       struct btrfs_subpage *subpage = folio_get_private(folio);
-       u64 folio_start = folio_pos(folio);
-       u64 cur = folio_start;
-
-       ASSERT(folio_test_locked(folio));
-       if (!btrfs_is_subpage(fs_info, folio->mapping)) {
-               folio_unlock(folio);
-               return;
-       }
-
-       /* The page has no new delalloc range locked on it. Just plain unlock. */
-       if (atomic_read(&subpage->writers) == 0) {
-               folio_unlock(folio);
-               return;
-       }
-       while (cur < folio_start + PAGE_SIZE) {
-               u64 found_start;
-               u32 found_len;
-               bool found;
-               bool last;
-
-               found = btrfs_subpage_find_writer_locked(fs_info, folio, cur,
-                                                        &found_start, &found_len);
-               if (!found)
-                       break;
-               last = btrfs_subpage_end_and_test_writer(fs_info, folio,
-                                                        found_start, found_len);
-               if (last) {
-                       folio_unlock(folio);
-                       break;
-               }
-               cur = found_start + found_len;
-       }
-}
-
 #define GET_SUBPAGE_BITMAP(subpage, fs_info, name, dst)                        \
 {                                                                      \
        const int sectors_per_page = fs_info->sectors_per_page;         \
index b67cd5f..f90e0c4 100644 (file)
@@ -109,7 +109,6 @@ void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
 bool btrfs_subpage_find_writer_locked(const struct btrfs_fs_info *fs_info,
                                      struct folio *folio, u64 search_start,
                                      u64 *found_start_ret, u32 *found_len_ret);
-void btrfs_folio_end_all_writers(const struct btrfs_fs_info *fs_info, struct folio *folio);
 
 /*
  * Template for subpage related operations.