From patchwork Tue Mar 14 22:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 69859 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2009586wrd; Tue, 14 Mar 2023 15:13:37 -0700 (PDT) X-Google-Smtp-Source: AK7set8WXx84AO4S2NEXOuxL5hrc1RFk1/gqR63aMizbtdpL6QwKGtXIbUDHvibRwGVcYb+uKPDR X-Received: by 2002:a17:90a:1913:b0:233:76bd:9faa with SMTP id 19-20020a17090a191300b0023376bd9faamr40999816pjg.47.1678832017220; Tue, 14 Mar 2023 15:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678832017; cv=none; d=google.com; s=arc-20160816; b=KGyNkaZoHR4hZruJIIK1oyYyDx416Tt3zi3ruqkkq7kq6EMVzpALJVH3SrMOXzZJ7b EhVFDUN1Ra5B45+cs7OuRm7H5S7ZKVpBFTUxPjIPCuvvRsA9DhN0gunsyGlUxIVb/84U t67C1+TlDDzGJRz83lD5REABCz+Y7yHIyqRd1uBMPLz+aA+PgBPEgOdkCVgW0wU6ThH2 FePSc61ZGa7qANjdtrQVlIGYVU6/+4m6wtoMiGWiOEm5nRTnDqI+ZuGT5IUBY+Jrtl98 PdDmNWoGCIYUK4S72XqaanyNMKeuZRAOGt1b0qgSSz0loVZhEppRFk64yl+efe3W/8hg hDyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0+QymJ+GCZW28tJ8JK9HTXv9GxubpscA9882LeMgv9w=; b=RmbF2uxPrb1gAiMxmuG40JoU1sDdedjUx8O5ANJPL8RvSoTF9SFqKxj+9A7aEudvWW 6rHsfAFDOiuGZcoAnbYPoAzjtQzNIt0mq5PwS4SjKGmt2z/MCkDoc3jNQqroSLlwxwwy MGWrCfvk6JCuFdxl+e6jtMhs1b8AD+rgzOavwpZ9HeUATPmAYR9JsVokpLaYyQIxLOzf xLp79JIgr06agVTDjg+EOZGgKGbyLtEEUPdGP3wGzD4zEQSdZShQbElutXCrypG88U5g pMlj+0EcKwjOP1sPw24Vxt/TrxNdKxmHPVudfu0rVNAiCBEr6+xbRy8MDZ1Ytn4W3h1k l5Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R4DPIoMM; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a17090a598600b0023d001665b3si3213473pji.144.2023.03.14.15.13.22; Tue, 14 Mar 2023 15:13:37 -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=@redhat.com header.s=mimecast20190719 header.b=R4DPIoMM; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbjCNWKV (ORCPT + 99 others); Tue, 14 Mar 2023 18:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229730AbjCNWJl (ORCPT ); Tue, 14 Mar 2023 18:09:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D592885E for ; Tue, 14 Mar 2023 15:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0+QymJ+GCZW28tJ8JK9HTXv9GxubpscA9882LeMgv9w=; b=R4DPIoMMJdtHq3Fq8tqDH20Nn4KnyRQMeqSTDr+drXH2CYu6mvzFmuNSrG0VCHbedwPZz6 tSXQtxlsRxQlPQFuX1koYBsVnu03X/kpoKKW55iJ1AK5m4tbbvBs9xwk31bL1PetC0IOTN 3/CQRBa3VTlAPmXb88qFxY3eWzs6JUQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-102-n0ZfiDmHMfGhrz83iRoe6A-1; Tue, 14 Mar 2023 18:08:40 -0400 X-MC-Unique: n0ZfiDmHMfGhrz83iRoe6A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E35971C08798; Tue, 14 Mar 2023 22:08:39 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CADA6C164E7; Tue, 14 Mar 2023 22:08:37 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , 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: [PATCH v18 11/15] block: Fix bio_flagged() so that gcc can better optimise it Date: Tue, 14 Mar 2023 22:07:53 +0000 Message-Id: <20230314220757.3827941-12-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760382961214471216?= X-GMAIL-MSGID: =?utf-8?q?1760382961214471216?= 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 --- include/linux/bio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index d766be7152e1..d9d6df62ea57 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -229,7 +229,7 @@ static inline void bio_cnt_set(struct bio *bio, unsigned int count) static inline bool bio_flagged(struct bio *bio, unsigned int bit) { - return (bio->bi_flags & (1U << bit)) != 0; + return bio->bi_flags & (1U << bit); } static inline void bio_set_flag(struct bio *bio, unsigned int bit)