Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4308819rwd; Tue, 23 May 2023 06:12:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cAfvVmYFPVLsZ57PKEQ2lGPaONF6EfKRDBspyfkUK3Hx5dt/tcrrK5cDZxeS36VSEp/2l X-Received: by 2002:a05:6a20:3c89:b0:10b:764b:a942 with SMTP id b9-20020a056a203c8900b0010b764ba942mr8210389pzj.11.1684847553584; Tue, 23 May 2023 06:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684847553; cv=none; d=google.com; s=arc-20160816; b=Sb3Ed1ZnzlY83HN1Re7aNe5dOE2ykQ2qdGyGMa2MdGha7u5ozblbd+WcqvTVVSwEqT 85J+mtFFPFL/BZxbTwy1sRg/8M3kKN5Z4bgGMhdBA+sIRd//9JhZvSng+stSdy11fMCV HOrYmzCj96F9Hb/AKVS+jrbVzhDjisDPasxsj4pho2V1+I2xAQ+STWKNQU0TDQ3P4Wk7 2iptYPMG5XI8PG3JQNj5P+7FuAriJ/i41zhJXPHMBRBD+DN3yfzrcwfZQUuNy3TeIlSh vrASP9tR/mUrp1XQlL0IQefwqbYYXmvynm6Gg6uIrKa5B6c+OkM9StTzGkE9jwwc++L5 PVzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LxWcbEmwvL8Zxjv+5B5BunQyBlwbF7mKdWYkCg6jhcc=; b=YU+lzlJeig+qUPYAX8nuhzXFeo9hko4rjK3Sb4uGvZt5VPTA+c8SJQhTc0H6AC83XN 0Vz8zwwtWK2f9EEcMwUSRez/xAj0PpH5ZyKi0aHBXqeG4vDe94ERRu37XPtuOTYZfs2p wK6lik2K0E6CTJj8dvUFdjtfa8s12goo79r/VjImv3fkbBuaKgaCXaiC6o1n2ZowyISe /wi6LRt18LQX/vGKY2NNgt4L46aBCdjCYh+6C83DOCvlxSdIfgtoyP79lTHen8VR0Y0r pjumFGo5QJC29Vz9oZzFxCwI94TgMa67PgPT2HjjzXbkHSECw6r/TTPkRUgrGjtOQdVz XU9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BbcPp5Wk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v135-20020a63618d000000b0053ee9b21820si1794383pgb.72.2023.05.23.06.12.18; Tue, 23 May 2023 06:12:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BbcPp5Wk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236900AbjEWMhq (ORCPT + 99 others); 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> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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