Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1625674rwd; Thu, 25 May 2023 15:46:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6sObcxcD7o/ISK1de2aD2qbmNJ9bo9ELlOWrg+keMbnJJYNkCXBizHfOAuwtLub3VPs2Ll X-Received: by 2002:a05:6a00:10c3:b0:63d:47ab:65ed with SMTP id d3-20020a056a0010c300b0063d47ab65edmr478913pfu.7.1685054799695; Thu, 25 May 2023 15:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685054799; cv=none; d=google.com; s=arc-20160816; b=jAZvNfYW3IZKslmdEFKewQdDxrMq04W3IuvCkloN51maoJJ8K14AbYfclq1TrlIKEk UyeKAvUfOqofYH9AmrJPNNh9zNOrxZxck91EKGSekW6LzShFPyT8tTtEwP2Bgg1+0UNY MYjZ4v/AX1ZcLDQVQBNJbow458jEUpwZKKi/HVB10IQQJgl1hJlKjhKNK/yDXA+jfV3M 0M5M821diJ1j3/wOLCDtpRyhnRrzcrrLjbwrVF9657zbaLCTff32T5ITj1veCMvyENOG 9oi7J7NgxvTCyyiEzniZO55Am2SlAvLb+wmyD6lQTRv6ONyWD+rtDtH3UYAop7L0f00a Xgwg== 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=4LadGJQg30+UITevY/GGSgUqQRDMNZJwaw2G4qvwi6M=; b=yGI/LYpjdjXfLGBOaScdzglf9AHK9SDTM+fB4fWH7tk+sC+ZoUg0NTYL6y+QFOLvjN AfUemu+B4qBf9/0EbxvvsnCkQ2f4O33PLYIxc42RrwboVZFCpgQXGKQbWNGh9ouX+dyx j+PPBory5Tcl/wev0QxwBl2EHjjlqbDdmOX3wosnp8Dl2uNUDJSzG4LHp0ZKfFDY0ikP ZHmUOFmOj4Ky8nAaZl7H8VoT8N5wndiMRhozPv2nIypCGvBdGqeIUS27q15+BZ5xNSNW x8diyaSxk1p/oy918Aw177W6kzVAKuhor0NtI4GAOTJxrDrFAC05vWGUFz/gHLlDbpew xhew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="erMMQ/8h"; 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 24-20020a631258000000b00524d1d335bbsi2161449pgs.56.2023.05.25.15.46.27; Thu, 25 May 2023 15:46:39 -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="erMMQ/8h"; 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 S236348AbjEYWlr (ORCPT + 99 others); Thu, 25 May 2023 18:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242062AbjEYWlk (ORCPT ); Thu, 25 May 2023 18:41:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFB661A6 for ; Thu, 25 May 2023 15:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685054409; 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=erMMQ/8hbFmRM+A7UKkIAKHduEUE56sSxIONbAEXuRlRhKDPJ4WtZW5kzVarzeCULgs/96 RvEmNbVpz+cbjpfPao3iUXnLqG2xwku/i56AEwaNwF8pTKN459ENsBb+z6M3KdazMLmtbo phl6z155anPsxIB0faRcXJSFI+0iL0o= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=unavailable 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: 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) {