Skip to content

Commit

Permalink
gup: use folios for gup_devmap
Browse files Browse the repository at this point in the history
Use try_grab_folio() instead of try_grab_page() so we get the folio back
that we calculated, and then use folio_set_referenced() instead of
SetPageReferenced().  Correspondingly, use gup_put_folio() to put any
unneeded references.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) authored and akpm00 committed May 6, 2024
1 parent 498aefb commit 9cbe495
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2877,13 +2877,10 @@ static void __maybe_unused gup_fast_undo_dev_pagemap(int *nr, int nr_start,
unsigned int flags, struct page **pages)
{
while ((*nr) - nr_start) {
struct page *page = pages[--(*nr)];
struct folio *folio = page_folio(pages[--(*nr)]);

ClearPageReferenced(page);
if (flags & FOLL_PIN)
unpin_user_page(page);
else
put_page(page);
folio_clear_referenced(folio);
gup_put_folio(folio, 1, flags);
}
}

Expand Down Expand Up @@ -3024,6 +3021,7 @@ static int gup_fast_devmap_leaf(unsigned long pfn, unsigned long addr,
struct dev_pagemap *pgmap = NULL;

do {
struct folio *folio;
struct page *page = pfn_to_page(pfn);

pgmap = get_dev_pagemap(pfn, pgmap);
Expand All @@ -3037,12 +3035,13 @@ static int gup_fast_devmap_leaf(unsigned long pfn, unsigned long addr,
break;
}

SetPageReferenced(page);
pages[*nr] = page;
if (unlikely(try_grab_page(page, flags))) {
folio = try_grab_folio(page, 1, flags);
if (!folio) {
gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages);
break;
}
folio_set_referenced(folio);
pages[*nr] = page;
(*nr)++;
pfn++;
} while (addr += PAGE_SIZE, addr != end);
Expand Down

0 comments on commit 9cbe495

Please sign in to comment.