]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: add __pure attribute to eb page and folio counters
authorDavid Sterba <dsterba@suse.com>
Tue, 25 Feb 2025 17:24:43 +0000 (18:24 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:47 +0000 (20:35 +0100)
The functions qualify for the pure attribute as they always return the
same value for the same argument (in the given scope). This allows to
optimize the calls and cache the value.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.h

index ae0c04019a7eddf6d8de36895043708ea0745c19..2e261892c7bc796329377535f6c2a73ad5255730 100644 (file)
@@ -274,7 +274,8 @@ void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info,
                                u64 bytenr, u64 owner_root, u64 gen, int level);
 void btrfs_readahead_node_child(struct extent_buffer *node, int slot);
 
-static inline int num_extent_pages(const struct extent_buffer *eb)
+/* Note: this can be used in for loops without caching the value in a variable. */
+static inline int __pure num_extent_pages(const struct extent_buffer *eb)
 {
        /*
         * For sectorsize == PAGE_SIZE case, since nodesize is always aligned to
@@ -292,8 +293,10 @@ static inline int num_extent_pages(const struct extent_buffer *eb)
  * As we can have either one large folio covering the whole eb
  * (either nodesize <= PAGE_SIZE, or high order folio), or multiple
  * single-paged folios.
+ *
+ * Note: this can be used in for loops without caching the value in a variable.
  */
-static inline int num_extent_folios(const struct extent_buffer *eb)
+static inline int __pure num_extent_folios(const struct extent_buffer *eb)
 {
        if (folio_order(eb->folios[0]))
                return 1;