]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ext4: replace ext4_es_insert_extent() when caching on-disk extents
authorZhang Yi <yi.zhang@huawei.com>
Sat, 29 Nov 2025 10:32:45 +0000 (18:32 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 18 Jan 2026 16:23:34 +0000 (11:23 -0500)
In ext4, the remaining places for inserting extents into the extent
status tree within ext4_ext_determine_insert_hole() and
ext4_map_query_blocks() directly cache on-disk extents. We can use
ext4_es_cache_extent() instead of ext4_es_insert_extent() in these
cases. This will help reduce unnecessary increases in extent sequence
numbers and cache invalidations after supporting IOMAP in the future.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Baokun Li <libaokun1@huawei.com>
Message-ID: <20251129103247.686136-14-yi.zhang@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/extents.c
fs/ext4/inode.c

index 2cfce2c012084b68489f1fe14085d206da252e75..27eb2c1df012832c3ed45329c68ce598cdc96317 100644 (file)
@@ -4192,8 +4192,7 @@ again:
 insert_hole:
        /* Put just found gap into cache to speed up subsequent requests */
        ext_debug(inode, " -> %u:%u\n", hole_start, len);
-       ext4_es_insert_extent(inode, hole_start, len, ~0,
-                             EXTENT_STATUS_HOLE, false);
+       ext4_es_cache_extent(inode, hole_start, len, ~0, EXTENT_STATUS_HOLE);
 
        /* Update hole_len to reflect hole size after lblk */
        if (hole_start != lblk)
index 0c466ccbed69672a983339fa53d0bdc986f7d885..08a7f2b54a9e1cf70f5837d28f8a7f01d443c54b 100644 (file)
@@ -503,8 +503,8 @@ static int ext4_map_query_blocks_next_in_leaf(handle_t *handle,
        retval = ext4_ext_map_blocks(handle, inode, &map2, 0);
 
        if (retval <= 0) {
-               ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
-                                     map->m_pblk, status, false);
+               ext4_es_cache_extent(inode, map->m_lblk, map->m_len,
+                                    map->m_pblk, status);
                return map->m_len;
        }
 
@@ -525,13 +525,13 @@ static int ext4_map_query_blocks_next_in_leaf(handle_t *handle,
         */
        if (map->m_pblk + map->m_len == map2.m_pblk &&
                        status == status2) {
-               ext4_es_insert_extent(inode, map->m_lblk,
-                                     map->m_len + map2.m_len, map->m_pblk,
-                                     status, false);
+               ext4_es_cache_extent(inode, map->m_lblk,
+                                    map->m_len + map2.m_len, map->m_pblk,
+                                    status);
                map->m_len += map2.m_len;
        } else {
-               ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
-                                     map->m_pblk, status, false);
+               ext4_es_cache_extent(inode, map->m_lblk, map->m_len,
+                                    map->m_pblk, status);
        }
 
        return map->m_len;
@@ -573,8 +573,8 @@ static int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
                        map->m_len == orig_mlen) {
                status = map->m_flags & EXT4_MAP_UNWRITTEN ?
                                EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
-               ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
-                                     map->m_pblk, status, false);
+               ext4_es_cache_extent(inode, map->m_lblk, map->m_len,
+                                    map->m_pblk, status);
        } else {
                retval = ext4_map_query_blocks_next_in_leaf(handle, inode, map,
                                                            orig_mlen);