]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: inline btrfs_space_info_used()
authorFilipe Manana <fdmanana@suse.com>
Thu, 23 Oct 2025 12:01:34 +0000 (13:01 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:08:14 +0000 (22:08 +0100)
The function is simple enough to be inlined and in fact doing it even
reduces the object code. In x86_64 with gcc 14.2.0-19 from Debian the
results were the following:

  Before this change

    $ size fs/btrfs/btrfs.ko
      text    data     bss     dec     hex filename
    1919410  161703   15592 2096705  1ffe41 fs/btrfs/btrfs.ko

  After this change

    $ size fs/btrfs/btrfs.ko
      text    data     bss     dec     hex filename
    1918991  161675   15592 2096258  1ffc82 fs/btrfs/btrfs.ko

Also remove the ASSERT() that checks the space_info argument is not NULL,
as it's odd to be there since it can never be NULL and in case that ever
happens during development, a stack trace from a NULL pointer dereference
will be obvious. It was originally added when btrfs_space_info_used() was
introduced in commit 4136135b080f ("Btrfs: use helper to get used bytes
of space_info").

Also add a lockdep assertion to check the space_info's lock is being held
by the calling task.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/space-info.c
fs/btrfs/space-info.h

index 6c2769044b552576e96f42f049a0e16fd6186e5f..53677ecb8c15ad236c413c56a2f8daf0439ee37b 100644 (file)
  *   thing with or without extra unallocated space.
  */
 
-u64 __pure btrfs_space_info_used(const struct btrfs_space_info *s_info,
-                         bool may_use_included)
-{
-       ASSERT(s_info);
-       return s_info->bytes_used + s_info->bytes_reserved +
-               s_info->bytes_pinned + s_info->bytes_readonly +
-               s_info->bytes_zone_unusable +
-               (may_use_included ? s_info->bytes_may_use : 0);
-}
-
 /*
  * after adding space to the filesystem, we need to clear the full flags
  * on all the space infos.
index d97b0799649f3819d16c69991291c1aed32ae302..7e16d4c116c8ff78f6a17def619e826788e2f758 100644 (file)
@@ -266,6 +266,17 @@ DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info");
 DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
 DECLARE_SPACE_INFO_UPDATE(bytes_zone_unusable, "zone_unusable");
 
+static inline u64 btrfs_space_info_used(const struct btrfs_space_info *s_info,
+                                       bool may_use_included)
+{
+       lockdep_assert_held(&s_info->lock);
+
+       return s_info->bytes_used + s_info->bytes_reserved +
+               s_info->bytes_pinned + s_info->bytes_readonly +
+               s_info->bytes_zone_unusable +
+               (may_use_included ? s_info->bytes_may_use : 0);
+}
+
 int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
 void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
                                struct btrfs_block_group *block_group);
@@ -273,8 +284,6 @@ void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
                                        u64 chunk_size);
 struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
                                               u64 flags);
-u64 __pure btrfs_space_info_used(const struct btrfs_space_info *s_info,
-                         bool may_use_included);
 void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
 void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
                           bool dump_block_groups);