Re: [PATCH 15/17] gup: Convert for_each_compound_range() to gup_for_each_folio_range()

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

 



On 1/2/22 13:57, Matthew Wilcox (Oracle) wrote:
This macro can be considerably simplified by returning the folio from
gup_folio_range_next() instead of void from compound_next().  Convert the
only caller to work on folios instead of pages.

This removes the last caller of put_compound_head(), so delete it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
---
  mm/gup.c | 50 +++++++++++++++++++++++---------------------------
  1 file changed, 23 insertions(+), 27 deletions(-)


Reviewed-by: John Hubbard <jhubbard@xxxxxxxxxx>


thanks,
--
John Hubbard
NVIDIA

diff --git a/mm/gup.c b/mm/gup.c
index eaffa6807609..76717e05413d 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -165,12 +165,6 @@ static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
  	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);
-}
-
  /**
   * try_grab_page() - elevate a page's refcount by a flag-dependent amount
   *
@@ -213,31 +207,30 @@ void unpin_user_page(struct page *page)
  }
  EXPORT_SYMBOL(unpin_user_page);
-static inline void compound_range_next(unsigned long i, unsigned long npages,
-				       struct page **list, struct page **head,
-				       unsigned int *ntails)
+static inline struct folio *gup_folio_range_next(unsigned long i,
+		unsigned long npages, struct page **list, unsigned int *ntails)
  {
-	struct page *next, *page;
+	struct page *next;
+	struct folio *folio;
  	unsigned int nr = 1;
if (i >= npages)
-		return;
+		return NULL;
next = *list + i;
-	page = compound_head(next);
-	if (PageCompound(page) && compound_order(page) >= 1)
-		nr = min_t(unsigned int,
-			   page + compound_nr(page) - next, npages - i);
+	folio = page_folio(next);
+	if (folio_test_large(folio))
+		nr = min_t(unsigned int, npages - i,
+			   &folio->page + folio_nr_pages(folio) - next);
- *head = page;
  	*ntails = nr;
+	return folio;
  }
-#define for_each_compound_range(__i, __list, __npages, __head, __ntails) \
-	for (__i = 0, \
-	     compound_range_next(__i, __npages, __list, &(__head), &(__ntails)); \
-	     __i < __npages; __i += __ntails, \
-	     compound_range_next(__i, __npages, __list, &(__head), &(__ntails)))
+#define gup_for_each_folio_range(__i, __list, __npages, __folio, __ntails) \
+	for (__i = 0; \
+	     (__folio = gup_folio_range_next(__i, __npages, __list, &(__ntails))) != NULL; \
+	     __i += __ntails)
static inline struct folio *gup_folio_next(unsigned long i,
  		unsigned long npages, struct page **list, unsigned int *ntails)
@@ -353,13 +346,16 @@ void unpin_user_page_range_dirty_lock(struct page *page, unsigned long npages,
  				      bool make_dirty)
  {
  	unsigned long index;
-	struct page *head;
-	unsigned int ntails;
+	struct folio *folio;
+	unsigned int nr;
- for_each_compound_range(index, &page, npages, head, ntails) {
-		if (make_dirty && !PageDirty(head))
-			set_page_dirty_lock(head);
-		put_compound_head(head, ntails, FOLL_PIN);
+	gup_for_each_folio_range(index, &page, npages, folio, nr) {
+		if (make_dirty && !folio_test_dirty(folio)) {
+			folio_lock(folio);
+			folio_mark_dirty(folio);
+			folio_unlock(folio);
+		}
+		gup_put_folio(folio, nr, FOLL_PIN);
  	}
  }
  EXPORT_SYMBOL(unpin_user_page_range_dirty_lock);




[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