From patchwork Fri May 19 07:40:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247783 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 27346C77B7A for ; Fri, 19 May 2023 07:42:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0EFF280003; Fri, 19 May 2023 03:42:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A744C280001; Fri, 19 May 2023 03:42:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82747280003; Fri, 19 May 2023 03:42:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 70A29280001 for ; Fri, 19 May 2023 03:42:42 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5339880991 for ; Fri, 19 May 2023 07:42:42 +0000 (UTC) X-FDA: 80806212564.14.15575C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 8E20518000F for ; Fri, 19 May 2023 07:42:40 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gdaDYS6F; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1684482160; 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=edStQDA/gh3f03KMzWRlpjb2e/gxKf5/7u3ht9bl6/4=; b=Wp0yKMaKZggAfT0fZmDr8Ish0sOPANaN8dM2VXsS1Wy9JWKQsfhyRmXDdTP2jMsEh1vevB acBp9ipXi2g73t0WMIxY2LaWxEDoj7p91x49ncF1jo/q4H2uamyLn+mBZy5HJDNHWlVTbE XIp4An/3vh4yfAAudHz4X+dErCvVDC8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gdaDYS6F; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1684482160; a=rsa-sha256; cv=none; b=3cd+WMWdfWBVPjM8fyVZiedqDA8Cy1Zqtcqcc2Edo5Ja5XgzJ+FBhjsv7DEoG5TgNhtKeI x44lwIaRrPsWl/CvGD0eEy3NEXho5h82kD+CTTPCkZKDD5tD/8iKxzeq789uXN9wDi+9Fi n/mbBqPp1Vq8CaAoiUbBdI+a0U/7IjQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482159; 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=edStQDA/gh3f03KMzWRlpjb2e/gxKf5/7u3ht9bl6/4=; b=gdaDYS6FFkw6F3YB4HIVdAp/+jefoPf8tqBAHV/C8htfAr9q5M+KM6bKv0co2bIWb7pbLI upNJ8chTvAjZKFqp0SWDbXFTfVQmhP/QypT9rkGwLs8/0dyV2CJfPNe8WeSo/M6p6/tehb kXt5bnM8W0zhbFfyqncLr/OQtwJi/vg= 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-558-Zn02uDUqNWychxCT98RFHQ-1; Fri, 19 May 2023 03:42:36 -0400 X-MC-Unique: Zn02uDUqNWychxCT98RFHQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 654BA101A531; Fri, 19 May 2023 07:42:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 468A240CFD46; Fri, 19 May 2023 07:42:33 +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 v20 28/32] block: Fix bio_flagged() so that gcc can better optimise it Date: Fri, 19 May 2023 08:40:43 +0100 Message-Id: <20230519074047.1739879-29-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Stat-Signature: jijr4wcfgd5iz4ip3j8e3zr54tnsbiug X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8E20518000F X-HE-Tag: 1684482160-698889 X-HE-Meta: U2FsdGVkX18kugZyfnof2d5YiVCNv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DHciVPn41OnBiz6Qx9GWf/iEwrEpvun+F+k+A50RfRWEVmdwH90bOJCqJJhmIekkFe+iPPWeDx4KNM6FO+rwt4vxPR60N0ezhlMl3dsb2e5bGgHzc82EBHAfBcbR4fZIcnR260J9dAm3/dk3GFPJxFyU3kLF2Cka5aQV7LMfl0V6ovLoixxgBNGRK3wKuDjVEYHS1pOxyMnI5bb3aimc7q6cYLY4t2pdP1pd7QJAJq89OcqCB+8L84GkWvZYRcMcg/4ik/498zfEbrKIx2HFdCOIiHHRK8fs40KyVRNSg2iockXvUW02+1CNZWw1SjY6oHIZnt+7X93JwFsmc/8+XeJ0xeh5gUXcyfOGfGh1duM55w== 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 b3e7529ff55e..7f53be035cf0 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)