From patchwork Thu Jan 26 14:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13117195 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 73ED6C54E94 for ; Thu, 26 Jan 2023 14:16:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1749B6B0078; Thu, 26 Jan 2023 09:16:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 124FF8E0001; Thu, 26 Jan 2023 09:16:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F079B6B007D; Thu, 26 Jan 2023 09:16:51 -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 E27E06B0078 for ; Thu, 26 Jan 2023 09:16:51 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9B07940CF7 for ; Thu, 26 Jan 2023 14:16:51 +0000 (UTC) X-FDA: 80397151422.13.32708A1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id DF9E840013 for ; Thu, 26 Jan 2023 14:16:48 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="YADvt9l/"; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1674742608; 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=H6WOtGjsn2aez7ttVp7/Gslbr79b6juUusL2rHFqO3TvBIsevbSpiDWXWM28On5HaeiKIA dW5tcbz6sKP4zK2u1L+NmBfYNX7Kv0tmxsVvVwrvlvx8RiXHj/OjFrIKRSnpqgRqwibDRO I0+Dr5xX5+SeEWBhvua8lQ9DQGj0oSE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="YADvt9l/"; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1674742608; a=rsa-sha256; cv=none; b=64JqN8WpQDPJY0P5CuWvbnOpvaZbnM2rfNfRe5PXRzWAHyyZM98PdeUC4IBlVd2SuDhhNw nbKrX2/IYsJXGZCNk+eqgrXM7cSMg8l9DTZ2fORdVImUIxeqz3rEnr6pG7BjtN4NZqTyKp /eDH3PJvxWNK6kZiBoiMlgbgL1I9XG4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674742608; 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=YADvt9l/TC3vAJPKaNcfrWVumeZ93LNJfKTlOnUTikwOuhAHdUvMVxYLD+q6OCcbzWdIOV NkKQ85fSDazyWnifJB3LFwlkBYl+NH4zr4V4mQnFJC4xwjoEE235eebJ2a5JE3B+9iAJvT 49pHoTa8CGLK4aiiEF3te8674m962i4= 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-632-TDWE-n9FPgCznZ4yl1rJMA-1; Thu, 26 Jan 2023 09:16:44 -0500 X-MC-Unique: TDWE-n9FPgCznZ4yl1rJMA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3DD3857F82; Thu, 26 Jan 2023 14:16:43 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C432D2026D4B; Thu, 26 Jan 2023 14:16:41 +0000 (UTC) From: David Howells To: Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jens Axboe , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , 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 v11 4/8] block: Fix bio_flagged() so that gcc can better optimise it Date: Thu, 26 Jan 2023 14:16:22 +0000 Message-Id: <20230126141626.2809643-5-dhowells@redhat.com> In-Reply-To: <20230126141626.2809643-1-dhowells@redhat.com> References: <20230126141626.2809643-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Stat-Signature: p33khu35jri349ug8qeh9zizdmxe37xq X-Rspam-User: X-Rspamd-Queue-Id: DF9E840013 X-Rspamd-Server: rspam06 X-HE-Tag: 1674742608-451937 X-HE-Meta: U2FsdGVkX19QGcBzB0SE1eKK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ISkGZZhm90VNzcYpGgzZtGkfcipsSUkj/MJK6PQ2Jqb/CrYXXNFpKNVl1kZoA7gVoqisiI5nzvympSQljTxIAQ8j1vptUldn0C9bwGsbiffYnO7M3coL7wrWbm+6rMyJ3dvQgatclruQ3JbLUK2pJk+42JJgwRYLt/ofORv+6yhXrwX/M2/dMzwz2UgldobxOSkAY8e36Aro6Vho2AdHSq4fBjUbxyaS/yFpocbsacW9QHjzLob1jnmM8PqhtUvZ7RyGOh/p46ZThEfmNNfWtCdGz0/pFdtoy9cM6oxTmK+OxpVPH5vUYg0hNfb0ewxwVF3NU+rqVu0R7Rg 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)