Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Cc: josef@toxicpanda.com
Subject: Re: [PATCH] btrfs: tree-checker: annotate all error branches as unlikely
Date: Sat, 21 Nov 2020 08:44:17 +0800	[thread overview]
Message-ID: <76e69b7d-ce38-47ff-82f0-4b18d8305f56@gmx.com> (raw)
In-Reply-To: <20201120161023.5033-1-dsterba@suse.com>


[-- Attachment #1.1: Type: text/plain, Size: 2473 bytes --]



On 2020/11/21 上午12:10, David Sterba wrote:
> 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>

The patch itself is pretty awesome, but still some questionable
likely/unlikely branches, comment inlined below.
> ---
> 
> Josef, would be good if you can add some details about the workload and
> hw, I'll update the changelog. Thanks.
> 
...
> @@ -181,10 +182,10 @@ static bool check_prev_ino(struct extent_buffer *leaf,
>  	 * Only subvolume trees along with their reloc trees need this check.
>  	 * Things like log tree doesn't follow this ino requirement.
>  	 */
> -	if (!is_fstree(btrfs_header_owner(leaf)))
> +	if (likely(!is_fstree(btrfs_header_owner(leaf))))
>  		return true;

This likely() is questionable.

Although the biggest metadata user of btrfs is mostly csum tree, one can
still argue that for  fs with mostly inlined extents, fs trees can be
more common.

>  
> -	if (key->objectid == prev_key->objectid)
> +	if (likely(key->objectid == prev_key->objectid))
>  		return true;

This is also questionable, this is completely dependent on fs content.

Thus we should only use likely/unlikely on the return value of
check_prev_ino(), but not inside it.

The rest looks fine.

Thanks for the effort to enhance tree-checker,
Qu



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-11-21  0:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20 16:10 [PATCH] btrfs: tree-checker: annotate all error branches as unlikely David Sterba
2020-11-21  0:44 ` Qu Wenruo [this message]
2020-11-23 15:39   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76e69b7d-ce38-47ff-82f0-4b18d8305f56@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox