From patchwork Mon May 22 20:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13251117 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 276F1C77B73 for ; Mon, 22 May 2023 20:58:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7D686B0078; Mon, 22 May 2023 16:58:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2D466B007B; Mon, 22 May 2023 16:58:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F5A3900002; Mon, 22 May 2023 16:58:04 -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 8C3796B0078 for ; Mon, 22 May 2023 16:58:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 47DC21C6F56 for ; Mon, 22 May 2023 20:58:04 +0000 (UTC) X-FDA: 80819103288.10.9CA35A4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 753681C000C for ; Mon, 22 May 2023 20:58:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M9kQZpO2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1684789082; 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=uOBuyD6EbN7BXMJoYEZpbIWeXSYTynyxjHvf8/ZAgh+WkkA66ztk2yqCJIgg8OzC0s730W YmId3r+tsZ3XpIxyIZUitVid8dqlflQzCqSpvUpcdoT6lzfhdTwtiwkMILigZrIGswjTzl MxovzRJlQ7jOdTXR6w1dnkp7bAff3XI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M9kQZpO2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1684789082; a=rsa-sha256; cv=none; b=vM8GpgSuISLHf+BWcjCKqbze1xZXxArtYYbVO/b7C91EgfkPgV7wzgkLoHSSBHWanRNt0f CZND1s4jXr0HPE3MKxnzOogHkfYpeIespwujloihUoMVs8NUmNeoW/YY9RHFH5T+jfblRl B8y/DA8sEOBxJuvoVwpppQlvmN+c1S8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789081; 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=M9kQZpO2AJHw89knPq4JCKLG8P7bU1u1dJmMpoi9wgoSd9MXPu6EidYmN0yuCKpqIh32Gb zxoFlwocoKmBJeCk81LD/Yy5OGUam+aHEC2WrWvigsH3hWcOpQYPjLtBzdtZXjPMBv1dOM 2PvN3dWKHae9lpn7lFpSro28+3CvFsw= 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-610-M04EVDuVNPuz6Y2LP-abug-1; Mon, 22 May 2023 16:57:56 -0400 X-MC-Unique: M04EVDuVNPuz6Y2LP-abug-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82EB9185A78E; Mon, 22 May 2023 20:57:55 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A1CB1121314; Mon, 22 May 2023 20:57:52 +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 v21 2/6] block: Fix bio_flagged() so that gcc can better optimise it Date: Mon, 22 May 2023 21:57:40 +0100 Message-Id: <20230522205744.2825689-3-dhowells@redhat.com> In-Reply-To: <20230522205744.2825689-1-dhowells@redhat.com> References: <20230522205744.2825689-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Stat-Signature: fd1xkf9ecfeozwbn78r97pgyqcdx6wfu X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 753681C000C X-HE-Tag: 1684789082-788240 X-HE-Meta: U2FsdGVkX19M4EBBTRdyIKBOIasyLW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BTH0HDrfj2Rjcqxwqq8Q2Sq6AgVylF4rzKFf8/feLjjCrNAIVjtokU8MkhUGV5ppzsPMY9DHqUIZKChwejW69xWhub0kQ3DiBLCHXLzddvi50jKfRgEr15moCD6Zft4ryfjnFR0LRgt4qO1NMZc/X2KAc3eP0E5ezL08GxOF9PDrhFSWxSL00jr+Khig6UWaRkhDaW8HDSOY5ur1r8wSEb03l1OE23UV91neH+OPmwZ09OMZyZIuAS+NE1/tB8iMyeoaF/dDW34LzF0szhiEl4GQW2f7g4SNWx0vCIQAMdS8udERLqkFrrYdc+/TMmP0/LmjCMijyp5Duk5nxObJySpBq+EROVRg3b56oK0YT91Upzb+g== 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 Reviewed-by: Jan Kara Reviewed-by: Christian Brauner --- 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)