2022-01-10 04:24:54

by Matthew Wilcox

[permalink] [raw]
Subject: [PATCH v2 24/28] gup: Convert gup_huge_pgd() to use a folio

Use the new folio-based APIs. This was the last user of
try_grab_compound_head(), so remove it.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
---
mm/gup.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 7b7bf8361558..b5786e83c418 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -146,12 +146,6 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags)
return NULL;
}

-static inline struct page *try_grab_compound_head(struct page *page,
- int refs, unsigned int flags)
-{
- return &try_grab_folio(page, refs, flags)->page;
-}
-
static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
{
if (flags & FOLL_PIN) {
@@ -2563,7 +2557,8 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
struct page **pages, int *nr)
{
int refs;
- struct page *head, *page;
+ struct page *page;
+ struct folio *folio;

if (!pgd_access_permitted(orig, flags & FOLL_WRITE))
return 0;
@@ -2573,17 +2568,17 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
page = nth_page(pgd_page(orig), (addr & ~PGDIR_MASK) >> PAGE_SHIFT);
refs = record_subpages(page, addr, end, pages + *nr);

- head = try_grab_compound_head(pgd_page(orig), refs, flags);
- if (!head)
+ folio = try_grab_folio(page, refs, flags);
+ if (!folio)
return 0;

if (unlikely(pgd_val(orig) != pgd_val(*pgdp))) {
- put_compound_head(head, refs, flags);
+ gup_put_folio(folio, refs, flags);
return 0;
}

*nr += refs;
- SetPageReferenced(head);
+ folio_set_referenced(folio);
return 1;
}

--
2.33.0



2022-01-10 08:40:38

by Christoph Hellwig

[permalink] [raw]

2022-01-11 07:38:50

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH v2 24/28] gup: Convert gup_huge_pgd() to use a folio

On 1/9/22 20:24, Matthew Wilcox (Oracle) wrote:
> Use the new folio-based APIs. This was the last user of
> try_grab_compound_head(), so remove it.
>
> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
> ---
> mm/gup.c | 17 ++++++-----------
> 1 file changed, 6 insertions(+), 11 deletions(-)

Reviewed-by: John Hubbard <[email protected]>


thanks,
--
John Hubbard
NVIDIA

>
> diff --git a/mm/gup.c b/mm/gup.c
> index 7b7bf8361558..b5786e83c418 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -146,12 +146,6 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags)
> return NULL;
> }
>
> -static inline struct page *try_grab_compound_head(struct page *page,
> - int refs, unsigned int flags)
> -{
> - return &try_grab_folio(page, refs, flags)->page;
> -}
> -
> static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
> {
> if (flags & FOLL_PIN) {
> @@ -2563,7 +2557,8 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
> struct page **pages, int *nr)
> {
> int refs;
> - struct page *head, *page;
> + struct page *page;
> + struct folio *folio;
>
> if (!pgd_access_permitted(orig, flags & FOLL_WRITE))
> return 0;
> @@ -2573,17 +2568,17 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
> page = nth_page(pgd_page(orig), (addr & ~PGDIR_MASK) >> PAGE_SHIFT);
> refs = record_subpages(page, addr, end, pages + *nr);
>
> - head = try_grab_compound_head(pgd_page(orig), refs, flags);
> - if (!head)
> + folio = try_grab_folio(page, refs, flags);
> + if (!folio)
> return 0;
>
> if (unlikely(pgd_val(orig) != pgd_val(*pgdp))) {
> - put_compound_head(head, refs, flags);
> + gup_put_folio(folio, refs, flags);
> return 0;
> }
>
> *nr += refs;
> - SetPageReferenced(head);
> + folio_set_referenced(folio);
> return 1;
> }
>