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: 13175054 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 38E77C76195 for ; Tue, 14 Mar 2023 22:08:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87578E000C; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9C0A8E000B; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C52B8E000C; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 83E398E000B for ; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 61A4740739 for ; Tue, 14 Mar 2023 22:08:46 +0000 (UTC) X-FDA: 80568894252.28.36DC034 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id AC1F780011 for ; Tue, 14 Mar 2023 22:08:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QX/VJIgu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678831724; 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=DvzTowaB0L6uwPv7n20vdUNEGVX8RHFti2LhKhOYcWjGHMMAbulkwpPHm23bhxmXvSp8um 87Zk/9YcUeEekqz4Rswj91Hw22MasTqvBga9xlNXguKUxTIXK2q+ZYjBvZpaM7H5YeQD4P SWBHAKyQlN2cFpsKRv8wbEQOuX5I6nk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QX/VJIgu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678831724; a=rsa-sha256; cv=none; b=KFczbCLNYbn0HOJ+4RqbwV/TTZm6XjQCA3zjJdgaqXaGM3iNQA/PRvkCodJKTGDMJ6dKFP n/Z3RbNUL8/6AUx/abLGNosUbHLva/TSUbmREa1AxLWFALHq2xI/vSF5ryqHugJBz1ioBe exeVW9XZJquo9+Ab9P57PHw0dX/Cm5o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831724; 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=QX/VJIgulNoojTu5UAIXOZ1OgNai1qAq/9n6c+mTK7Z5XZWd5vvC0qhA3r9GgeDDCtQUtq bcuQ9f+DJ5OU5O2bOI7aWfL5elSn69HpnEXOKc+Jt1Ly7A4myiKuKhC1YIaFiL44ktc1k8 XF2aeWq0JFmHqgAq1lras657KAnn4tk= 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-Rspamd-Queue-Id: AC1F780011 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 86un5o1isubj3kr9ra8t3fi37ek7qqpc X-HE-Tag: 1678831724-548372 X-HE-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PJtnWRFyIz1HZcCqSeyNd2/7U8SxLzN07iTTZm6AM1fQfZ3xGGpfNFScv06TzHcOvidtLTgezSVnWkjBTuPlRTk8FHcYZkseikphAPxAmzijJSgH3M0JHnO4rj6j63RQXI/3+riCNlLIIGaYe6FKdFDoJPsSm0m2TDIyvgEPzSm3ykSJ+xwsRUjLgBNr8j/Px/8ZBe6WNqAkjnizGwxfybuCDIpVOhXnko/7Y6HTP61ttZmWyLq2P+SjU1RRPvvvOsEsg0499zNPGnJ8G8OD+8Thx2kMmNUbbxSurDiZi3nLGLL2kfek0OAgEVpnFOV4tBvkqAsMJMcsnFYyQCS6Gg5/23sLEe999irsH9i6InW8RA/NddHJjJ3OIeBagam4lOfeqCRFRkHpA0= 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)