From patchwork Fri May 26 11:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13256800 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 185FFC7EE23 for ; Fri, 26 May 2023 11:29:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78F04900002; Fri, 26 May 2023 07:29:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71A5D280002; Fri, 26 May 2023 07:29:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51DBB900004; Fri, 26 May 2023 07:29:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 42599900002 for ; Fri, 26 May 2023 07:29:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 11065140E82 for ; Fri, 26 May 2023 11:29:25 +0000 (UTC) X-FDA: 80832185490.19.96A1210 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 3E10020019 for ; Fri, 26 May 2023 11:29:22 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JFHaeL1C; 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=1685100563; 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=/oa1BFyOPAnXCxzKNg+OmyZ2j7EgUWqexyoMi96HVck=; b=70mJxDRtHag3uZQPhjxXcMiVnBdLq8fVjsOaGvuNlzpmZG6cV0V/7wyoVF0yUc4I5X6da9 l6PRMRrFict7JHaz/IJvUNDpwU3yI7KMU2NW0RPvqIpFl61BzqtG2XfneQtmNjTmoLj1Lb WJe+tdaH/IZSOY7WcqEC26S+AI/tKHs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685100563; a=rsa-sha256; cv=none; b=DwdVWPcCpkkZQkRP1eEYPkc5NqmN0RkHzx+VEH1slCfP3obSPoOet5rabbRQJFV9xq5abL 09Y8fZLdWxJv+nSpsyEIvRtjF2GJB1di92A23kzK7NGy/tlXHfPMc1CU4EV+PfbHNeW4DI DGU9NK38avdptDqOutAGAItcY468CZA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JFHaeL1C; 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=1685100562; 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=/oa1BFyOPAnXCxzKNg+OmyZ2j7EgUWqexyoMi96HVck=; b=JFHaeL1CFo7cf1Xz99FLkfHiZxTX3JKmwnsH3gbKd5p/sN//9gBZWT/enRjH2iN/2twF85 BUNg84Esr7Q1uIAxCY0C8HcDAcPExnT6DB7WXNitQCHa3k4dCbiObQ4UoTe+UYEGVeLz33 aqJZ9YxrpnU+CVefowZxjQ3Q7JVQ884= 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-460-5Dx9Zud5NgaNs8x-s-9Znw-1; Fri, 26 May 2023 07:29:19 -0400 X-MC-Unique: 5Dx9Zud5NgaNs8x-s-9Znw-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 B8933185A78F; Fri, 26 May 2023 11:29:17 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 470B0200AD47; Fri, 26 May 2023 11:29:15 +0000 (UTC) From: David Howells To: Christoph Hellwig , David Hildenbrand , Lorenzo Stoakes 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: [PATCH v3 2/3] mm: Provide a function to get an additional pin on a page Date: Fri, 26 May 2023 12:28:58 +0100 Message-Id: <20230526112859.654506-3-dhowells@redhat.com> In-Reply-To: <20230526112859.654506-1-dhowells@redhat.com> References: <20230526112859.654506-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Stat-Signature: mpi9t8jynurk76f9e8noyw36t1pcee8j X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3E10020019 X-Rspam-User: X-HE-Tag: 1685100562-207917 X-HE-Meta: U2FsdGVkX18/862GJMy20l+62pnyYxhpbc4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ImYjiSmfQKGJUdA7Ncj+c3Bd4EmTESlJC2pHO3/HkgMoBDHwWefSMUT8aC2CTfpILIAcW75Y5gLbqi4SiygA1oPRMACL4ALQ87MmLU+XevBkzgMXx+6Bu5MsAJKhaZ0hR0po2ZRb1+WKySUKy/oHvPldWkR1DKhFZT0xlYQK1WBHmaq06oHMpEeAOJUyqU9S+Nm94i7KCGSI6VDNcBEvNkdUD1pOsVQyb8C2sQq2VljoXQY98zgQgQCTaertDgEwg1jDz0w1gwYil1/9vmC+e/v0jQsRnAisTaqPRpOXF7KjnWOTb4Fl7ihURwRnShSPXRQAQJSjg4d4qzyO9fjxr6NDgln/7wyd07TqLPuo6NWS7uj8VP+ZjpvKIRUMx/Ve9FnjXyO+YXOpwZ4WjP78R3S5n7L8tUIWumhSBWeJUprZVxFgM5jzmlGfsAcWEhcU9ICmnZv2R66WK9HdcimgVL9tkSyqRiw0i1pD4/lbJy6/YyHpO7dyfYPPhKsJTwjbQgMPMKyyrU7m5ZuCCrNwZiSABAM/QzD7VTgkhN3Vko6prmFKVRn/0LudgX8E+uf4eJRcZo 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: Lorenzo Stoakes 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 --- Notes: ver #3) - Rename to folio_add_pin(). - Change to using is_zero_folio() include/linux/mm.h | 1 + mm/gup.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3c2f6b452586..200068d98686 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2405,6 +2405,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 folio_add_pin(struct folio *folio); 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 ad28261dcafd..08fdd84088d1 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -275,6 +275,33 @@ void unpin_user_page(struct page *page) } EXPORT_SYMBOL(unpin_user_page); +/** + * folio_add_pin - Try to get an additional pin on a pinned folio + * @folio: The folio to be pinned + * + * Get an additional pin on a folio we already have a pin on. Makes no change + * if the folio is a zero_page. + */ +void folio_add_pin(struct folio *folio) +{ + if (is_zero_folio(folio)) + 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) {