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: 97621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1722887vqo; Mon, 22 May 2023 14:14:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7FQCX5vy2Yr4S8fJRrVvHlBZr+qlkL5AVjbUxcM9aRGflH+RmTeneVdDvqjoM2KSYnxmr3 X-Received: by 2002:a17:903:11c7:b0:1ac:8717:d436 with SMTP id q7-20020a17090311c700b001ac8717d436mr13851864plh.60.1684790049299; Mon, 22 May 2023 14:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684790049; cv=none; d=google.com; s=arc-20160816; b=BrsPS+7O3586u0FGlkIi6KIM0SPy6eUHFvyscktA6KpOSKV64rlKeDN1ujA69ukcTB Sufh/7D7EoSLHg6UHTCov3PRuLlve8MK2EEZFWib47bG8YIPF3RMYu8VHmVTtfJBdOE7 KQrsijitqrd8EeHspIpF6hAmGRFf+GvA3fFxTritJdH8X2TNJhWt4ihgoiKlGRkeQvMy VrlQDyL5owKg6hHXgSkU++rZ+ITQVpZeE8X8x7j1VB5cHKnw6+Ki/LHRVJzTVztdOcFi W8qcTAr3Vl8Mi4ZWE33SX/ZYGh3/4As50rZ7Gd/5yNCukst04v97gwT0CJdoAZAxDHxF 6+Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=edStQDA/gh3f03KMzWRlpjb2e/gxKf5/7u3ht9bl6/4=; b=mCxQKgfqZa+KTmHbpLJzaafBFT0TZxIRFqliM2XwV64+oON5z3YyS9U/w8C88sK9IR FlPH6GeNJUAMH6EFAhlTtvF7iNUBuXZ1G1mTGKroWoAtR2w+yTpshLEhuefuhnCJKy6o 77l607R3R6jZfzlHrI2zf2Q09XEBGmk+47+GFMxwemAs1FeyzVVjgZZ0MvsrwYp9x32x LtDduoKbuTI6Mvobqh4EEK5s7XUBhfwHZpuzO9u46Tv08yvrEErCE+Cm21P39U095UVv F1AoASxyOiUE5UlIRs8FHBnz5EC+Kbo9GI8QeF/ue1bd36vOtjvN4GISloqxpJq/5Yxe Gz9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f03ZF8rH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170903120f00b001ac813bbfb4si5233570plh.203.2023.05.22.14.13.57; Mon, 22 May 2023 14:14:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f03ZF8rH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232442AbjEVU7A (ORCPT + 99 others); Mon, 22 May 2023 16:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235100AbjEVU6r (ORCPT ); Mon, 22 May 2023 16:58:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0101C4 for ; Mon, 22 May 2023 13:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789079; 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=f03ZF8rHtp1uumre1QtCJlDs+snBbhU3y9gJtM7g3A+QWdKLLVVF29SrmwIJv9uvOnEg7x tYXFH4D+kDgSG6pK9zzlU7Ctl49T4Vw0eGCovkHoZMFXUJ5HGLk5oLq/2Lcmk2TOFczomO 7dxDH1ByXO9+Fy+1YBN4iOUPHm/DZyI= 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766630411111567360?= X-GMAIL-MSGID: =?utf-8?q?1766630411111567360?= 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)