From patchwork Fri May 26 21:41: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: 13257339 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 2CA06C77B7C for ; Fri, 26 May 2023 21:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B648D280002; Fri, 26 May 2023 17:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEB75900002; Fri, 26 May 2023 17:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B2F3280002; Fri, 26 May 2023 17:42:00 -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 87599900002 for ; Fri, 26 May 2023 17:42:00 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 47397140790 for ; Fri, 26 May 2023 21:42:00 +0000 (UTC) X-FDA: 80833729200.15.48E0316 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 8200B180006 for ; Fri, 26 May 2023 21:41:58 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dmeHILRf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.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=1685137318; 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=ygH+ZqonbpI6GaSwXkJ0fs6Q5AaJM3JSYEP5qBjfvE4=; b=z9TJPN6qcO5QFfYYiJswM+BylzC2ouhl2/VIFXdfGrL2jB+qlwNOeEXJzhum5JuRsNMTkG byjsNOTvAxCRk2K9U3tVWugwFu0i4aoChetFiRXndDRTTpehnBuoDg4h9p7ju87JweECdD u2vwC6P6Gyr33YvZXkcTNqAYAv7S2ww= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dmeHILRf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.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=1685137318; a=rsa-sha256; cv=none; b=VAJrtPb1+DEYRvOhczdcDiDZt76n4x6BqzAniQxsMiE172Lb1fNSsVV4pnUTJ2Z6InjoNo ZQ+4CXS3usvrjVV07CZfKCRt2kgVaBuI20dK8cFw2szDGi6jE+CF0AV/Ieg1bMVt4mGD3f S2lLBfQsmhCA2KF1yWi0zuvG0fNJS28= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685137317; 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=ygH+ZqonbpI6GaSwXkJ0fs6Q5AaJM3JSYEP5qBjfvE4=; b=dmeHILRfQCgud9X6NIAcjtaGiRuwZYMOwtZqPG0IcC7eVNcfPZcIIvaqbML9pXqqTvc2K3 9ubOfHjUi/o9pfG/cVJ0Rv75b/NTgChEhDJyCz6uJFuAyRx0MlkyOnDIjRoaA6dx3XlQ0D P0DYssm+ZIbx3uNH+Uv7PRgyh7U6TTY= 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-563-16yAqvjWNa-RXszar_4pfQ-1; Fri, 26 May 2023 17:41:54 -0400 X-MC-Unique: 16yAqvjWNa-RXszar_4pfQ-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 858EA3803508; Fri, 26 May 2023 21:41:53 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03C5A2166B2E; Fri, 26 May 2023 21:41:50 +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 v4 2/3] mm: Provide a function to get an additional pin on a page Date: Fri, 26 May 2023 22:41:41 +0100 Message-Id: <20230526214142.958751-3-dhowells@redhat.com> In-Reply-To: <20230526214142.958751-1-dhowells@redhat.com> References: <20230526214142.958751-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: 8200B180006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: assuwyxpdd9nortfqgxkchyjwmm9h3gg X-HE-Tag: 1685137318-157857 X-HE-Meta: U2FsdGVkX18jkSQHL++CLXb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HyHpjtcz8epuywyjpLNBUfAOYEOhzKPgvLPOxGTeLzs6EpAQL7EPu/8hHtPniSZT2fAXQ8sywTs7NMbaqlkclGdckmBo1HnRahLjkNiR+HZ7oBMAYcKOb2hSuRYdXcrFw4dNWOrlCdca/mC5lmoxqSuWOCKtsQmhH50CUH0FP8OALM/zqJpchfWT18zA9aXvhJ3syWIWOOR2s11Znrn/VdknXM0n8GEcYiSqZyyQ8LUKMMIWDjaA3LmXY9LeadyWFnNsq0OCDtuIFDitCG35f/723lsija9jHnk1iRCe6E8thceCjYs384Q2ITz7adaBgerbDvzFAJGdJSuFIRUByL3GKwgNC/yu2izZFtESmUQWjTO7yJPIbaRsMLufOoOV7KyBP0vm2gpaGKavbfo9ZNr/ld369SVZqhBmBLht5d98IKgELz+h7Fjcby9TLyYlT2zZQM0VmZaj1xDsyVNpYiKPCgOydWrXefbe+bxqX5f+XEQPKYTUMIrigulTVDFcNBXnKwbbW+rco2rL/MO/f3ExkOnvfVGqhmekhAAb+/RrUJ1LGCNThx4KeRcSG0W1FURfeAvKUjtZcZPd9/6BvqtjzLCY 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 Reviewed-by: Christoph Hellwig Acked-by: David Hildenbrand --- Notes: ver #4) - Use _inc rather than _add ops when we're just adding 1. 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..0814576b7366 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_inc(folio); + atomic_inc(&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) {