From patchwork Wed Mar 8 14:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13165958 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 68ECFC678D5 for ; Wed, 8 Mar 2023 14:38:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03D0F6B0082; Wed, 8 Mar 2023 09:38:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F300D6B0083; Wed, 8 Mar 2023 09:38:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD0836B0085; Wed, 8 Mar 2023 09:38:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CF3916B0082 for ; Wed, 8 Mar 2023 09:38:38 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A2614C0928 for ; Wed, 8 Mar 2023 14:38:38 +0000 (UTC) X-FDA: 80545987116.23.C5CCB43 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id D943420012 for ; Wed, 8 Mar 2023 14:38:36 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="VU/7DXSR"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1678286316; 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=CFPrPUxQI/mBpidLY6T3r0/BBw6WY1EN/vkIWL5xYPrYUIUI3DvmzAVJU+OHowuWQRn7BA Yc+aoJbD3iLo31iKjEuWtpWOCHhihcJa/y4mDJfwTBJgex5tRXrCbcntSzJcLBb71RsE8h vRvAhaSXtloNNbWNAUzS9JvM9D8W8r8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="VU/7DXSR"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1678286316; a=rsa-sha256; cv=none; b=7me3RCc/vp5c/jjuPkJ9OCAtX58Yhk/HMydY7x8HTELa5QHlpDuIbdR2q+zD7ozOUFEj/9 hb4sqTOYNTgXHjVhX0XAYfOW+pFEYuD5FFlpMWeUIE1zK0CjO9TQqBGogU8AMlUsOPUj+A wd869ubwfjCN2DviNcvITICDXVL/Dm4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678286316; 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=VU/7DXSR3FdInzB59T4HXp+vfDM9KX55TPo2xoEW9TVoONigm98t+v0QELbEqPp+crhq1G fq31dLuABtBFo9cjQxBp1Gr83To2e5ykW1A0zQR1ZqTCEv8Hp7njH4ee9O9D8CUlxwsoYf fFz7OdwSu0McvZnfukO9sgn+yTdx7Xg= 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-522-MQY17EnwNZGepEkwDtQ80A-1; Wed, 08 Mar 2023 09:38:34 -0500 X-MC-Unique: MQY17EnwNZGepEkwDtQ80A-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 E96C0803D62; Wed, 8 Mar 2023 14:38:24 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA7C22166B2A; Wed, 8 Mar 2023 14:38:22 +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 v16 09/13] block: Fix bio_flagged() so that gcc can better optimise it Date: Wed, 8 Mar 2023 14:37:50 +0000 Message-Id: <20230308143754.1976726-10-dhowells@redhat.com> In-Reply-To: <20230308143754.1976726-1-dhowells@redhat.com> References: <20230308143754.1976726-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D943420012 X-Stat-Signature: 7fjr1f1sdma9jsdm6bx6qo4beiu4bp1h X-HE-Tag: 1678286316-239347 X-HE-Meta: U2FsdGVkX18+x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a5lGrckoREyqukQfOlQ4F171RRDd1tyLii7mjWm2fr2TkrYqPVL14LD/5JmDcbBdgsKTql/yDFVo6FhSMoUqBPStRX5jDauECiDgWyqBZ52GNyq99L+OVkFTCZgkdyb/9DEVbJyOpL2KkLk6Cg5Q3HtFMYEtDX8/tfjlaRa7X6qdyvsU94rnjHehOAwxfC5Bw10ypMzZbBfQUBAzsOp7f/XCwhREra7qY78om/NfOsYlQ9HOyIlkwjURzYic7Jw133RmyIC7r5V5L4uWS/Rb39q2YQx3/Fl0nAHHragvtxV54XOiwrx3ydnwB4k6pqufLsJO2HXqBd2pb6a4tfMNBep3m7dmnGSW6o+wQvJ7mkz7uPhhwgyTv7CBLOFzejDJo= 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)