btrfs: combine btrfs_clear_buffer_dirty and clear_extent_buffer_dirty
authorJosef Bacik <josef@toxicpanda.com>
Thu, 26 Jan 2023 21:00:59 +0000 (16:00 -0500)
committerDavid Sterba <dsterba@suse.com>
Wed, 15 Feb 2023 18:38:54 +0000 (19:38 +0100)
btrfs_clear_buffer_dirty just does the test_clear_bit() and then calls
clear_extent_buffer_dirty and does the dirty metadata accounting.
Combine this into clear_extent_buffer_dirty and make the result
btrfs_clear_buffer_dirty.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h

index 2ef9e0b3a4258fd5870bba7b86ad0a0a2f74de2e..b53f0e30ce2b3bbb2e40baa1163ee57e29e942b7 100644 (file)
@@ -868,22 +868,6 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
 
 }
 
-void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
-                             struct extent_buffer *buf)
-{
-       struct btrfs_fs_info *fs_info = buf->fs_info;
-       if (!trans || btrfs_header_generation(buf) == trans->transid) {
-               btrfs_assert_tree_write_locked(buf);
-
-               if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)) {
-                       percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,
-                                                -buf->len,
-                                                fs_info->dirty_metadata_batch);
-                       clear_extent_buffer_dirty(buf);
-               }
-       }
-}
-
 static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
                         u64 objectid)
 {
index ada88ada49e1d4c620ddaac82f04f1d4c4f703df..287e25edb3ef4cea7832669968543b5da97c63e4 100644 (file)
@@ -36,6 +36,7 @@
 #include "file.h"
 #include "dev-replace.h"
 #include "super.h"
+#include "transaction.h"
 
 static struct kmem_cache *extent_buffer_cache;
 
@@ -4268,12 +4269,25 @@ static void clear_subpage_extent_buffer_dirty(const struct extent_buffer *eb)
        WARN_ON(atomic_read(&eb->refs) == 0);
 }
 
-void clear_extent_buffer_dirty(const struct extent_buffer *eb)
+void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
+                             struct extent_buffer *eb)
 {
+       struct btrfs_fs_info *fs_info = eb->fs_info;
        int i;
        int num_pages;
        struct page *page;
 
+       btrfs_assert_tree_write_locked(eb);
+
+       if (trans && btrfs_header_generation(eb) != trans->transid)
+               return;
+
+       if (!test_and_clear_bit(EXTENT_BUFFER_DIRTY, &eb->bflags))
+               return;
+
+       percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, -eb->len,
+                                fs_info->dirty_metadata_batch);
+
        if (eb->fs_info->nodesize < PAGE_SIZE)
                return clear_subpage_extent_buffer_dirty(eb);
 
index 1b311cd6978321182251622a037b2c703bd5465e..4341ad978fb8e43fa185df4fbb82938fed2f3d31 100644 (file)
@@ -11,6 +11,8 @@
 #include "ulist.h"
 #include "misc.h"
 
+struct btrfs_trans_handle;
+
 enum {
        EXTENT_BUFFER_UPTODATE,
        EXTENT_BUFFER_DIRTY,
@@ -260,7 +262,6 @@ void extent_buffer_bitmap_set(const struct extent_buffer *eb, unsigned long star
 void extent_buffer_bitmap_clear(const struct extent_buffer *eb,
                                unsigned long start, unsigned long pos,
                                unsigned long len);
-void clear_extent_buffer_dirty(const struct extent_buffer *eb);
 bool set_extent_buffer_dirty(struct extent_buffer *eb);
 void set_extent_buffer_uptodate(struct extent_buffer *eb);
 void clear_extent_buffer_uptodate(struct extent_buffer *eb);
@@ -272,6 +273,8 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
                                  u32 bits_to_clear, unsigned long page_ops);
 int extent_invalidate_folio(struct extent_io_tree *tree,
                            struct folio *folio, size_t offset);
+void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
+                             struct extent_buffer *buf);
 
 int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array);