From patchwork Mon May 22 20:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13251116 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 0B36CC77B73 for ; Mon, 22 May 2023 20:58:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BFE86B0075; Mon, 22 May 2023 16:58:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86E456B0078; Mon, 22 May 2023 16:58:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 738E36B007B; Mon, 22 May 2023 16:58:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 624426B0075 for ; Mon, 22 May 2023 16:58:00 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2A7C6C045D for ; Mon, 22 May 2023 20:58:00 +0000 (UTC) X-FDA: 80819103120.13.B994CC5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 732BA12000C for ; Mon, 22 May 2023 20:57:58 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tv59qOQG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.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=1684789078; 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=oZIY9GTPXEPoSMZhe+ryqBhZXmHTyjPJq3hYdlaANCY=; b=e45che8iNX/Gu9I8uRLCKzX3BvE5B7TDofu1TAEoz9NQLTE1FxwNCvePE287p6leVphmcZ J4Nk6fpEYbuCVmmXuHPYsA1K97prNtHHnnZboaOdquym9O/ibh3oVjacK5M+CBYQVPtEOs TwPfGE+Hcw/o/vXccvD/RX0KepM8+Zs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tv59qOQG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.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=1684789078; a=rsa-sha256; cv=none; b=5Hsqk0bqKup+QmRt98KlvZvNHZ5jTTbDqdMYMbl3feO9NE9Zky8xuN39uE8JEHKILlMJo3 FBdM7aBRKFO7a/Xxr4oJQVC+F/fg6dliFX8xlYR3t0MolqB4o8uNT7pPVGwATrHWXFe3hH GxK3DwuGJarqyqENCv3voypxQPU8ZkU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789077; 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=oZIY9GTPXEPoSMZhe+ryqBhZXmHTyjPJq3hYdlaANCY=; b=Tv59qOQGJIDgUZMTyFz/1O4sMupQuCl6IcihYBouiTODv9NndTFMgqDF1jrqrmLok9v2Op LrlhhFtcyh8cxB/ohh9gJ2pX6Cul6JsmGbMaK8jzzZrs+ByiMrQExiNszBQVw7+44jaOQf uKK6RqI7oVSgrYSO+fY0kv4V7VU9B6Q= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-uxNl4WjbMQmkgPs6MbWOuQ-1; Mon, 22 May 2023 16:57:53 -0400 X-MC-Unique: uxNl4WjbMQmkgPs6MbWOuQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3732F28EC104; Mon, 22 May 2023 20:57:52 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B2D02166B25; Mon, 22 May 2023 20:57:49 +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, John Hubbard , Dave Chinner , Christoph Hellwig Subject: [PATCH v21 1/6] iomap: Don't get an reference on ZERO_PAGE for direct I/O block zeroing Date: Mon, 22 May 2023 21:57:39 +0100 Message-Id: <20230522205744.2825689-2-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.6 X-Rspamd-Queue-Id: 732BA12000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ttkk4jis3qodiw47n5mwyoshtmom6g7u X-HE-Tag: 1684789078-986838 X-HE-Me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DDnGzN9VbGNxASfZ/dLQUh/cAy6cCNQAjYULHMw0o3M6MZlwsOywbC1hOLM1qOP920p23x0TgCNzBbA6zr2s/S6Dg21GGRvOgw2fVTueEE1QHcNYVWOLLHow4y0nCo6+jmLGLuX8xdaVHn5N5+QaQn1wksYQs9PvYGsg/VgGCmZ59C1ciKsQMLbm91Zwze9f0+sl3DKTtnIPgCSOKhD/1w4acGNRBQYy3QMqCeD7fVzsLm74U9nwj0ac8zQHXbLYZREXYOWWZHjWeAcj2qCJWje5mMrRHMR 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: ZERO_PAGE can't go away, no need to hold an extra reference. Signed-off-by: David Howells Reviewed-by: David Hildenbrand Reviewed-by: John Hubbard Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig cc: Al Viro cc: linux-fsdevel@vger.kernel.org Reviewed-by: Jan Kara Reviewed-by: Christian Brauner --- fs/iomap/direct-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 019cc87d0fb3..66a9f10e3207 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -203,7 +203,7 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - get_page(page); + bio_set_flag(bio, BIO_NO_PAGE_REF); __bio_add_page(bio, page, len, 0); iomap_dio_submit_bio(iter, dio, bio, pos); } 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: U2FsdGVkX19M4EBBTRdyIKBOIasyLWM/4w2L4bGQ4QSxadEVuUt24/OKRpkdpA+vusIrKJQymyhnv0afsSENOs0q7+HnVTZqq1+/eeiLN1zsRNU1QL1qOiw9rjHaTGA1b+kbS4aHIVVrO9LHilvVAUPkU6ryMqjqYXrSQnHxJR8ddh+dkwKXcoSJNeXYorFvQmjRK7D8gP+cTw31ZBk4wbAIkmiLxkkMrivuZWsKfPTSG+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wSEb03l1OE23UV91neH+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) From patchwork Mon May 22 20:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13251118 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 4508BC7EE2A for ; Mon, 22 May 2023 20:58:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C92D96B007B; Mon, 22 May 2023 16:58:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1AC76B007D; Mon, 22 May 2023 16:58:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB913900002; Mon, 22 May 2023 16:58:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9A3566B007B for ; Mon, 22 May 2023 16:58:06 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6CF6E160216 for ; Mon, 22 May 2023 20:58:06 +0000 (UTC) X-FDA: 80819103372.29.07C6FC5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id B4A674000A for ; Mon, 22 May 2023 20:58:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ech9JQWv; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684789083; 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=TuE+HSvYodh9xYXD2lD0nf71BaZqaWOFZeqfoTjFcWg=; b=NdP1rqcZJ87TfHdocH5oZQPNOIukOLZxixuaEXYYnVzmUX+eSZj/nhMsZxWlyVYBsh5m25 bcss4D23Olh0pkUanmaMLX2vlSiC82y4OfkBYgn2eyvDv8UtN02oIV7JBjDdrXdynYz875 vunlijEgiZA9hepNJRyZHvjxIbjxBXc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ech9JQWv; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684789083; a=rsa-sha256; cv=none; b=m5qJ1efWSFAv02nLCd3iSItUIPQ510ZvzpTcasKB8hT9c8rtrHDd4ZkoUhgsYBrilctBwK qFgixYgu3OV4gCgKYo/9vIiwY2P7+a9P52E6A/Y2M7Rzx+9DYDZW8j2epr4CCUGl0dtyNn 1D1E6ndzgWBUWSkmd4r46EcddAQxyaw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789083; 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=TuE+HSvYodh9xYXD2lD0nf71BaZqaWOFZeqfoTjFcWg=; b=ech9JQWv7JbzKnfVTr9Rte5+twYcgsgGQpJTN/czFcSQSHdnjiyjVtz8eEyqXqU8z4njIB ApeSs7w/j0cRMB08glm/xEhdMr+JBbmOT30dmZpRnTVWKD/0QN5ou2PR/7fJ+8kMqTGmpj oWCGeOaTTd/ln4RQZBWkt993RAWlzfU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-193-4iF6x20XMxWuSAjOpQPW7g-1; Mon, 22 May 2023 16:57:59 -0400 X-MC-Unique: 4iF6x20XMxWuSAjOpQPW7g-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 A847F1C0150C; Mon, 22 May 2023 20:57:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38CE8C478DB; Mon, 22 May 2023 20:57:56 +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 3/6] block: Replace BIO_NO_PAGE_REF with BIO_PAGE_REFFED with inverted logic Date: Mon, 22 May 2023 21:57:41 +0100 Message-Id: <20230522205744.2825689-4-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.8 X-Rspamd-Queue-Id: B4A674000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5me61a7dntjhp4affd5awg3743y96nju X-HE-Tag: 1684789083-152647 X-HE-Meta: U2FsdGVkX1/2DkvfZu0DIOHTda/djDT5tLClLgszIUtRp+Re8F71rANpL/hB/TRyiw6BM598mMZsQxJLfVsj5JyJWOu9/eIocHAon6iQD+E/Gq97ItwUOobnyw6uy/IsirGhCtU0wJYJjrRNPN70TM6xjs7FoRLvHewaOLD0+pCjFtax43ULoElzxzHaZbMZVYy1BLe+Bwa+K1jtBi1ceYjcWf6fQKxkg6vWqxA81bsVIFQjct0qyoyUViTQQDhrCTcCs4fGKliReguIvaFHL6D/yyIOVmA2mgo6liNyNzIvH3AK7Qcf8j2vjHksOZx5uJj4QyQx2S4lX7EMZvXCmHApLpoVDHYYO6Ke3mvaqks11/Z8gJFGNo4EvaXAkj14pC7G63hd4NknoMxMpiXCtGpXJpbfRu/+rdPO+eSRaodJm+6WJK09XnLtgoKC3ZBTV1JP+XtYKtYwRl8tVBSuONzhq8VdaW8sFTySjP9mOY7hkEKT6rZnZZ8k+/a1NrDhXUTz+T0dEoBKyR/MrCFfZ7D2hId3SEPD8Ic6v2Rb+DVUR1r2CcsnR7jQB9KWr4N/+CIYKwRejYVmPF2zArZgInVSWoWlXy26JVtILGCwCo7XiiM8JecLN+/AKSOfK5VD55W/cCn2Qur66eMwo3v7U9ustvOiO3aoiAwF5+mAG+VlW1pcHax2CUVrWLFap9Z1SoUrSHDAv+96YJrropWpCKx2Um3ukBDkzcTC0XnXTgrOIKe1hWw7Snzd6S3/sTqTFf74yvBR+UQFnRFLbUYHTbRSJ5FuDXv6UPgGCIziwCaCcJAzkvwoJg6qcx5x8ruQDwnEv3dH5ehcAUFCUAgL1BytxS9u6Sh749KSHaPWZTZTMosGrH01DPGsW6Tx0VLue8qDHcXRpr4znK3gC9Yo7PGAkTFNpTYO28by6oJIO8omQVsMTFP/HQ/eej8PPWezj2c2HbiEm5YV04R2w+u u6X1x6pr KweMqtY3OAAjti6JtPbjqU8vbePBKavf7LUw8vek2vxgbSdCx48RYQfjcHDMFwM+ZlFsz8xa2dDtI4Oc4TZ+q88g391njO4X3JX2h2cN3t4MHf0nN/ZwVDIUoFeuT0eaF3Ju+37KRCY82/p4BCadXAd7aHAXAJwIEYCcEKNlul1eCUA4ZBACt3qQUsrIi4/522Ly/XnNWq1lZWxgulxcEm9cCe4JawLt9gjv9q60w0WCUvJOOgrX76hWgr3u8JsC94JTU6vw2lf/Wvb0m3PHFdGxcQbYZLYI1lyDbVUs/4wMxFjurvvg76S0m2EsBZmJio6by004RkEZglYWV6BvPIxKPQVBWFw7d2itV3cBy8bM0eRGhiaqn7dEAYdui9lH/3QbBV9wEq4hNHrJ3iSfLOkGZPRYtHhJ0fktJl/jeCvx69rtHA7cfEQ1ho/24VGjMgMmpCSCkm2Xw1r8MNsPuL4wC8NWb1uX3L+kL 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: From: Christoph Hellwig Replace BIO_NO_PAGE_REF with a BIO_PAGE_REFFED flag that has the inverted meaning is only set when a page reference has been acquired that needs to be released by bio_release_pages(). Signed-off-by: Christoph Hellwig Signed-off-by: David Howells Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org Reviewed-by: Jan Kara --- Notes: ver #8) - Split out from another patch [hch]. - Don't default to BIO_PAGE_REFFED [hch]. ver #5) - Split from patch that uses iov_iter_extract_pages(). block/bio.c | 2 +- block/blk-map.c | 1 + fs/direct-io.c | 2 ++ fs/iomap/direct-io.c | 1 - include/linux/bio.h | 2 +- include/linux/blk_types.h | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 043944fd46eb..8516adeaea26 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1191,7 +1191,6 @@ void bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter) bio->bi_io_vec = (struct bio_vec *)iter->bvec; bio->bi_iter.bi_bvec_done = iter->iov_offset; bio->bi_iter.bi_size = size; - bio_set_flag(bio, BIO_NO_PAGE_REF); bio_set_flag(bio, BIO_CLONED); } @@ -1336,6 +1335,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) return 0; } + bio_set_flag(bio, BIO_PAGE_REFFED); do { ret = __bio_iov_iter_get_pages(bio, iter); } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0)); diff --git a/block/blk-map.c b/block/blk-map.c index 04c55f1c492e..33d9f6e89ba6 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -282,6 +282,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; + bio_set_flag(bio, BIO_PAGE_REFFED); while (iov_iter_count(iter)) { struct page **pages, *stack_pages[UIO_FASTIOV]; ssize_t bytes; diff --git a/fs/direct-io.c b/fs/direct-io.c index 0b380bb8a81e..ad20f3428bab 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -402,6 +402,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, bio->bi_end_io = dio_bio_end_aio; else bio->bi_end_io = dio_bio_end_io; + /* for now require references for all pages */ + bio_set_flag(bio, BIO_PAGE_REFFED); sdio->bio = bio; sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; } diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 66a9f10e3207..08873f0627dd 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -203,7 +203,6 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - bio_set_flag(bio, BIO_NO_PAGE_REF); __bio_add_page(bio, page, len, 0); iomap_dio_submit_bio(iter, dio, bio, pos); } diff --git a/include/linux/bio.h b/include/linux/bio.h index 7f53be035cf0..0922729acd26 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -488,7 +488,7 @@ void zero_fill_bio(struct bio *bio); static inline void bio_release_pages(struct bio *bio, bool mark_dirty) { - if (!bio_flagged(bio, BIO_NO_PAGE_REF)) + if (bio_flagged(bio, BIO_PAGE_REFFED)) __bio_release_pages(bio, mark_dirty); } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 740afe80f297..dfd2c2cb909d 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -323,7 +323,7 @@ struct bio { * bio flags */ enum { - BIO_NO_PAGE_REF, /* don't put release vec pages */ + BIO_PAGE_REFFED, /* put pages in bio_release_pages() */ BIO_CLONED, /* doesn't own data */ BIO_BOUNCED, /* bio is a bounce bio */ BIO_QUIET, /* Make BIO Quiet */ From patchwork Mon May 22 20:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13251119 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 C9E8CC77B73 for ; Mon, 22 May 2023 20:58:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 589BC6B007D; Mon, 22 May 2023 16:58:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53A196B007E; Mon, 22 May 2023 16:58:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38C5B900002; Mon, 22 May 2023 16:58:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 26D006B007D for ; Mon, 22 May 2023 16:58:09 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 06184A0491 for ; Mon, 22 May 2023 20:58:09 +0000 (UTC) X-FDA: 80819103498.13.4CFFBF1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 41ABEC0009 for ; Mon, 22 May 2023 20:58:07 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SVcXfvMJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684789087; 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=xt8MS4tNW7WMUMs3pTsS0U26gIFNlNPWhaB+SXg4cNY=; b=qBv3eG4Gxwpp9lvdEBP40B7BI2ngFgwCBmR48BmKFYPOK8DB/CeKG9jA2B0pABOvGjTGQI /C1y+Ior3X4QPE4CuS4KIDPL994QH6S4eSFLJEBq8R/xCLWbkmM6SIBpcQM6JqsA09/1s+ nSemom3CaRNdeldMEdf038TjAXKCyr0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SVcXfvMJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684789087; a=rsa-sha256; cv=none; b=YjXOOuDmTtFAQknBv/BVTnDYLIC1YiBp9AXsVerVVZWH0nUJghESX8hpgxOkWp7/C+hjYM jgDMJvABNkXLhWBy5fBXG2wBjLik1MZuhtMaSKjAlsdz5iTZ0NG8nVeMy+dK0QlGuEEDt/ p2uqQKz77/yFPSz8+tLQ8SR72cdAiDk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789086; 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=xt8MS4tNW7WMUMs3pTsS0U26gIFNlNPWhaB+SXg4cNY=; b=SVcXfvMJjboQRg3u6w2idGYtBcrOlTq9/Aroxlhlt4/zzAAFL4u1ESBh9y2OMEsydlNnrs 7CDzq8gX4qENjJtM1tM3S8PT4PEk0dti+Sso5blH1SCgT7uGuIy2ju24hCBCUcCnMPfXzm hc7Tn4ZvI7YCc/su2dJ8RKM/XQVoiaI= 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-325-raSTpLIKOaCh0l3iPTbjyg-1; Mon, 22 May 2023 16:58:03 -0400 X-MC-Unique: raSTpLIKOaCh0l3iPTbjyg-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 3F811802E58; Mon, 22 May 2023 20:58:02 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83F4540CFD45; Mon, 22 May 2023 20:57:59 +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 4/6] block: Add BIO_PAGE_PINNED and associated infrastructure Date: Mon, 22 May 2023 21:57:42 +0100 Message-Id: <20230522205744.2825689-5-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.1 X-Rspam-User: X-Stat-Signature: cwehthwxgrbhd76xonipd6tygs5irbre X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 41ABEC0009 X-HE-Tag: 1684789087-294230 X-HE-Meta: U2FsdGVkX1+GtK2Xwj8/+t7495QxXTrPi4+y+/21+9ZIwYB0xQy89ErQq8Kb0M4c2iZDVc6SOKRGrRvkCh3uc5PLeeDNN4teQJl4Vcs5XJnMrTRjRnUgenlcaDBd0aJ60Ft3cg+ExOlNovwjNBb7I9euz1tNpjSVUpTSnQJOvJyk7CQQwgB1hyd23su37c3AgvK6MBa4bQNu4uVa7nE6o2Mfaug96GPNIsgKoSOd1FEy1OHfJdkuXvdvq4HrKMKFEwgiswgziXZW3Eon2Mf+Aj8EQ060S3u4Q5GPgbp5tnQXgUsa8WQuombwAfm6ndNHFqVVcJrpkKvO/KUttTWNuZK5SxGmzJLnX5aVVVk29s0W9YaFOmu9t/nsgOPvjgMF9WE3rUwhqapSPABHuZCQoGfkbLNE7IvO2MQF2n/ox+6YzJ8FhPnq9LCB5ZT7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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add BIO_PAGE_PINNED to indicate that the pages in a bio are pinned (FOLL_PIN) and that the pin will need removing. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org Reviewed-by: Jan Kara --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #9) - Only consider pinning in bio_set_cleanup_mode(). Ref'ing pages in struct bio is going away. - page_put_unpin() is removed; call unpin_user_page() and put_page() directly. - Use bio_release_page() in __bio_release_pages(). - BIO_PAGE_PINNED and BIO_PAGE_REFFED can't both be set, so use if-else when testing both of them. ver #8) - Move the infrastructure to clean up pinned pages to this patch [hch]. - Put BIO_PAGE_PINNED before BIO_PAGE_REFFED as the latter should probably be removed at some point. FOLL_PIN can then be renumbered first. block/bio.c | 6 +++--- block/blk.h | 12 ++++++++++++ include/linux/bio.h | 3 ++- include/linux/blk_types.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 8516adeaea26..17bd01ecde36 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1169,7 +1169,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty) bio_for_each_segment_all(bvec, bio, iter_all) { if (mark_dirty && !PageCompound(bvec->bv_page)) set_page_dirty_lock(bvec->bv_page); - put_page(bvec->bv_page); + bio_release_page(bio, bvec->bv_page); } } EXPORT_SYMBOL_GPL(__bio_release_pages); @@ -1489,8 +1489,8 @@ void bio_set_pages_dirty(struct bio *bio) * the BIO and re-dirty the pages in process context. * * It is expected that bio_check_pages_dirty() will wholly own the BIO from - * here on. It will run one put_page() against each page and will run one - * bio_put() against the BIO. + * here on. It will unpin each page and will run one bio_put() against the + * BIO. */ static void bio_dirty_fn(struct work_struct *work); diff --git a/block/blk.h b/block/blk.h index 45547bcf1119..e1ded2ccb3ca 100644 --- a/block/blk.h +++ b/block/blk.h @@ -420,6 +420,18 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset, unsigned int max_sectors, bool *same_page); +/* + * Clean up a page appropriately, where the page may be pinned, may have a + * ref taken on it or neither. + */ +static inline void bio_release_page(struct bio *bio, struct page *page) +{ + if (bio_flagged(bio, BIO_PAGE_PINNED)) + unpin_user_page(page); + else if (bio_flagged(bio, BIO_PAGE_REFFED)) + put_page(page); +} + struct request_queue *blk_alloc_queue(int node_id); int disk_scan_partitions(struct gendisk *disk, fmode_t mode); diff --git a/include/linux/bio.h b/include/linux/bio.h index 0922729acd26..8588bcfbc6ef 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -488,7 +488,8 @@ void zero_fill_bio(struct bio *bio); static inline void bio_release_pages(struct bio *bio, bool mark_dirty) { - if (bio_flagged(bio, BIO_PAGE_REFFED)) + if (bio_flagged(bio, BIO_PAGE_REFFED) || + bio_flagged(bio, BIO_PAGE_PINNED)) __bio_release_pages(bio, mark_dirty); } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index dfd2c2cb909d..8ef209e3aa96 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -323,6 +323,7 @@ struct bio { * bio flags */ enum { + BIO_PAGE_PINNED, /* Unpin pages in bio_release_pages() */ BIO_PAGE_REFFED, /* put pages in bio_release_pages() */ BIO_CLONED, /* doesn't own data */ BIO_BOUNCED, /* bio is a bounce bio */ From patchwork Mon May 22 20:57: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: 13251120 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 C1716C77B75 for ; Mon, 22 May 2023 20:58:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D79B6B007E; Mon, 22 May 2023 16:58:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 587D1900002; Mon, 22 May 2023 16:58:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 450256B0081; Mon, 22 May 2023 16:58:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 353166B007E for ; Mon, 22 May 2023 16:58:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 019A3802A0 for ; Mon, 22 May 2023 20:58:14 +0000 (UTC) X-FDA: 80819103750.12.38C5373 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 2A5EF20016 for ; Mon, 22 May 2023 20:58:11 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fDhO8fAh; spf=pass (imf03.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=1684789092; 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=ehlvfIu1rrXcuy8/PZvsT00k//DN+ilG0RL3yAJWLmk=; b=F7CovrmifQL/V7w+Q+EEByOr4co94LDZw2AERuLkGJTHKORnS44sI5O2sidT7sgDraEpiM QBJFWv7VXBS30jEhjXac8nAn0vvKR0wZhPv5AH74A8++n7Yfoe2cAB+1CRJwGQYjbDIUun tJuAhbqGgroFdpKExHHh1HDaVNTlsIE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684789092; a=rsa-sha256; cv=none; b=WsvnOl8a9bf9eATt+L1XNv/C/hFJhEJbWumjv/tHCq0sWzeAqPw+msAAATBNQKHiJRk0Dj Br+ViXU67trc4RmiKSKuqIeVib+Am1xK0iT+rNH4c3pr7eZTXYmHadTxYLdp75WhvxmoOu KMBUz2pk6Dm1xG3jRYiNGri/ba+K3os= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fDhO8fAh; spf=pass (imf03.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789091; 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=ehlvfIu1rrXcuy8/PZvsT00k//DN+ilG0RL3yAJWLmk=; b=fDhO8fAhBWVLJKHrkKPN9p4ZxiMH3402lZ/rlZIrXtDLGc5AnHQqbLp4Pq8u77Yr8F1Ftm dIiJfooPAd6ug1txbw5SsYw/iGPLVFa/xwdH+5z9Xp9NLf2vnfu9BdVNIA8Bt81FC13cli apaozsJlO/EAs+30Z72a3+whUzupUpY= 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-314-MKSAMsAkP0a73wRCpRgbJQ-1; Mon, 22 May 2023 16:58:07 -0400 X-MC-Unique: MKSAMsAkP0a73wRCpRgbJQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18D64800159; Mon, 22 May 2023 20:58:06 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id EECB5400DFF; Mon, 22 May 2023 20:58:02 +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 5/6] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Date: Mon, 22 May 2023 21:57:43 +0100 Message-Id: <20230522205744.2825689-6-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.9 X-Stat-Signature: ocho3gijjnpnfiyehp5irf193pcr3663 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2A5EF20016 X-Rspam-User: X-HE-Tag: 1684789091-282545 X-HE-Meta: U2FsdGVkX18nhjPsvgapEOhnxBpX4yYA2ikvzEwMHQG4JATl09u7j9eo7qrXg0ah/jDG2ssaq9dnj33dbmiuAvjMNJj6oSfuqgdQwGqdk0rX3o5kheBk1o/6snCPmxpA2ssixPNnlWEukFIhygjpf0BkaDXzK1q/gSgNRnJuPK8AkeH12ozM34trNseN+C/nOsSEupAPOYbnzRDxdWfwJNP1vSAWSW/Pd0Kp3SzJqhTVWD+ets9Uk20PVf7KDvRa673LqZabLPVzIChga7W8rFlCK7rItr1nyq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Z7GNyab//iz67IcLvk5CXFofcvq+N1GfjBzoVY34x8GvNnRdKBww2dKcVhZVWDtObjd90FHlZJFzL8OonGJQNXD+D2Nwo3Y7u8TZyEcQBwb0lA 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: This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O could otherwise end up being affected by/visible to the child process). Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org Reviewed-by: Jan Kara --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #8) - Split the patch up a bit [hch]. - We should only be using pinned/non-pinned pages and not ref'd pages, so adjust the comments appropriately. ver #7) - Don't treat BIO_PAGE_REFFED/PINNED as being the same as FOLL_GET/PIN. ver #5) - Transcribe the FOLL_* flags returned by iov_iter_extract_pages() to BIO_* flags and got rid of bi_cleanup_mode. - Replaced BIO_NO_PAGE_REF to BIO_PAGE_REFFED in the preceding patch. block/bio.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block/bio.c b/block/bio.c index 17bd01ecde36..798cc4cf3bd2 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1205,7 +1205,7 @@ static int bio_iov_add_page(struct bio *bio, struct page *page, } if (same_page) - put_page(page); + bio_release_page(bio, page); return 0; } @@ -1219,7 +1219,7 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, queue_max_zone_append_sectors(q), &same_page) != len) return -EINVAL; if (same_page) - put_page(page); + bio_release_page(bio, page); return 0; } @@ -1230,10 +1230,10 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, * @bio: bio to add pages to * @iter: iov iterator describing the region to be mapped * - * Pins pages from *iter and appends them to @bio's bvec array. The - * pages will have to be released using put_page() when done. - * For multi-segment *iter, this function only adds pages from the - * next non-empty segment of the iov iterator. + * Extracts pages from *iter and appends them to @bio's bvec array. The pages + * will have to be cleaned up in the way indicated by the BIO_PAGE_PINNED flag. + * For a multi-segment *iter, this function only adds pages from the next + * non-empty segment of the iov iterator. */ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { @@ -1265,9 +1265,9 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) * result to ensure the bio's total size is correct. The remainder of * the iov data will be picked up in the next bio iteration. */ - size = iov_iter_get_pages(iter, pages, - UINT_MAX - bio->bi_iter.bi_size, - nr_pages, &offset, extraction_flags); + size = iov_iter_extract_pages(iter, &pages, + UINT_MAX - bio->bi_iter.bi_size, + nr_pages, extraction_flags, &offset); if (unlikely(size <= 0)) return size ? size : -EFAULT; @@ -1300,7 +1300,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) iov_iter_revert(iter, left); out: while (i < nr_pages) - put_page(pages[i++]); + bio_release_page(bio, pages[i++]); return ret; } @@ -1335,7 +1335,8 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) return 0; } - bio_set_flag(bio, BIO_PAGE_REFFED); + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); do { ret = __bio_iov_iter_get_pages(bio, iter); } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0)); From patchwork Mon May 22 20:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13251121 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 E20F7C77B73 for ; Mon, 22 May 2023 20:58:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 785B26B0080; Mon, 22 May 2023 16:58:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E78C6B0081; Mon, 22 May 2023 16:58:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 588A76B0082; Mon, 22 May 2023 16:58:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4649C6B0080 for ; Mon, 22 May 2023 16:58:17 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2023B1204A6 for ; Mon, 22 May 2023 20:58:17 +0000 (UTC) X-FDA: 80819103834.22.A5C5389 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 66D28C0019 for ; Mon, 22 May 2023 20:58:15 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aDaJm41c; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.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=1684789095; 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=0UdxcT7QYPFwRvPO4h85pE794/0OGizygn6UovNdu60=; b=1/RtLkcmAmZ+hGsk4bN3uXIIN+4vpOVXqyOvyiaKxNMbfXO8i5HfKO5QKGh7e75aCLi+Kr tm8tcACnEEAokPpZjB1Im/5JsMyV+ls5+69q4N7zDmA0sX0nkeHu7/OX05ZCfey4uMIOFW fLPCA9Gh9TSoIVwChbzTKBIJeexJC08= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aDaJm41c; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.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=1684789095; a=rsa-sha256; cv=none; b=E14vavVAO3aAg/sMahJwWpz4s/5Umn86V+NXXf/uI1huBMV6oH5S3BdTeh4mtxo5yYt9v3 yTWXHO7Dc6eMphVKF3OK3MUaFQY0GTkmSpPLXjka4V9Hksz0YTzD35/qslkJEiygZqa390 xxWpFFqGrLgRut+hT9TJV+tZoeug4Vc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684789094; 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=0UdxcT7QYPFwRvPO4h85pE794/0OGizygn6UovNdu60=; b=aDaJm41cmeJpjZRQAz/zVXk6wrsAiPVopfRSd1dw4RtO5gCO+uNiKZzcRBKpVdyn/j8+nE 16e92ckzJlo2n9UMQaf0gCsYNeVwoDuTa+1C6bDogFORmMl/WrKfSIuoa5gVlbXIsdpaec XDV5myQBWwYPfOx76lNEzXM+YaxWYGU= 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-36-QHGrTEFvMROVinDkIKBxuA-1; Mon, 22 May 2023 16:58:10 -0400 X-MC-Unique: QHGrTEFvMROVinDkIKBxuA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 706D1800141; Mon, 22 May 2023 20:58:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E042D140E95D; Mon, 22 May 2023 20:58:06 +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 6/6] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Mon, 22 May 2023 21:57:44 +0100 Message-Id: <20230522205744.2825689-7-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.7 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 66D28C0019 X-Stat-Signature: r1wtacjbspa9b9zpoo5nqh81zdc4h4x4 X-HE-Tag: 1684789095-117210 X-HE-Meta: U2FsdGVkX1+QKRkSJ2cluUmxjrNpK6ulYhwltVYuiV90w3Z7Spu3rQcgBqTSLDaR3l4ZfqqIOtux9xg+LckNwHk/5VfElrtRak0vGNIEpicdQwQFED1xxv7aw+YAvaHEP3ON5IbT2BSi6pUxNc0B7RVAYrHstYJiSujqBKq8M0Df8vt/7RKIF0blB54AjaQ4pqRLgUAdeoCtKJBOGGARxMj9Gm1Efwa2VczfijpbauSaOWhRF4wFV+OS0pLos93f/TxlmTYxL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j/unueHNAcNnUfwaApbKhLt8//jtB/iSvue1Ylv2FN4ggWmFPmbaQPFUrncrLTe45SaM80LY/1vbUVPsxT/rl4Q+GB/NbiIXDe/a7BAZ+JoKYkvMwlH3 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: This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O could otherwise end up being visible to/affected by the child process). Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org Reviewed-by: Jan Kara --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #8) - Split the patch up a bit [hch]. - We should only be using pinned/non-pinned pages and not ref'd pages, so adjust the comments appropriately. ver #7) - Don't treat BIO_PAGE_REFFED/PINNED as being the same as FOLL_GET/PIN. ver #5) - Transcribe the FOLL_* flags returned by iov_iter_extract_pages() to BIO_* flags and got rid of bi_cleanup_mode. - Replaced BIO_NO_PAGE_REF to BIO_PAGE_REFFED in the preceding patch. block/blk-map.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 33d9f6e89ba6..3551c3ff17cf 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -281,22 +281,21 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); - bio_set_flag(bio, BIO_PAGE_REFFED); while (iov_iter_count(iter)) { - struct page **pages, *stack_pages[UIO_FASTIOV]; + struct page *stack_pages[UIO_FASTIOV]; + struct page **pages = stack_pages; ssize_t bytes; size_t offs; int npages; - if (nr_vecs <= ARRAY_SIZE(stack_pages)) { - pages = stack_pages; - bytes = iov_iter_get_pages(iter, pages, LONG_MAX, - nr_vecs, &offs, extraction_flags); - } else { - bytes = iov_iter_get_pages_alloc(iter, &pages, - LONG_MAX, &offs, extraction_flags); - } + if (nr_vecs > ARRAY_SIZE(stack_pages)) + pages = NULL; + + bytes = iov_iter_extract_pages(iter, &pages, LONG_MAX, + nr_vecs, extraction_flags, &offs); if (unlikely(bytes <= 0)) { ret = bytes ? bytes : -EFAULT; goto out_unmap; @@ -318,7 +317,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (!bio_add_hw_page(rq->q, bio, page, n, offs, max_sectors, &same_page)) { if (same_page) - put_page(page); + bio_release_page(bio, page); break; } @@ -330,7 +329,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, * release the pages we didn't map into the bio, if any */ while (j < npages) - put_page(pages[j++]); + bio_release_page(bio, pages[j++]); if (pages != stack_pages) kvfree(pages); /* couldn't stuff something into bio? */