From patchwork Thu Feb 9 10:29: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: 13134345 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 5524AC61DA4 for ; Thu, 9 Feb 2023 10:30:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4641B6B007E; Thu, 9 Feb 2023 05:30:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 350A16B0080; Thu, 9 Feb 2023 05:30:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A5D26B0081; Thu, 9 Feb 2023 05:30:30 -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 F34B26B0080 for ; Thu, 9 Feb 2023 05:30:29 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C8E98C01A2 for ; Thu, 9 Feb 2023 10:30:29 +0000 (UTC) X-FDA: 80447384178.19.F29B4AA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id F2F3C12001C for ; Thu, 9 Feb 2023 10:30:27 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tbbc1PoH; spf=pass (imf29.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=1675938628; 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=4CDhjIxaDLDmTAXY+lGUvHk6M9Wo5wU7U2lPmyAkMToncxG89pMMhB6twhCfNhy49RZJui KQk3H0fkWFAcqJWgEq2se7wR8p3jFg6BjPFK4nCJwTTMhG+g2uuT+DN0MNkdo10x0AzsIP W9TpfrHN3MOuFMQiby6EXGPhO919+/k= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tbbc1PoH; spf=pass (imf29.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=1675938628; a=rsa-sha256; cv=none; b=DA4vzLfx9FK2pAyWQvTK69uwJW+gkwWCst/czaEfUWeScjG0s14SMMQs6n9V3OVbL2fRGm TPvUARCgvajGa920hVVWzIqlPRXD4h1uijLcye+2b5ykSp6e+2TEo6ofnTfRcoMgufVltV uTxQf7Rx/Ij3CPthcIyUAZoeWM8xcA8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675938627; 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=Tbbc1PoHGxkF3GCeCubs0Dpupx/xEhfrPFzcMmU2Q05Ec9NyFyfhDphGOZK4PHao1QaxzQ 1g+tvCeXfWj4zXCAMVzRVZ16kG74H9mQ+as+EqweocM8DHxYXStpSBvKpkng8AAq4zgRlk zZUvBB6JPJhBwFMxIQ8Dt3N4GveM4Kk= 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-557-B72h0Av4Pby1SBTw9mI3sg-1; Thu, 09 Feb 2023 05:30:23 -0500 X-MC-Unique: B72h0Av4Pby1SBTw9mI3sg-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 2ACFD832E70; Thu, 9 Feb 2023 10:30:20 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DD82C16022; Thu, 9 Feb 2023 10:30:18 +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 v13 08/12] block: Fix bio_flagged() so that gcc can better optimise it Date: Thu, 9 Feb 2023 10:29:50 +0000 Message-Id: <20230209102954.528942-9-dhowells@redhat.com> In-Reply-To: <20230209102954.528942-1-dhowells@redhat.com> References: <20230209102954.528942-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 8pfx99ztkob7nim1f7cyxoyni3uqnpsg X-Rspamd-Queue-Id: F2F3C12001C X-HE-Tag: 1675938627-781394 X-HE-Meta: U2FsdGVkX1+JW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OI7KYgM5t2f1F14ocC3AmY0aOqUJtCO48sxqGFxPYCd9B/iw6AsYByi59bLFOZe5wnWUAHhrWgH4CgNaBZ2DI2/ds54eBEEpeiQR6q8XWorWbIe+0Mmh+usEY7kUPLYx/moosAKHUEe0wXqugc7tpIoYo+hrU5UM3uc5mZcwZhpD3wOZKdAI0QYIEiAGzGpg3Tu03TVVoJdp+i426OIgU2hVJ3M3t2O4vRo12QMUXYA0A+5+eFOD2W5E5C8AUI+wdZSWSg2m7/g7hYlQoLQ1PRUMJyTspFEeysof16mGXdw51Tfx7nsPRFf2x8L/fR+jqxTBqROS6CEHzU3y4mOSnseShox 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)