diff mbox series

[v3,05/25] mm: Add put_folio

Message ID 20210128070404.1922318-6-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Page folios | expand

Commit Message

Matthew Wilcox Jan. 28, 2021, 7:03 a.m. UTC
If we know we have a folio, we can call put_folio() instead of put_page()
and save the overhead of calling compound_head().  Also skips the
devmap checks.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/mm.h | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Zi Yan March 1, 2021, 9:41 p.m. UTC | #1
On 28 Jan 2021, at 2:03, Matthew Wilcox (Oracle) wrote:

> If we know we have a folio, we can call put_folio() instead of put_page()
> and save the overhead of calling compound_head().  Also skips the
> devmap checks.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  include/linux/mm.h | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 7d787229dd40..873d649107ba 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1220,9 +1220,15 @@ static inline __must_check bool try_get_page(struct page *page)
>  	return true;
>  }
>
> +static inline void put_folio(struct folio *folio)
> +{
> +	if (put_page_testzero(&folio->page))
> +		__put_page(&folio->page);
> +}
> +
>  static inline void put_page(struct page *page)
>  {
> -	page = compound_head(page);
> +	struct folio *folio = page_folio(page);
>
>  	/*
>  	 * For devmap managed pages we need to catch refcount transition from
> @@ -1230,13 +1236,12 @@ static inline void put_page(struct page *page)
>  	 * need to inform the device driver through callback. See
>  	 * include/linux/memremap.h and HMM for details.
>  	 */
> -	if (page_is_devmap_managed(page)) {
> -		put_devmap_managed_page(page);
> +	if (page_is_devmap_managed(&folio->page)) {
> +		put_devmap_managed_page(&folio->page);
>  		return;
>  	}
>
> -	if (put_page_testzero(page))
> -		__put_page(page);
> +	put_folio(folio);
>  }
>
>  /*
> -- 
> 2.29.2

LGTM.

Reviewed-by: Zi Yan <ziy@nvidia.com>


—
Best Regards,
Yan Zi
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7d787229dd40..873d649107ba 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1220,9 +1220,15 @@  static inline __must_check bool try_get_page(struct page *page)
 	return true;
 }
 
+static inline void put_folio(struct folio *folio)
+{
+	if (put_page_testzero(&folio->page))
+		__put_page(&folio->page);
+}
+
 static inline void put_page(struct page *page)
 {
-	page = compound_head(page);
+	struct folio *folio = page_folio(page);
 
 	/*
 	 * For devmap managed pages we need to catch refcount transition from
@@ -1230,13 +1236,12 @@  static inline void put_page(struct page *page)
 	 * need to inform the device driver through callback. See
 	 * include/linux/memremap.h and HMM for details.
 	 */
-	if (page_is_devmap_managed(page)) {
-		put_devmap_managed_page(page);
+	if (page_is_devmap_managed(&folio->page)) {
+		put_devmap_managed_page(&folio->page);
 		return;
 	}
 
-	if (put_page_testzero(page))
-		__put_page(page);
+	put_folio(folio);
 }
 
 /*