From patchwork Tue Jan 24 17:01:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 47787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2269620wrn; Tue, 24 Jan 2023 09:12:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXuPYAfOOWm6HcO+Q7Ou68w96fJ9L9a2ADlpsbRWCuP7fhmLxuK+muw92YWqpHVt7KyvGwRb X-Received: by 2002:a05:6a21:99a7:b0:b5:d781:ca7 with SMTP id ve39-20020a056a2199a700b000b5d7810ca7mr40223146pzb.3.1674580359439; Tue, 24 Jan 2023 09:12:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674580359; cv=none; d=google.com; s=arc-20160816; b=gn1v3RO3GDOJECo2RZwk0U4bEZGHcaS9sxOr+LaPl3pKLkmpimPzURxVFu3Ir4+4jl 6geGHK+3rt1xjNvtdVyerdLTEd6CnOr8pShNPmfw7scCAZsyPzuxabvVqLvj2LOTwFfX VX3hl8fLRqRhA3z645bEE5G9FUqg3meR8BDfYcFlZu2+gb5orRighwjVIO19MNXifdh6 9l9sFebwHJAuiNH0TLN5rgGXD1oFqvI1uqUAgHUhwLJ03ioLz34/AP3tsQ6WLZU7s6m/ 7tM8b4+FPhoUOX7qrqHEEq3QWWYgMBYSbZZVQsYXtZISB2YCmBxhJ6W6ltV/naCXPs0r zoqQ== 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=ws++TYA3+95tmIWLYOLAybQ1B+3xtFbcyZ6i7KySwPY=; b=R4jwvADGNou3ulQRITIOiChHr5X2Gll8NAyjxIsKJUUOVf7d0fP8QzoWZJLxYZtN0h 3kygkgXTu/zXVGrPJG0QvSDPq21ImGnphd1BQ4WZP6/09F+ua15yHoFxAik845WTHKqW vSzNnywfsxWjAZj0m6OaDwje5rqDWJPiqPl4mSCP0SyuvKn+EFCFSCG4j8WMtocC07L+ QkGKQRarS6TdcE3n8IPPH1A2MJl1/zS+wwBc7N1qnozxbeeibV1HldbbW0r5C2qah9RI 62FDt+reUTO6Ubm7am+8ZGl+Nn7P2Bi4lzYXVnCzOCELB6p/V1JFTIITVd4HqCVVL4ps 4TkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZxA53FdF; 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 t1-20020a17090aba8100b002297696e25bsi2887487pjr.118.2023.01.24.09.12.27; Tue, 24 Jan 2023 09:12:39 -0800 (PST) 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=ZxA53FdF; 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 S234606AbjAXRDP (ORCPT + 99 others); Tue, 24 Jan 2023 12:03:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234449AbjAXRCl (ORCPT ); Tue, 24 Jan 2023 12:02:41 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 878664B88F for ; Tue, 24 Jan 2023 09:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674579709; 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=ws++TYA3+95tmIWLYOLAybQ1B+3xtFbcyZ6i7KySwPY=; b=ZxA53FdFZR1NaVIw7/hlaqNPhetKF2ejpPbAfMXp6BaUQYE+EZvxi/r4v+V/4qQKbPBBqs GDyMLBP5S7lxB2Xsclr5qvb30yHOxErosKoX9x+LTWsNKkNcsC4/ITX/nN4RO2NzzXcEn4 MPwUjJkuPfLhP6gwdHPBh0VMjkdvH8E= 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-421-UEKnBzFdMTKx7HDKATbAZg-1; Tue, 24 Jan 2023 12:01:46 -0500 X-MC-Unique: UEKnBzFdMTKx7HDKATbAZg-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 B7B2D1C02D2A; Tue, 24 Jan 2023 17:01:45 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id E24DEC15BA0; Tue, 24 Jan 2023 17:01:43 +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, Christoph Hellwig Subject: [PATCH v9 6/8] block: Switch to pinning pages. Date: Tue, 24 Jan 2023 17:01:06 +0000 Message-Id: <20230124170108.1070389-7-dhowells@redhat.com> In-Reply-To: <20230124170108.1070389-1-dhowells@redhat.com> References: <20230124170108.1070389-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 autolearn=unavailable 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?1755924775065943076?= X-GMAIL-MSGID: =?utf-8?q?1755924775065943076?= 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 cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Christoph Hellwig cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- Notes: 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 | 21 +++++++++++++++++++++ include/linux/bio.h | 3 ++- include/linux/blk_types.h | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 851c23641a0d..fc45aaa97696 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1176,7 +1176,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); @@ -1496,8 +1496,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 4c3b3325219a..32b252903f9a 100644 --- a/block/blk.h +++ b/block/blk.h @@ -425,6 +425,27 @@ 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); +/* + * Set the cleanup mode for a bio from an iterator and the extraction flags. + */ +static inline void bio_set_cleanup_mode(struct bio *bio, struct iov_iter *iter) +{ + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); +} + +/* + * 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, void *owner); diff --git a/include/linux/bio.h b/include/linux/bio.h index 805957c99147..b2c09997d79c 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -484,7 +484,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 7daa261f4f98..a0e339ff3d09 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -318,6 +318,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 */