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: 13131884 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 ADA04C636CC for ; Tue, 7 Feb 2023 17:13:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4048E8E0002; Tue, 7 Feb 2023 12:13:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 38CAF8E0001; Tue, 7 Feb 2023 12:13:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 256168E0002; Tue, 7 Feb 2023 12:13:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0305B8E0001 for ; Tue, 7 Feb 2023 12:13:35 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C96E0140A5F for ; Tue, 7 Feb 2023 17:13:34 +0000 (UTC) X-FDA: 80441142348.09.671CCA5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 0B4C9140012 for ; Tue, 7 Feb 2023 17:13:32 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OXjFoh9n; spf=pass (imf09.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=1675790013; a=rsa-sha256; cv=none; b=by0KY0Ug/WpGzuA7FN3wzQxATuK/1gIZdEJW9JNckqkISp5FNrZNWZ2N2m1YhzOiDkgMxv UtgO43JRIABIA17qimrqdV6wgRvC44uBaxBAxZD9GoGWzPmjIyFIg18I7HqziMQutIrtcW TeHY525CpSmzWFvr5GlpX3c1AHKVbDc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OXjFoh9n; spf=pass (imf09.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=1675790013; 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=8Bt0E9inDJohaZLhFSXlVRRQOAHhg5lVampuG5wXNsb/ZdOLKY9Th+5lWcdVYlNyqFfvfe XDsXyyt9iE0Vz2FwOOlvDBmBpCxO8dLWIJDPt381GIkH/zRwi8j2ASoNxXk1N3pshG39cS p4RChGMVlE34AkplkplrL8jEekpIyZA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675790012; 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=OXjFoh9nvkJWzn2s3f36/MBW66MoMQyLFuYUtYqK5YeAjPn45CRUQ6e/sIZc36xi2agvRg OrEtyDiYa4YhJP0UhmzNVoWJysZvzWbKSw6dQLEl84+uY+Tcy+iZDGTeOddk2s2pCkLYYn 9m2UGDspFkd2ayhfDslzIktjS90K/y4= 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-Rspam-User: X-Rspamd-Queue-Id: 0B4C9140012 X-Rspamd-Server: rspam01 X-Stat-Signature: 5opdnbt61ksi1iqu3g9i5yjmy1qsa6iw X-HE-Tag: 1675790012-483426 X-HE-Meta: U2FsdGVkX19YwP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Tkfa5dESvqYIvGBeeN7Yf5d2MQGzEnl5hzRHGnDSdVGaTcMKba+glxp+SbPsakF6w0g5XhCWP/fmQUhUVhuTrLVURW8Wwkv98UPqLX9c5ee2kb+Lo3uNZa1NYSXzfwacUuXe18SYNrRCSBpTiqNgjJ/IezjzswHbjJSgDMoOJljlQrRr9p2gQalzsQEU4RBEPF2dvHTjHt/kEUNRs2U1ciuvHVE2yGch1pQGhmKnizvqO2PwNeQVLpdcjdmK8XxSUHyUmhcgED1TB+mDFumSa1eC11f9PHNeMNuBgirTImsjPtEfHqpRfQrE2A1biYxagOLPt9mtUGJvOczNp4J1AdDH1/OucQ9kEC3wvcYDUwkgCec 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)