Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp70596rwd; Fri, 26 May 2023 15:10:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pMkSbF8iTQVs6Cvy56xqNXy22/2Qfemc7OOYuVGNm53sprNnLej2pD0AMIvPlmYcBSx3L X-Received: by 2002:a05:6a20:7d95:b0:10f:1d33:d667 with SMTP id v21-20020a056a207d9500b0010f1d33d667mr978986pzj.5.1685139035917; Fri, 26 May 2023 15:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685139035; cv=none; d=google.com; s=arc-20160816; b=G//+XijFJjcMd45N66k6tprTep3h/FLjWVBLmLy09FTBbS81xtVWqnEsWcq+cSrEc2 FCs9NlG+NxCNaHq38CFWQtU8eNgvZljAp//jCq4hy95U8/jaKBVRbU3IcJkrxmYbMlYx ERXRJQgVj/iA0Id7axOjENCir3IkvCXNa2G9hD0eqYovbbSuJSW7UrBCJHA11XAOSvwq gR0+w7lNHtF/P05GMbCr+iLPco5ZK5gS90r+v0piNPlsHqzH9oZj5eFCZwvj+gJHMufK Pj8emyMdj5xYIMsYCnuACadnj9eGieHDLYOPOHXu6ET5cWxcErPGsT7kO+xSuUPINWU/ GNfQ== 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=ygH+ZqonbpI6GaSwXkJ0fs6Q5AaJM3JSYEP5qBjfvE4=; b=aKuJzO1SkKOocesxq4GQTJsBNSpLOXIq7GUengHZppxwg2gRKhTunsFYPqVq1SO/5Y UFFv41Lx2Hxl4VjGRlRrxrcR42uXwL9J1vPqcZ3AetFGkgQELJTfxpVrHzYSaDDrJPJM qh2jxbibOg62DQspPNg8cyJn3LK46Vhd7XDX1MPIGg83ULGjxGCvHu+dx4/mbYsQP/cB WKpB0dX+/i2Ji1bu9F16kOfWcA3QCY9JJwr05AYpqTUMlEl6/dhHX82yZl2zHBz4Acd0 iM09RXNvyBO6R2V4gg8X8bqffZQIq3oGo0bDKcmCWF9gwwpjX0fgwiQM3cUTgxyYOAca ejiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d8G187P5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i192-20020a639dc9000000b0053f3498ac9dsi970423pgd.677.2023.05.26.15.10.20; Fri, 26 May 2023 15:10:35 -0700 (PDT) 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=d8G187P5; 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 S243441AbjEZVnV (ORCPT + 99 others); Fri, 26 May 2023 17:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243261AbjEZVnS (ORCPT ); Fri, 26 May 2023 17:43:18 -0400 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 B50E8119 for ; Fri, 26 May 2023 14:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685137318; 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=d8G187P5/gtktcm1xgH20T0d9kBm9r6/VRYNzCQqY5L5xqeR5nuG328LZzE8tMXkIP2qtn Qh0ZUYKSRycVAIldW22538ze2kqISHOnmQu+PvBtv/Svo5tT4wrzWigj7j5GnxM62i1BLG lnWt0B9RugUwgI9WcbNWG+a+bnW1COc= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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 #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) {