OSDN Git Service

btrfs: tree-checker: annotate all error branches as unlikely
authorDavid Sterba <dsterba@suse.com>
Wed, 4 Nov 2020 15:12:45 +0000 (16:12 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 8 Dec 2020 14:54:15 +0000 (15:54 +0100)
commitc7c01a4a2524b3f130c1821fbaf1677fe8394165
treeacb487907df3c6732dfbfb5e397f1e7164f7ad5f
parenta0f6d924cada10eefa526ccfa1be7888f559d9d7
btrfs: tree-checker: annotate all error branches as unlikely

The tree checker is called many times as it verifies metadata at
read/write time. The checks follow a simple pattern:

  if (error_condition) {
  report_error();
  return -EUCLEAN;
  }

All the error reporting functions are annotated as __cold that is
supposed to hint the compiler to move the statement block out of the hot
path. This does not seem to happen that often.

As the error condition is expected to be false almost always, we can
annotate it with 'unlikely' as this satisfies one of the few use cases
for the annotation. The expected outcome is a stronger hint to compiler
to reorder the checks

  test
  jump to exit
  test
  jump to exit
  ...

which can be observed in asm of eg. check_dir_item,
btrfs_check_chunk_valid, check_root_item or check_leaf.

There's a measurable run time improvement reported by Josef, the testing
workload went from 655 MiB/s to 677 MiB/s, which is about +3%.

There should be no functional changes but some of the conditions have
been rewritten to produce more readable result, some lines are longer
than 80, for the sake of readability.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-checker.c