From patchwork Wed Jan 25 21:06: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: 13116174 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89F9AC54EED for ; Wed, 25 Jan 2023 21:07:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 256936B007D; Wed, 25 Jan 2023 16:07:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 206376B007E; Wed, 25 Jan 2023 16:07:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A93F6B0080; Wed, 25 Jan 2023 16:07:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F0DC56B007D for ; Wed, 25 Jan 2023 16:07:21 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C7AC01C66D5 for ; Wed, 25 Jan 2023 21:07:21 +0000 (UTC) X-FDA: 80394557082.16.BAABEC8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 19E6180023 for ; Wed, 25 Jan 2023 21:07:19 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cfN0jHQ0; spf=pass (imf02.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674680840; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9PNg3WPaFWzxoLjSof2qU8psox3R+qpqOMDOMyjiLi8=; b=RvFeW8uvaqmwIucarZTgPbQ9tlye7zkEk0f/Jx+FlDrTUobt0ILheFxz9c85cPKEjyq0/P ghDHPIYW2xJUwhAsrm8rJFNRnqzPj8tculbPgVXrI/dgk3gE2a9kE9nz/giRGdICpjD7U+ 52O8rpkYVft+BFNRRU1dda/GTnigMJI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cfN0jHQ0; spf=pass (imf02.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674680840; a=rsa-sha256; cv=none; b=PK7RQczQ9csqhk4Hkt3bs4ulseDGMBG0TjL9LBKKOa58fotBJDNAzikOhy0pLRycKmXHDy hB0K+vVBOTJV+Vb4FJVvoj+K0XF2otyMLPmwpmReLZM0y+f3nalibMzgNhUSozhdM9qrZc SdboFJOIcnlh+tJHTO9TFVj6YbNmygY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674680839; 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=cfN0jHQ0zrb6l1JIzQNI+SzrfqRXsDwYizeD1ryfsLegNywyEJcuMHA1ia3sirnlhvDBFj HE5e67O65lpwk2AlOeH9TRA0MgAUlfTfHvgn9FspaG3joKEuDp+XenFQNqv5sAFsfMY5mD T/h/7uAAkc3hgw9d3toCntGeE0e9nF4= 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-570-EUx7EZNBM3WJWvkpN3fCVw-1; Wed, 25 Jan 2023 16:07:15 -0500 X-MC-Unique: EUx7EZNBM3WJWvkpN3fCVw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6EBF73C22744; Wed, 25 Jan 2023 21:07:14 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67530492C14; Wed, 25 Jan 2023 21:07:12 +0000 (UTC) From: David Howells To: Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jens Axboe , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , 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 v10 4/8] block: Fix bio_flagged() so that gcc can better optimise it Date: Wed, 25 Jan 2023 21:06:53 +0000 Message-Id: <20230125210657.2335748-5-dhowells@redhat.com> In-Reply-To: <20230125210657.2335748-1-dhowells@redhat.com> References: <20230125210657.2335748-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 19E6180023 X-Rspam-User: X-Stat-Signature: hkjj5a4ch4aikced46qxnsmgkkxpp6qo X-HE-Tag: 1674680839-667641 X-HE-Meta: U2FsdGVkX1/w4icv+cszkfb6n7PCTw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O++UE8UHag1MjHu1RZzxBq1TMvs9TrbOrh9jAenB6p7kwZahqVKSrp96lNxb4mNYGT5OQHwD76wu6Zoy6TuIJa75pdOMuKPSrv/N+elS0qiSHwOOFrmrwQ5VdupmMZ1k/Hp+KLWvoeIVrm3K4nmE+hsFS/lEAD+TlqEy1P5zGU+oYz/Er2CRrTTB5f5A0JRrl9AFOrLHX15oarpm3HXkbi/hGqAs7XPMr5vRuF8K0PqRorev2PWjvtBXmr0+iifUXtL7pcmhrMlGKh/Z8dKzv12hfvFKRFWO3DW1WrZJWbFLAYZ0ytnC8pzX1l5ECJ1bgELLHtU7WkA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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)