From patchwork Tue Feb 7 17:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 54004 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2971009wrn; Tue, 7 Feb 2023 09:17:24 -0800 (PST) X-Google-Smtp-Source: AK7set/jMDQkpPb6MJ6XqOi9/xCsnAV8MiwA4bvIFKcOqx5eeUDiBvR/WDrBVg5ILZ7ZDVoLcqUB X-Received: by 2002:a62:31c1:0:b0:593:96a2:d60a with SMTP id x184-20020a6231c1000000b0059396a2d60amr3255993pfx.30.1675790243851; Tue, 07 Feb 2023 09:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675790243; cv=none; d=google.com; s=arc-20160816; b=AY4T2J7n/ion6+Q/TWvt3QzG5lXN2X6ZXZbiwgKtb/QM03pUjh1zeBSWvS276Vpuny /L3930aqdgdjZIgCTRUXWS3ek8O8rFVN3JQztO8uzj95xgdGzjs2DUOPl1EQRzoXt2O9 BKQEugqB/AuqA4/PJ49O4Rm5MNro5A0NJpoviZphJiw9JM7acsWSNG1QrktNvY15ZlGj eT4fSuywFIkTWGT9/06fuFv+OcgZ187WPos5NU8d7zUgyvQYNZmj8V6GNvnpKiR4OSE0 4fKgpoRX7+II6emx/mtvYIXJau4DpRq4e4q/IUKgVv6T2giJbCqsb71lmO4NLCW49O2O 2G7A== 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=9PNg3WPaFWzxoLjSof2qU8psox3R+qpqOMDOMyjiLi8=; b=lw3aug1B4c72KGHB2hM8R8exZZrIqhUGFgeVq/JoMv9FeEs8wX4MygBT2bVtsFHbr8 bDDrTC0qeXe/MoHpiyD7rxxGqdN+VsKQ4MyHam9E3u21GlLG+d80nR295dR5rT5RmE21 aI/lo2eGoEEMLDHNskcHEGf8KLfI5zyll1bp0WqMHGVOqbypx1Sax9j+0J1TjaUO4dRN sywlb1UdlsgP56ZQ7luXcj789eGfMW8b0afTxfwYoyxjm5e7J/64aRfZNS/JmftOAO3i oEaC/cE9h4ip447PGFb41FgsPhUBLO3Ze4UhAnN1xhKSaUOfFt0PF5YuGTaGSQTbHYWx 3XsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S1JnYf7u; 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 a17-20020a621a11000000b00591b0cab4f0si16052168pfa.0.2023.02.07.09.17.11; Tue, 07 Feb 2023 09:17:23 -0800 (PST) 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=S1JnYf7u; 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 S232356AbjBGRPn (ORCPT + 99 others); Tue, 7 Feb 2023 12:15:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbjBGRPZ (ORCPT ); Tue, 7 Feb 2023 12:15:25 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CF183D097 for ; Tue, 7 Feb 2023 09:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675790014; 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=9PNg3WPaFWzxoLjSof2qU8psox3R+qpqOMDOMyjiLi8=; b=S1JnYf7uGJstF627uN/4lAiRAy/JthDVok1Jk9KlcgFZ1WK7UsOrwmdpXImGvxKKbt87IA kk++VqE7wuMITHrqarDLZrVWVgCFu9qkEBIQTPbxrkgur17SvrlB4Q4na5HwOQ4PQENYLo mlJOpPKhzW+zDfzb0AbPkEV2qJEctA4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-83-P1yZu5qUNLmrLp6Co-SkqQ-1; Tue, 07 Feb 2023 12:13:29 -0500 X-MC-Unique: P1yZu5qUNLmrLp6Co-SkqQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C89E85A588; Tue, 7 Feb 2023 17:13:28 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4176F2166B29; Tue, 7 Feb 2023 17:13:26 +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 , 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 v12 06/10] block: Fix bio_flagged() so that gcc can better optimise it Date: Tue, 7 Feb 2023 17:13:01 +0000 Message-Id: <20230207171305.3716974-7-dhowells@redhat.com> In-Reply-To: <20230207171305.3716974-1-dhowells@redhat.com> References: <20230207171305.3716974-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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 autolearn=unavailable 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?1757193430471154516?= X-GMAIL-MSGID: =?utf-8?q?1757193430471154516?= 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 c1da63f6c808..10366b8bdb13 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -227,7 +227,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)