From patchwork Thu May 25 15:51:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13255406 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 EFD3DC7EE2D for ; Thu, 25 May 2023 15:51:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3E56280001; Thu, 25 May 2023 11:51:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC6DA6B0075; Thu, 25 May 2023 11:51:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9C45280001; Thu, 25 May 2023 11:51:22 -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 A68566B0074 for ; Thu, 25 May 2023 11:51:22 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 248E0C0B98 for ; Thu, 25 May 2023 15:51:22 +0000 (UTC) X-FDA: 80829216804.11.E3660F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 0E63A1A0025 for ; Thu, 25 May 2023 15:51:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Fp08mMQ/"; spf=pass (imf19.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=1685029879; 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=BVMkJArYFah5gI2QNFMxWzaYnawUBl8R91cCRWuGcSI=; b=nqSCu5ogGrUxrjJmdwUJgcfhZTMsKO8ISbzNVVzp7Zo1LS+4n5uuepgFh78lz/+Tl3w0/M /8fg4Qd2trchVe+DGvs5E15faa87tdh4uEOFMhX3gwA/V3b9fBesZh7yXxPIaSmac7NIDr wAu9Ht8a1BS2mPOjfNVbCk6GygZusLs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685029879; a=rsa-sha256; cv=none; b=okdCqyiwNgX4Lrf96vVE5xEoq+0zd3RvuJuCoke7atQdyPeyOnvxI4dv4uFxSltlbdgzxu z4aegaRRQf4Jx/J0TlsV8yPJASFgO155IzoFbMgD0QzWprxjQDv6hA2Unn7kbsJPkcEtPM FOMlNqzXfpB2+iwdGaxoWWUggv2krgQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Fp08mMQ/"; spf=pass (imf19.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=1685029878; 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=BVMkJArYFah5gI2QNFMxWzaYnawUBl8R91cCRWuGcSI=; b=Fp08mMQ/g8XkuMXTSaMpNU1r3oiMD+mK4fQUkVIJM2kKjlr0B9/sPlTeaIx1XFvf+8d/fN GKO/N1Wo/J8t38jbYDdBaadqz4OvYjQ3HYsSgFC8pQ5bLB5NCAr291dp0kkESHodSmAMCn IC3/szzm/Fy2teW2aPSdJosFja+hMFo= 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-414-ellFKLpmOhqtIg-dAldJeQ-1; Thu, 25 May 2023 11:51:14 -0400 X-MC-Unique: ellFKLpmOhqtIg-dAldJeQ-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 C448238294B6; Thu, 25 May 2023 15:51:13 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EE15407DEC3; Thu, 25 May 2023 15:51:11 +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 2/3] mm: Provide a function to get an additional pin on a page Date: Thu, 25 May 2023 16:51:01 +0100 Message-Id: <20230525155102.87353-3-dhowells@redhat.com> In-Reply-To: <20230525155102.87353-1-dhowells@redhat.com> References: <20230525155102.87353-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: 0E63A1A0025 X-Rspam-User: X-Stat-Signature: mf4xnz4rghcnjzpz37n7mgz83esttpst X-Rspamd-Server: rspam03 X-HE-Tag: 1685029878-944141 X-HE-Meta: U2FsdGVkX1+FMHRhPLQWO5S09PjmnW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jh3SH0ky66Nc5jJGRDj8bZ670tVF32RfnaOJljcb9OWQCKBHzOcp4sOMNfd6Pvv0ZsrYVvBLK1oj+Bzfg13ZM2LHYL2omUAgjnZ/OZx4hDt5ojkFUbepEamEPHxL3iVyJOOR9/mBodILwqqsASF4srTJNJYXXDa+uOweENyNWKGt6iVnPBqncHZpJxxmARMVkapgjkoPWQWk7awPtOl4ILz9LRykPfLR+AbbCjAt82KMnXmTLDsAiq8HWVSQoKOI4TbiF3JbQFmfQnwEcaSsTsxndr8udN80i6aZhM4MSwwa/1MaRe4g0z1Iy7KIIJQFlQu3QXBAXepFU+ID0d0EVWT5/pdyNotZcgscYFhpS3m6IZTICsCuKUAeQEXvflnFIhHXj42TTx4kTexRdoE1GdwEqPYC+Q3VDDBpoxGhjQJEPpwZBgDzBPVEiKfqgmokg3+S5Mfw9cSgVN51C4nboD2HZPZ10ue3wkRVoMV5bVXBhbOzQDSoD43LLI176yqGURWFRhAkSQFj3WDujgdI2kae3aVlMJv2I52N7Ays9bkRJrG/VxoNKg= 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 d2662aa8cf01..b1e55847ca13 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) {