]> git.hungrycats.org Git - linux/commit
btrfs: tree-checker: cache accessor return value in CHECK_FE_ALIGNED()
authorFilipe Manana <fdmanana@suse.com>
Fri, 11 Sep 2026 10:56:29 +0000 (11:56 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Sep 2026 12:56:32 +0000 (14:56 +0200)
commit6d55b4bf99d73c0bc7180c1b88f3930410ab1591
tree32b9c679769b75e09e4d9f0a629476fd266abe02
parentdf90bc736a1511db861de33ef5ef357303bee517
btrfs: tree-checker: cache accessor return value in CHECK_FE_ALIGNED()

We are calling an accessor for a file extent item multiple times in the
CHECK_FE_ALIGNED() macro, even when we don't find a corruption (once in
the if statement's expression and then once again in the expression for
the return value). This adds extra runtime overhead (which is critical
since the tree checker runs against every extent buffer when it's read
or before persisting it) and increases the module's size.

So cache the accessor's return value in a variable and use it, reducing
runtime, object size and making the source code shorter too. Also avoid
repeating twice the IS_ALIGNED() computation.

Before:

  $ size fs/btrfs/btrfs.ko
     text    data     bss     dec     hex filename
  2073340  217928   15624 2306892  23334c fs/btrfs/btrfs.ko

After:

  $ size fs/btrfs/btrfs.ko
     text    data     bss     dec     hex filename
  2073076  217928   15624 2306628  233244 fs/btrfs/btrfs.ko

Also running the following fsstress test and capturing the runtime of
check_extent_data_item() (the only caller of CHECK_FE_ALIGNED()) in
nanoseconds (using bpftrace), showed the following runtime improvements:

Test:

  mkfs.btrfs -f /dev/nullb0
  mount /dev/nullb0 /mnt
  fsstress -w -p 8 -n 5000 -s 12345 -d /mnt
  umount /mnt

Before:

  Count: 2033671
  Range:  0.000 - 1336060.000; Mean: 679.642; Median: 656.000; Stddev: 2031.323
  Percentiles:  90th: 850.000; 95th: 909.000; 99th: 1272.000
       0.000 -       6.647:      11 |
       6.647 -      28.241:      36 |
      28.241 -     110.807:     176 |
     110.807 -     426.512:   38012 #
     426.512 -    1633.663: 1983372 #####################################################
    1633.663 -    6249.399:    8315 |
    6249.399 -   23898.422:    3243 |
   23898.422 -   91382.340:     153 |
   91382.340 -  349418.114:      36 |
  349418.114 - 1336060.000:      11 |

After:

  Count: 2092797
  Range:  0.000 - 1677284.000; Mean: 627.650; Median: 617.000; Stddev: 1848.010
  Percentiles:  90th: 809.000; 95th: 859.000; 99th: 1209.000
       0.000 -       6.823:       18 |
       6.823 -      29.602:       82 |
      29.602 -     118.702:      416 |
     118.702 -     467.232:   515774 #################
     467.232 -    1830.549:  1565599 #####################################################
    1830.549 -    7163.339:     5297 |
    7163.339 -   28023.237:     4186 |
   28023.237 -  109619.427:      166 |
  109619.427 -  428793.471:       25 |
  428793.471 - 1677284.000:        4 |

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/tree-checker.c