Linux-mm Archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] More folio compat code removal
@ 2024-04-24 19:19 Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 1/7] mm: Remove page_cache_alloc() Matthew Wilcox (Oracle)
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

More code removal with bonus kernel-doc addition.

Matthew Wilcox (Oracle) (7):
  mm: Remove page_cache_alloc()
  mm: Remove put_devmap_managed_page()
  mm: Convert put_devmap_managed_page_refs() to
    put_devmap_managed_folio_refs()
  mm: Remove page_ref_sub_return()
  gup: Use folios for gup_devmap
  mm: Add kernel-doc for folio_mark_accessed()
  mm: Remove PageReferenced

 include/linux/mm.h         | 17 ++++++-----------
 include/linux/page-flags.h |  6 +++---
 include/linux/page_ref.h   | 11 +++--------
 include/linux/pagemap.h    |  5 -----
 mm/gup.c                   | 23 +++++++++++------------
 mm/memremap.c              | 10 +++++-----
 mm/swap.c                  | 19 +++++++++++--------
 7 files changed, 39 insertions(+), 52 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/7] mm: Remove page_cache_alloc()
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 2/7] mm: Remove put_devmap_managed_page() Matthew Wilcox (Oracle)
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

All callers have now been converted to filemap_alloc_folio().

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

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 941f7ed714b9..1dcaf86fb615 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -557,11 +557,6 @@ static inline struct page *__page_cache_alloc(gfp_t gfp)
 	return &filemap_alloc_folio(gfp, 0)->page;
 }
 
-static inline struct page *page_cache_alloc(struct address_space *x)
-{
-	return __page_cache_alloc(mapping_gfp_mask(x));
-}
-
 static inline gfp_t readahead_gfp_mask(struct address_space *x)
 {
 	return mapping_gfp_mask(x) | __GFP_NORETRY | __GFP_NOWARN;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/7] mm: Remove put_devmap_managed_page()
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 1/7] mm: Remove page_cache_alloc() Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 3/7] mm: Convert put_devmap_managed_page_refs() to put_devmap_managed_folio_refs() Matthew Wilcox (Oracle)
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

It only has one caller; convert that caller to use
put_devmap_managed_page_refs() instead.

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

diff --git a/include/linux/mm.h b/include/linux/mm.h
index e36db5e4509b..070a6e2d7222 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1453,11 +1453,6 @@ static inline bool put_devmap_managed_page_refs(struct page *page, int refs)
 }
 #endif /* CONFIG_ZONE_DEVICE && CONFIG_FS_DAX */
 
-static inline bool put_devmap_managed_page(struct page *page)
-{
-	return put_devmap_managed_page_refs(page, 1);
-}
-
 /* 127: arbitrary random number, small enough to assemble well */
 #define folio_ref_zero_or_close_to_overflow(folio) \
 	((unsigned int) folio_ref_count(folio) + 127u <= 127u)
@@ -1576,7 +1571,7 @@ static inline void put_page(struct page *page)
 	 * For some devmap managed pages we need to catch refcount transition
 	 * from 2 to 1:
 	 */
-	if (put_devmap_managed_page(&folio->page))
+	if (put_devmap_managed_page_refs(&folio->page, 1))
 		return;
 	folio_put(folio);
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/7] mm: Convert put_devmap_managed_page_refs() to put_devmap_managed_folio_refs()
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 1/7] mm: Remove page_cache_alloc() Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 2/7] mm: Remove put_devmap_managed_page() Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 4/7] mm: Remove page_ref_sub_return() Matthew Wilcox (Oracle)
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

All callers have a folio so we can remove this use of
page_ref_sub_return().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/mm.h | 12 ++++++------
 mm/gup.c           |  6 +++---
 mm/memremap.c      | 10 +++++-----
 mm/swap.c          |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 070a6e2d7222..19d0ec4f43f4 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1437,17 +1437,17 @@ vm_fault_t finish_fault(struct vm_fault *vmf);
 #if defined(CONFIG_ZONE_DEVICE) && defined(CONFIG_FS_DAX)
 DECLARE_STATIC_KEY_FALSE(devmap_managed_key);
 
-bool __put_devmap_managed_page_refs(struct page *page, int refs);
-static inline bool put_devmap_managed_page_refs(struct page *page, int refs)
+bool __put_devmap_managed_folio_refs(struct folio *folio, int refs);
+static inline bool put_devmap_managed_folio_refs(struct folio *folio, int refs)
 {
 	if (!static_branch_unlikely(&devmap_managed_key))
 		return false;
-	if (!is_zone_device_page(page))
+	if (!folio_is_zone_device(folio))
 		return false;
-	return __put_devmap_managed_page_refs(page, refs);
+	return __put_devmap_managed_folio_refs(folio, refs);
 }
 #else /* CONFIG_ZONE_DEVICE && CONFIG_FS_DAX */
-static inline bool put_devmap_managed_page_refs(struct page *page, int refs)
+static inline bool put_devmap_managed_folio_refs(struct folio *folio, int refs)
 {
 	return false;
 }
@@ -1571,7 +1571,7 @@ static inline void put_page(struct page *page)
 	 * For some devmap managed pages we need to catch refcount transition
 	 * from 2 to 1:
 	 */
-	if (put_devmap_managed_page_refs(&folio->page, 1))
+	if (put_devmap_managed_folio_refs(folio, 1))
 		return;
 	folio_put(folio);
 }
diff --git a/mm/gup.c b/mm/gup.c
index b797424f78ef..49376f756936 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -89,7 +89,7 @@ static inline struct folio *try_get_folio(struct page *page, int refs)
 	 * belongs to this folio.
 	 */
 	if (unlikely(page_folio(page) != folio)) {
-		if (!put_devmap_managed_page_refs(&folio->page, refs))
+		if (!put_devmap_managed_folio_refs(folio, refs))
 			folio_put_refs(folio, refs);
 		goto retry;
 	}
@@ -156,7 +156,7 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags)
 	 */
 	if (unlikely((flags & FOLL_LONGTERM) &&
 		     !folio_is_longterm_pinnable(folio))) {
-		if (!put_devmap_managed_page_refs(&folio->page, refs))
+		if (!put_devmap_managed_folio_refs(folio, refs))
 			folio_put_refs(folio, refs);
 		return NULL;
 	}
@@ -198,7 +198,7 @@ static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
 			refs *= GUP_PIN_COUNTING_BIAS;
 	}
 
-	if (!put_devmap_managed_page_refs(&folio->page, refs))
+	if (!put_devmap_managed_folio_refs(folio, refs))
 		folio_put_refs(folio, refs);
 }
 
diff --git a/mm/memremap.c b/mm/memremap.c
index e1776693e2ea..40d4547ce514 100644
--- a/mm/memremap.c
+++ b/mm/memremap.c
@@ -512,9 +512,9 @@ void zone_device_page_init(struct page *page)
 EXPORT_SYMBOL_GPL(zone_device_page_init);
 
 #ifdef CONFIG_FS_DAX
-bool __put_devmap_managed_page_refs(struct page *page, int refs)
+bool __put_devmap_managed_folio_refs(struct folio *folio, int refs)
 {
-	if (page->pgmap->type != MEMORY_DEVICE_FS_DAX)
+	if (folio->page.pgmap->type != MEMORY_DEVICE_FS_DAX)
 		return false;
 
 	/*
@@ -522,9 +522,9 @@ bool __put_devmap_managed_page_refs(struct page *page, int refs)
 	 * refcount is 1, then the page is free and the refcount is
 	 * stable because nobody holds a reference on the page.
 	 */
-	if (page_ref_sub_return(page, refs) == 1)
-		wake_up_var(&page->_refcount);
+	if (folio_ref_sub_return(folio, refs) == 1)
+		wake_up_var(&folio->_refcount);
 	return true;
 }
-EXPORT_SYMBOL(__put_devmap_managed_page_refs);
+EXPORT_SYMBOL(__put_devmap_managed_folio_refs);
 #endif /* CONFIG_FS_DAX */
diff --git a/mm/swap.c b/mm/swap.c
index f0d478eee292..f29b3018ba3a 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -981,7 +981,7 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs)
 				unlock_page_lruvec_irqrestore(lruvec, flags);
 				lruvec = NULL;
 			}
-			if (put_devmap_managed_page_refs(&folio->page, nr_refs))
+			if (put_devmap_managed_folio_refs(folio, nr_refs))
 				continue;
 			if (folio_ref_sub_and_test(folio, nr_refs))
 				free_zone_device_folio(folio);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/7] mm: Remove page_ref_sub_return()
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2024-04-24 19:19 ` [PATCH 3/7] mm: Convert put_devmap_managed_page_refs() to put_devmap_managed_folio_refs() Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 5/7] gup: Use folios for gup_devmap Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

With all callers converted to folios, we can act directly on
folio->_refcount.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/page_ref.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
index d7c2d33baa7f..1acf5bac7f50 100644
--- a/include/linux/page_ref.h
+++ b/include/linux/page_ref.h
@@ -139,20 +139,15 @@ static inline void folio_ref_sub(struct folio *folio, int nr)
 	page_ref_sub(&folio->page, nr);
 }
 
-static inline int page_ref_sub_return(struct page *page, int nr)
+static inline int folio_ref_sub_return(struct folio *folio, int nr)
 {
-	int ret = atomic_sub_return(nr, &page->_refcount);
+	int ret = atomic_sub_return(nr, &folio->_refcount);
 
 	if (page_ref_tracepoint_active(page_ref_mod_and_return))
-		__page_ref_mod_and_return(page, -nr, ret);
+		__page_ref_mod_and_return(&folio->page, -nr, ret);
 	return ret;
 }
 
-static inline int folio_ref_sub_return(struct folio *folio, int nr)
-{
-	return page_ref_sub_return(&folio->page, nr);
-}
-
 static inline void page_ref_inc(struct page *page)
 {
 	atomic_inc(&page->_refcount);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/7] gup: Use folios for gup_devmap
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
                   ` (3 preceding siblings ...)
  2024-04-24 19:19 ` [PATCH 4/7] mm: Remove page_ref_sub_return() Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  2024-04-25  9:49   ` David Hildenbrand
  2024-04-24 19:19 ` [PATCH 6/7] mm: Add kernel-doc for folio_mark_accessed() Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 7/7] mm: Remove PageReferenced Matthew Wilcox (Oracle)
  6 siblings, 1 reply; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

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.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/gup.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 49376f756936..e4cc12b8e985 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -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);
 	}
 }
 
@@ -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);
@@ -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);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/7] mm: Add kernel-doc for folio_mark_accessed()
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
                   ` (4 preceding siblings ...)
  2024-04-24 19:19 ` [PATCH 5/7] gup: Use folios for gup_devmap Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  2024-04-24 19:19 ` [PATCH 7/7] mm: Remove PageReferenced Matthew Wilcox (Oracle)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

Convert the existing documentation to kernel-doc and remove
references to pages.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/swap.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/mm/swap.c b/mm/swap.c
index f29b3018ba3a..73bebd3ca6b7 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -448,15 +448,18 @@ static void folio_inc_refs(struct folio *folio)
 }
 #endif /* CONFIG_LRU_GEN */
 
-/*
- * Mark a page as having seen activity.
+/**
+ * folio_mark_accessed - Mark a folio as having seen activity.
+ * @folio: The folio to mark.
+ *
+ * This function will perform one of the following transitions:
  *
- * inactive,unreferenced	->	inactive,referenced
- * inactive,referenced		->	active,unreferenced
- * active,unreferenced		->	active,referenced
+ * * inactive,unreferenced	->	inactive,referenced
+ * * inactive,referenced	->	active,unreferenced
+ * * active,unreferenced	->	active,referenced
  *
- * When a newly allocated page is not yet visible, so safe for non-atomic ops,
- * __SetPageReferenced(page) may be substituted for mark_page_accessed(page).
+ * When a newly allocated folio is not yet visible, so safe for non-atomic ops,
+ * __folio_set_referenced() may be substituted for folio_mark_accessed().
  */
 void folio_mark_accessed(struct folio *folio)
 {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/7] mm: Remove PageReferenced
  2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
                   ` (5 preceding siblings ...)
  2024-04-24 19:19 ` [PATCH 6/7] mm: Add kernel-doc for folio_mark_accessed() Matthew Wilcox (Oracle)
@ 2024-04-24 19:19 ` Matthew Wilcox (Oracle)
  6 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-24 19:19 UTC (permalink / raw
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

All callers now use folio_*_referenced() so we can remove the
PageReferenced family of functions.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/page-flags.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 5a5f84d75f31..c79f78d0ab72 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -508,9 +508,9 @@ static inline int TestClearPage##uname(struct page *page) { return 0; }
 
 __PAGEFLAG(Locked, locked, PF_NO_TAIL)
 FOLIO_FLAG(waiters, FOLIO_HEAD_PAGE)
-PAGEFLAG(Referenced, referenced, PF_HEAD)
-	TESTCLEARFLAG(Referenced, referenced, PF_HEAD)
-	__SETPAGEFLAG(Referenced, referenced, PF_HEAD)
+FOLIO_FLAG(referenced, FOLIO_HEAD_PAGE)
+	FOLIO_TEST_CLEAR_FLAG(referenced, FOLIO_HEAD_PAGE)
+	__FOLIO_SET_FLAG(referenced, FOLIO_HEAD_PAGE)
 PAGEFLAG(Dirty, dirty, PF_HEAD) TESTSCFLAG(Dirty, dirty, PF_HEAD)
 	__CLEARPAGEFLAG(Dirty, dirty, PF_HEAD)
 PAGEFLAG(LRU, lru, PF_HEAD) __CLEARPAGEFLAG(LRU, lru, PF_HEAD)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/7] gup: Use folios for gup_devmap
  2024-04-24 19:19 ` [PATCH 5/7] gup: Use folios for gup_devmap Matthew Wilcox (Oracle)
@ 2024-04-25  9:49   ` David Hildenbrand
  2024-04-25 12:43     ` Matthew Wilcox
  0 siblings, 1 reply; 10+ messages in thread
From: David Hildenbrand @ 2024-04-25  9:49 UTC (permalink / raw
  To: Matthew Wilcox (Oracle), Andrew Morton; +Cc: linux-mm

On 24.04.24 21:19, Matthew Wilcox (Oracle) wrote:

Nit: s/gup_devmap/gup_fast_devmap/

> 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.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>   mm/gup.c | 17 ++++++++---------
>   1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index 49376f756936..e4cc12b8e985 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -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);

I stumbled over that likely unwarranted ClearPageReferenced() recently 
as well: what if the page was already referenced before we called 
SetPageReferenced?

> -		if (flags & FOLL_PIN)
> -			unpin_user_page(page);
> -		else
> -			put_page(page);
> +		folio_clear_referenced(folio);
> +		gup_put_folio(folio, 1, flags);

For !FOLL_PIN, we wouldn't have done the
	if (!put_devmap_managed_page_refs(&folio->page, refs))
		folio_put_refs(folio, refs);

Magic in gup_put_folio()

... was that a BUG?


This devmap crap is so confusing.

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/7] gup: Use folios for gup_devmap
  2024-04-25  9:49   ` David Hildenbrand
@ 2024-04-25 12:43     ` Matthew Wilcox
  0 siblings, 0 replies; 10+ messages in thread
From: Matthew Wilcox @ 2024-04-25 12:43 UTC (permalink / raw
  To: David Hildenbrand; +Cc: Andrew Morton, linux-mm

On Thu, Apr 25, 2024 at 11:49:01AM +0200, David Hildenbrand wrote:
> >   	while ((*nr) - nr_start) {
> > -		struct page *page = pages[--(*nr)];
> > +		struct folio *folio = page_folio(pages[--(*nr)]);
> > -		ClearPageReferenced(page);
> 
> I stumbled over that likely unwarranted ClearPageReferenced() recently as
> well: what if the page was already referenced before we called
> SetPageReferenced?

Yes, it seems bizarre.  I imagine the person who wrote this was trying
to undo everything, but no other cleanup path calls
folio_clear_referenced().  I don't object to taking it out.

> > -		if (flags & FOLL_PIN)
> > -			unpin_user_page(page);
> > -		else
> > -			put_page(page);
> > +		folio_clear_referenced(folio);
> > +		gup_put_folio(folio, 1, flags);
> 
> For !FOLL_PIN, we wouldn't have done the
> 	if (!put_devmap_managed_page_refs(&folio->page, refs))
> 		folio_put_refs(folio, refs);
> 
> Magic in gup_put_folio()
> 
> ... was that a BUG?

I think so.  But probably nobody noticed because it's an error path.
Also nobody noticed that we shouldn't have called SetPageReferenced()
before getting the refcount on the page.  I didn't bother mentioning it
in the changelog because I think it's harmless, just conceptually wrong.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-25 12:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-24 19:19 [PATCH 0/7] More folio compat code removal Matthew Wilcox (Oracle)
2024-04-24 19:19 ` [PATCH 1/7] mm: Remove page_cache_alloc() Matthew Wilcox (Oracle)
2024-04-24 19:19 ` [PATCH 2/7] mm: Remove put_devmap_managed_page() Matthew Wilcox (Oracle)
2024-04-24 19:19 ` [PATCH 3/7] mm: Convert put_devmap_managed_page_refs() to put_devmap_managed_folio_refs() Matthew Wilcox (Oracle)
2024-04-24 19:19 ` [PATCH 4/7] mm: Remove page_ref_sub_return() Matthew Wilcox (Oracle)
2024-04-24 19:19 ` [PATCH 5/7] gup: Use folios for gup_devmap Matthew Wilcox (Oracle)
2024-04-25  9:49   ` David Hildenbrand
2024-04-25 12:43     ` Matthew Wilcox
2024-04-24 19:19 ` [PATCH 6/7] mm: Add kernel-doc for folio_mark_accessed() Matthew Wilcox (Oracle)
2024-04-24 19:19 ` [PATCH 7/7] mm: Remove PageReferenced Matthew Wilcox (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).