btrfs: remove not needed mod_start and mod_len from struct extent_map
authorFilipe Manana <fdmanana@suse.com>
Tue, 2 Apr 2024 13:24:00 +0000 (14:24 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 May 2024 19:31:02 +0000 (21:31 +0200)
The mod_start and mod_len fields of struct extent_map were introduced by
commit 4e2f84e63dc1 ("Btrfs: improve fsync by filtering extents that we
want") in order to avoid too low performance when fsyncing a file that
keeps getting extent maps merge, because it resulted in each fsync logging
again csum ranges that were already merged before.

We don't need this anymore as extent maps in the list of modified extents
are never merged with other extent maps and once we log an extent map we
remove it from the list of modified extent maps, so it's never logged
twice.

So remove the mod_start and mod_len fields from struct extent_map and use
instead the start and len fields when logging checksums in the fast fsync
path. This also makes EXTENT_FLAG_FILLING unused so remove it as well.

Running the reproducer from the commit mentioned before, with a larger
number of extents and against a null block device, so that IO is fast
and we can better see any impact from searching checksums items and
logging them, gave the following results from dd:

Before this change:

   409600000 bytes (410 MB, 391 MiB) copied, 22.948 s, 17.8 MB/s

After this change:

   409600000 bytes (410 MB, 391 MiB) copied, 22.9997 s, 17.8 MB/s

So no changes in throughput.
The test was done in a release kernel (non-debug, Debian's default kernel
config) and its steps are the following:

   $ mkfs.btrfs -f /dev/nullb0
   $ mount /dev/sdb /mnt
   $ dd if=/dev/zero of=/mnt/foobar bs=4k count=100000 oflag=sync
   $ umount /mnt

This also reduces the size of struct extent_map from 128 bytes down to 112
bytes, so now we can have 36 extents maps per 4K page instead of 32.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_map.c
fs/btrfs/extent_map.h
fs/btrfs/inode.c
fs/btrfs/tree-log.c
include/trace/events/btrfs.h

index 24a048210b15719db5ae76f09ac114e227ff0ac0..955ce300e5a1d9165a37cef8ddda80f2f1c29d25 100644 (file)
@@ -252,8 +252,6 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
                        em->len += merge->len;
                        em->block_len += merge->block_len;
                        em->block_start = merge->block_start;
-                       em->mod_len = (em->mod_len + em->mod_start) - merge->mod_start;
-                       em->mod_start = merge->mod_start;
                        em->generation = max(em->generation, merge->generation);
                        em->flags |= EXTENT_FLAG_MERGED;
 
@@ -271,7 +269,6 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
                em->block_len += merge->block_len;
                rb_erase_cached(&merge->rb_node, &tree->map);
                RB_CLEAR_NODE(&merge->rb_node);
-               em->mod_len = (merge->mod_start + merge->mod_len) - em->mod_start;
                em->generation = max(em->generation, merge->generation);
                em->flags |= EXTENT_FLAG_MERGED;
                free_extent_map(merge);
@@ -300,7 +297,6 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen)
        struct extent_map_tree *tree = &inode->extent_tree;
        int ret = 0;
        struct extent_map *em;
-       bool prealloc = false;
 
        write_lock(&tree->lock);
        em = lookup_extent_mapping(tree, start, len);
@@ -325,21 +321,9 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen)
 
        em->generation = gen;
        em->flags &= ~EXTENT_FLAG_PINNED;
-       em->mod_start = em->start;
-       em->mod_len = em->len;
-
-       if (em->flags & EXTENT_FLAG_FILLING) {
-               prealloc = true;
-               em->flags &= ~EXTENT_FLAG_FILLING;
-       }
 
        try_merge_map(tree, em);
 
-       if (prealloc) {
-               em->mod_start = em->start;
-               em->mod_len = em->len;
-       }
-
 out:
        write_unlock(&tree->lock);
        free_extent_map(em);
@@ -361,8 +345,6 @@ static inline void setup_extent_mapping(struct extent_map_tree *tree,
                                        int modified)
 {
        refcount_inc(&em->refs);
-       em->mod_start = em->start;
-       em->mod_len = em->len;
 
        ASSERT(list_empty(&em->list));
 
index c5a098c99cc6e246e49260b6bb5dac6669b1074e..10e9491865c91fb3f93c9eb307d9463d74753332 100644 (file)
@@ -30,8 +30,6 @@ enum {
        ENUM_BIT(EXTENT_FLAG_PREALLOC),
        /* Logging this extent */
        ENUM_BIT(EXTENT_FLAG_LOGGING),
-       /* Filling in a preallocated extent */
-       ENUM_BIT(EXTENT_FLAG_FILLING),
        /* This em is merged from two or more physically adjacent ems */
        ENUM_BIT(EXTENT_FLAG_MERGED),
 };
@@ -46,8 +44,6 @@ struct extent_map {
        /* all of these are in bytes */
        u64 start;
        u64 len;
-       u64 mod_start;
-       u64 mod_len;
        u64 orig_start;
        u64 orig_block_len;
        u64 ram_bytes;
index 15a13e191ee744db0d3473d59cfe24fa36d6a98a..12b1a83a43035c2ddc2a45cbf6511c621beb6012 100644 (file)
@@ -7337,9 +7337,7 @@ static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
        em->ram_bytes = ram_bytes;
        em->generation = -1;
        em->flags |= EXTENT_FLAG_PINNED;
-       if (type == BTRFS_ORDERED_PREALLOC)
-               em->flags |= EXTENT_FLAG_FILLING;
-       else if (type == BTRFS_ORDERED_COMPRESSED)
+       if (type == BTRFS_ORDERED_COMPRESSED)
                extent_map_set_compression(em, compress_type);
 
        ret = btrfs_replace_extent_map_range(inode, em, true);
index 472918a5bc73ae4a19d5b6b862306d7a3c5db724..d9777649e17058c1fe2e0584d5651fa7c99f10e5 100644 (file)
@@ -4574,8 +4574,8 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
        struct btrfs_root *csum_root;
        u64 csum_offset;
        u64 csum_len;
-       u64 mod_start = em->mod_start;
-       u64 mod_len = em->mod_len;
+       u64 mod_start = em->start;
+       u64 mod_len = em->len;
        LIST_HEAD(ordered_sums);
        int ret = 0;
 
index 90b0222390e51f4bd28f7e2528d2f6fb3262027d..766cfd48386c13646ad6095652d9b8ef80d958e6 100644 (file)
@@ -277,8 +277,7 @@ DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
                { EXTENT_FLAG_COMPRESS_LZO,     "COMPRESS_LZO"  },\
                { EXTENT_FLAG_COMPRESS_ZSTD,    "COMPRESS_ZSTD" },\
                { EXTENT_FLAG_PREALLOC,         "PREALLOC"      },\
-               { EXTENT_FLAG_LOGGING,          "LOGGING"       },\
-               { EXTENT_FLAG_FILLING,          "FILLING"       })
+               { EXTENT_FLAG_LOGGING,          "LOGGING"       })
 
 TRACE_EVENT_CONDITION(btrfs_get_extent,