Re: [PATCH 07/17] gup: Add gup_put_folio()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Comment inline.

> On Jan 2, 2022, at 2:57 PM, Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx>
> ---
> 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
> 
> 






[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux