diff mbox series

[07/17] gup: Add gup_put_folio()

Message ID 20220102215729.2943705-8-willy@infradead.org (mailing list archive)
State New
Headers show
Series Convert GUP to folios | expand

Commit Message

Matthew Wilcox Jan. 2, 2022, 9:57 p.m. UTC
put_compound_head() is turned into a call to gup_put_folio().
This removes the last call to put_page_refs(), so delete it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/gup.c | 44 +++++++++++++++-----------------------------
 1 file changed, 15 insertions(+), 29 deletions(-)

Comments

Christoph Hellwig Jan. 4, 2022, 8:22 a.m. UTC | #1
On Sun, Jan 02, 2022 at 09:57:19PM +0000, Matthew Wilcox (Oracle) wrote:
> put_compound_head() is turned into a call to gup_put_folio().
> This removes the last call to put_page_refs(), so delete it.

Except for one more of those nasty page to folio casts (which I assume
will go away soon), this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
John Hubbard Jan. 5, 2022, 6:52 a.m. UTC | #2
On 1/2/22 13:57, Matthew Wilcox (Oracle) wrote:
> put_compound_head() is turned into a call to gup_put_folio().
> This removes the last call to put_page_refs(), so delete it.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>   mm/gup.c | 44 +++++++++++++++-----------------------------
>   1 file changed, 15 insertions(+), 29 deletions(-)
> 

Reviewed-by: John Hubbard <jhubbard@nvidia.com>


thanks,
William Kucharski Jan. 6, 2022, 10:05 p.m. UTC | #3
Comment inline.

> On Jan 2, 2022, at 2:57 PM, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> put_compound_head() is turned into a call to gup_put_folio().
> This removes the last call to put_page_refs(), so delete it.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> mm/gup.c | 44 +++++++++++++++-----------------------------
> 1 file changed, 15 insertions(+), 29 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index 58e5cfaaa676..6d827f7d66d8 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -36,29 +36,11 @@ static void folio_pincount_add(struct folio *folio, int refs)
> 	atomic_add(refs, folio_pincount_ptr(folio));
> }
> 
> -static void hpage_pincount_sub(struct page *page, int refs)
> +static void folio_pincount_sub(struct folio *folio, int refs)
> {
> -	VM_BUG_ON_PAGE(!hpage_pincount_available(page), page);
> -	VM_BUG_ON_PAGE(page != compound_head(page), page);
> -
> -	atomic_sub(refs, compound_pincount_ptr(page));
> -}
> -
> -/* Equivalent to calling put_page() @refs times. */
> -static void put_page_refs(struct page *page, int refs)
> -{
> -#ifdef CONFIG_DEBUG_VM
> -	if (VM_WARN_ON_ONCE_PAGE(page_ref_count(page) < refs, page))
> -		return;
> -#endif

Should this retain a form of the CONFIG_DEBUG_VM warning here to trigger if
folio_pincount_ptr(folio) is < refs?

> +	VM_BUG_ON_FOLIO(!folio_pincount_available(folio), folio);
> -	/*
> -	 * Calling put_page() for each ref is unnecessarily slow. Only the last
> -	 * ref needs a put_page().
> -	 */
> -	if (refs > 1)
> -		page_ref_sub(page, refs - 1);
> -	put_page(page);
> +	atomic_sub(refs, folio_pincount_ptr(folio));
> }
> 
> /*
> @@ -175,19 +157,23 @@ struct page *try_grab_compound_head(struct page *page,
> 	return NULL;
> }
> 
> -static void put_compound_head(struct page *page, int refs, unsigned int flags)
> +static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
> {
> 	if (flags & FOLL_PIN) {
> -		mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED,
> -				    refs);
> -
> -		if (hpage_pincount_available(page))
> -			hpage_pincount_sub(page, refs);
> +		node_stat_mod_folio(folio, NR_FOLL_PIN_RELEASED, refs);
> +		if (folio_pincount_available(folio))
> +			folio_pincount_sub(folio, refs);
> 		else
> 			refs *= GUP_PIN_COUNTING_BIAS;
> 	}
> 
> -	put_page_refs(page, refs);
> +	folio_put_refs(folio, refs);
> +}
> +
> +static void put_compound_head(struct page *page, int refs, unsigned int flags)
> +{
> +	VM_BUG_ON_PAGE(PageTail(page), page);
> +	gup_put_folio((struct folio *)page, refs, flags);
> }
> 
> /**
> @@ -228,7 +214,7 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags)
>  */
> void unpin_user_page(struct page *page)
> {
> -	put_compound_head(compound_head(page), 1, FOLL_PIN);
> +	gup_put_folio(page_folio(page), 1, FOLL_PIN);
> }
> EXPORT_SYMBOL(unpin_user_page);
> 
> -- 
> 2.33.0
> 
>
diff mbox series

Patch

diff --git a/mm/gup.c b/mm/gup.c
index 58e5cfaaa676..6d827f7d66d8 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -36,29 +36,11 @@  static void folio_pincount_add(struct folio *folio, int refs)
 	atomic_add(refs, folio_pincount_ptr(folio));
 }
 
-static void hpage_pincount_sub(struct page *page, int refs)
+static void folio_pincount_sub(struct folio *folio, int refs)
 {
-	VM_BUG_ON_PAGE(!hpage_pincount_available(page), page);
-	VM_BUG_ON_PAGE(page != compound_head(page), page);
-
-	atomic_sub(refs, compound_pincount_ptr(page));
-}
-
-/* Equivalent to calling put_page() @refs times. */
-static void put_page_refs(struct page *page, int refs)
-{
-#ifdef CONFIG_DEBUG_VM
-	if (VM_WARN_ON_ONCE_PAGE(page_ref_count(page) < refs, page))
-		return;
-#endif
+	VM_BUG_ON_FOLIO(!folio_pincount_available(folio), folio);
 
-	/*
-	 * Calling put_page() for each ref is unnecessarily slow. Only the last
-	 * ref needs a put_page().
-	 */
-	if (refs > 1)
-		page_ref_sub(page, refs - 1);
-	put_page(page);
+	atomic_sub(refs, folio_pincount_ptr(folio));
 }
 
 /*
@@ -175,19 +157,23 @@  struct page *try_grab_compound_head(struct page *page,
 	return NULL;
 }
 
-static void put_compound_head(struct page *page, int refs, unsigned int flags)
+static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
 {
 	if (flags & FOLL_PIN) {
-		mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED,
-				    refs);
-
-		if (hpage_pincount_available(page))
-			hpage_pincount_sub(page, refs);
+		node_stat_mod_folio(folio, NR_FOLL_PIN_RELEASED, refs);
+		if (folio_pincount_available(folio))
+			folio_pincount_sub(folio, refs);
 		else
 			refs *= GUP_PIN_COUNTING_BIAS;
 	}
 
-	put_page_refs(page, refs);
+	folio_put_refs(folio, refs);
+}
+
+static void put_compound_head(struct page *page, int refs, unsigned int flags)
+{
+	VM_BUG_ON_PAGE(PageTail(page), page);
+	gup_put_folio((struct folio *)page, refs, flags);
 }
 
 /**
@@ -228,7 +214,7 @@  bool __must_check try_grab_page(struct page *page, unsigned int flags)
  */
 void unpin_user_page(struct page *page)
 {
-	put_compound_head(compound_head(page), 1, FOLL_PIN);
+	gup_put_folio(page_folio(page), 1, FOLL_PIN);
 }
 EXPORT_SYMBOL(unpin_user_page);