From patchwork Wed Mar 8 16:52:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13166167 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 706D0C6FD1E for ; Wed, 8 Mar 2023 16:53:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 443EA6B0080; Wed, 8 Mar 2023 11:53:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CCC6280005; Wed, 8 Mar 2023 11:53:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21F286B0083; Wed, 8 Mar 2023 11:53:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0A9AF6B0080 for ; Wed, 8 Mar 2023 11:53:34 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DD81FA30B5 for ; Wed, 8 Mar 2023 16:53:33 +0000 (UTC) X-FDA: 80546327106.22.2CFA19E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 2B31418001F for ; Wed, 8 Mar 2023 16:53:31 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cgaoeWDA; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1678294412; a=rsa-sha256; cv=none; b=K/lsPWAPlGK826EVrJ1waXp1InyylpQZy9KTrs3M/4UDN6LU3XTI+y8QekNKgySrqGdasV xmmEAd8Nf+JWqz5u1hYDT4Ehq0jQWZTZa9i4bx2wRbnKLLJJZbaVlwFj87PDmVFRlG0VLg ovrznds9evoIUoLB9r88b6fpeHQbkFc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cgaoeWDA; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1678294412; 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=0+QymJ+GCZW28tJ8JK9HTXv9GxubpscA9882LeMgv9w=; b=2fpYjV8Xr3/p1031cpdS16N/n4XeRBbfSuYshdTLjdaut8eMVD50qIB0vvlVPkzlAzHyrQ re6f6XQQPeZiOaYUPuQtC1jiki2G0HiLRF72ELghVw2V8SO3rY9GtbHg26m34JkL1RIWGE WdyQpJ3DJYN1swpzSMfGDPuX+IUyNAE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678294411; 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=cgaoeWDA4GLtYnWKdXmE89cDwJGZvbmzo2xBJLx+bLIoqJvxpSum8duznH7Io5cyC5FGZO MEGDEGdkvuA6NFqFiY9wZyyEgoRNrhJjs5RRV15o5Gb5qfI7ypTXn5lEN3Gaq5k9t1o2gc 9zkiri3K1tzue68Koxg0Lyns0RmioMU= 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-581-t3_NrMduOtmhP4jO257PkQ-1; Wed, 08 Mar 2023 11:53:28 -0500 X-MC-Unique: t3_NrMduOtmhP4jO257PkQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32CB7811E9C; Wed, 8 Mar 2023 16:53:27 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B99618EC7; Wed, 8 Mar 2023 16:53:25 +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 , 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 v17 10/14] block: Fix bio_flagged() so that gcc can better optimise it Date: Wed, 8 Mar 2023 16:52:47 +0000 Message-Id: <20230308165251.2078898-11-dhowells@redhat.com> In-Reply-To: <20230308165251.2078898-1-dhowells@redhat.com> References: <20230308165251.2078898-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Queue-Id: 2B31418001F X-Rspamd-Server: rspam01 X-Stat-Signature: y5cnfismzwbkaucji6zz3dbi4ya6zp13 X-HE-Tag: 1678294411-674171 X-HE-Meta: U2FsdGVkX18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J4kpumUj85H4EkEmSuEzpoGBEomAYPWvSiwKT5+SgySurdxEufWCko5gOfpLuYcRD45PcUeNof79ooYqV4XoZoe2bRCh1pBxLWYTGd6RZxx/0P/P+IrP9PYCqozeLlwuWT7uyCRL5gc/kHla0PVOhpfFj7+1qlxs/l7qPbXDM9aD6MIjkoSVIsRNt3XNOFV7/DGvjMUEvLn177fWFIsHK+bA4rVACSXCxMGRLljcjlLx9w5+6TuUWvVZO8a8m2koZ23sEGAcVFqu7lH6Dp6VvL/6FZbnGEumG+jZAhe327JCIas7eEDRwEbAOcm1b29y+hMOpaQktrea394NiNNyCJ5VEwjK8nwQuJvjy1BNPc2Xo8ZedAhor9yG6CK4YNrM8= 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 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)