From patchwork Thu May 25 22:39:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13255749 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 1C505C7EE2F for ; Thu, 25 May 2023 22:40:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FC79900005; Thu, 25 May 2023 18:40:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85C97900002; Thu, 25 May 2023 18:40:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FE89900005; Thu, 25 May 2023 18:40:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 626DC900002 for ; Thu, 25 May 2023 18:40:11 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A1E324081F for ; Thu, 25 May 2023 22:40:10 +0000 (UTC) X-FDA: 80830246980.28.5DBAFB4 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 E81E620016 for ; Thu, 25 May 2023 22:40:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bVSP8N20; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1685054409; 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=4LadGJQg30+UITevY/GGSgUqQRDMNZJwaw2G4qvwi6M=; b=J5dk7+NeVcnPWSg2/VMFLOTB59MV+POYDIUdp/4lFb6s1o/PfbTGyi88ksnrXZ8Tr3L/Yz YPJJYmBvs7N8RC8iL971+2s57CGpsS5h+zAD8FGsdiS3op8r4e1ZHXLnGVjQoM2CsrXbg1 MGe2pKHRFUlss8PUQTDYjFf+t+QnPGs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bVSP8N20; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1685054409; a=rsa-sha256; cv=none; b=kS3U5UqF+jgZLk9Fxy/2RoBYIStjsEdFnzd9IhSVHDavdHNlHUkEDmUiJGZHZyYO/HkvBR 1g+ARBsyap62YjDBS/jsweNJesOX8v7jWWFRo5Mry3OOgcNjqTiUATTSbpe17SmAhYm4Up +x5u1FgUGMnAZMEGFK9h+nJZO7p/Q9I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685054408; 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=4LadGJQg30+UITevY/GGSgUqQRDMNZJwaw2G4qvwi6M=; b=bVSP8N20MF6jnS3VAwOGm28+Y6yZUoeR03pIP5wXoY/zU0kzK6v+B/8Po61niUVS9p5sDj Ep65YtANR8NFPCuqjiuIHV83k0wbE0n8pteN3Nc5CjSleR4guz04n7AB1J6gVSP0Mvvb/U lyejXG470sgGU2cFOeOz0R8a4YIFtI4= 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-164-lyrjH9PRONCGKTu4lTu3Vg-1; Thu, 25 May 2023 18:40:05 -0400 X-MC-Unique: lyrjH9PRONCGKTu4lTu3Vg-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 DC30B1C05EA3; Thu, 25 May 2023 22:40:04 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C98540CFD45; Thu, 25 May 2023 22:40:02 +0000 (UTC) From: David Howells To: Christoph Hellwig , David Hildenbrand Cc: David Howells , Jens Axboe , Al Viro , Matthew Wilcox , Jan Kara , Jeff Layton , 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, Andrew Morton Subject: [RFC PATCH v2 2/3] mm: Provide a function to get an additional pin on a page Date: Thu, 25 May 2023 23:39:52 +0100 Message-Id: <20230525223953.225496-3-dhowells@redhat.com> In-Reply-To: <20230525223953.225496-1-dhowells@redhat.com> References: <20230525223953.225496-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: E81E620016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: j9ok6j1wjzzy67zuzzkmhwk14jnrkgos X-HE-Tag: 1685054408-626650 X-HE-Meta: U2FsdGVkX19rCCju0ZQ2tZb+vjyc2LXGu004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FTemw/EMg6oYqZfU+lhhKN0vgnhS0xdmnEaKnODDyFNP5ykDuSN5T2dgX6mqU/ZxxTcm+O89xkRa40xVj+BKyhc0aQJMOwQT/3X0YjdV9cGJH3Ax+o/uzmM5wMzgtaeReGQTxLt+9izhEupKZ3YRPEThL2fmD0IFjGwj8z2zGSdGWsHMR0O0HaGKVWGPkjz6jqH33y5ws5BmPXsLsBJwo3dAyLqlFLBF7RD5FSlZKFJ+sCa5dAgUhF3zyPk5C48a2feU7raXt0ZwzC0EAD4uwbXEzci86CqCiP1nnheVcXU86jvDQ6losAf9Y9XRsaTmHH5cXPljid4wySEGQhL7JPRfcr1d+xsO/rJjxrnCiXg8xyVYK1DTHXy6h6KQ9U2WvcH522viXB3mE78mu2Zk117cYFKZJu2KnRvIjRpffMiIuaZ+lol+S5IhxblwsJrPXhlqicYUlmg/+suA75Vn3GHMt38a4kS3U/OcUemTHuBQPCyf9XomywSxekbltb0hHWYseP7isQXWgED7Zbuiek0mXAmfn5cpIP0lUlqLp+2ZdrmceFwrPEw= 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: Provide a function to get an additional pin on a page that we already have a pin on. This will be used in fs/direct-io.c when dispatching multiple bios to a page we've extracted from a user-backed iter rather than redoing the extraction. Signed-off-by: David Howells cc: Christoph Hellwig cc: David Hildenbrand cc: Andrew Morton cc: Jens Axboe cc: Al Viro cc: Matthew Wilcox cc: Jan Kara cc: Jeff Layton cc: Jason Gunthorpe cc: Logan Gunthorpe cc: Hillf Danton cc: Christian Brauner cc: Linus Torvalds cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-kernel@vger.kernel.org cc: linux-mm@kvack.org --- include/linux/mm.h | 1 + mm/gup.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 27ce77080c79..931b75dae7ff 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2383,6 +2383,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages); int pin_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages); +void page_get_additional_pin(struct page *page); int account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc); int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, diff --git a/mm/gup.c b/mm/gup.c index 69b002628f5d..4b4353a184ed 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -275,6 +275,35 @@ void unpin_user_page(struct page *page) } EXPORT_SYMBOL(unpin_user_page); +/** + * page_get_additional_pin - Try to get an additional pin on a pinned page + * @page: The page to be pinned + * + * Get an additional pin on a page we already have a pin on. Makes no change + * if the page is the zero_page. + */ +void page_get_additional_pin(struct page *page) +{ + struct folio *folio = page_folio(page); + + if (page == ZERO_PAGE(0)) + return; + + /* + * Similar to try_grab_folio(): be sure to *also* increment the normal + * page refcount field at least once, so that the page really is + * pinned. + */ + if (folio_test_large(folio)) { + WARN_ON_ONCE(atomic_read(&folio->_pincount) < 1); + folio_ref_add(folio, 1); + atomic_add(1, &folio->_pincount); + } else { + WARN_ON_ONCE(folio_ref_count(folio) < GUP_PIN_COUNTING_BIAS); + folio_ref_add(folio, GUP_PIN_COUNTING_BIAS); + } +} + static inline struct folio *gup_folio_range_next(struct page *start, unsigned long npages, unsigned long i, unsigned int *ntails) {