From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F7F9C7EE23 for ; Tue, 23 May 2023 12:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236873AbjEWMhq (ORCPT ); Tue, 23 May 2023 08:37:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbjEWMho (ORCPT ); Tue, 23 May 2023 08:37:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAC48DD; Tue, 23 May 2023 05:37:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6FBF2631E6; Tue, 23 May 2023 12:37:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1AFFC433D2; Tue, 23 May 2023 12:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684845462; bh=IrFR6hSXFwTPIqL0va6YERj1ltruCOkzI1N56fCgPFM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BbcPp5Wk39tfRgN0F4hqRWr2z1n0SIKLjtFrqEbV6rdwWzWWBf41JaluXdPwngS7n YkP2M+MNrre1IqYdowqD2gvwspBlw+78DyFX72q66G+F/EgL87TSfBL03dsoLrD1qM au4VSvKklwQat8ncTYQIWu6YEu3YE2e8269d+DGcLRwFi/TP2lU7v9EbyBbjcrqMjT TfL44g4byc+ONKKhrrNPF7Del3TtLGY10AAIErkDGWFzW9t8m2z9qEjENI9kADmq1S RJahiUXw1uO7b7wkD3a2j0nrda5NEi0cA233jlDNrLclS7KunYJMBDqfAzEFmnY2a2 OI0JXdTdk+PsQ== Date: Tue, 23 May 2023 14:37:35 +0200 From: Christian Brauner To: David Howells Cc: Jens Axboe , Al Viro , Christoph Hellwig , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: Re: [PATCH v21 2/6] block: Fix bio_flagged() so that gcc can better optimise it Message-ID: <20230523-kommst-gewechselt-e7b94e891a12@brauner> References: <20230522205744.2825689-1-dhowells@redhat.com> <20230522205744.2825689-3-dhowells@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230522205744.2825689-3-dhowells@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Mon, May 22, 2023 at 09:57:40PM +0100, David Howells wrote: > Fix bio_flagged() so that multiple instances of it, such as: > > if (bio_flagged(bio, BIO_PAGE_REFFED) || > bio_flagged(bio, BIO_PAGE_PINNED)) > > can be combined by the gcc optimiser into a single test in assembly > (arguably, this is a compiler optimisation issue[1]). > > The missed optimisation stems from bio_flagged() comparing the result of > the bitwise-AND to zero. This results in an out-of-line bio_release_page() > being compiled to something like: > > <+0>: mov 0x14(%rdi),%eax > <+3>: test $0x1,%al > <+5>: jne 0xffffffff816dac53 > <+7>: test $0x2,%al > <+9>: je 0xffffffff816dac5c > <+11>: movzbl %sil,%esi > <+15>: jmp 0xffffffff816daba1 <__bio_release_pages> > <+20>: jmp 0xffffffff81d0b800 <__x86_return_thunk> > > However, the test is superfluous as the return type is bool. Removing it > results in: > > <+0>: testb $0x3,0x14(%rdi) > <+4>: je 0xffffffff816e4af4 > <+6>: movzbl %sil,%esi > <+10>: jmp 0xffffffff816dab7c <__bio_release_pages> > <+15>: jmp 0xffffffff81d0b7c0 <__x86_return_thunk> > > instead. > > Also, the MOVZBL instruction looks unnecessary[2] - I think it's just > 're-booling' the mark_dirty parameter. > > Signed-off-by: David Howells > Reviewed-by: Christoph Hellwig > Reviewed-by: John Hubbard > cc: Jens Axboe > cc: linux-block@vger.kernel.org > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108370 [1] > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108371 [2] > Link: https://lore.kernel.org/r/167391056756.2311931.356007731815807265.stgit@warthog.procyon.org.uk/ # v6 > --- Reviewed-by: Christian Brauner