All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Some more filemap folio conversions
@ 2023-01-16 19:39 Matthew Wilcox (Oracle)
  2023-01-16 19:39 ` [PATCH 1/3] filemap: Convert filemap_map_pmd() to take a folio Matthew Wilcox (Oracle)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-01-16 19:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

Three more places which could easily be converted to folios.  The third
one fixes a minor bug in readahead_expand(), but it's only a performance
bug and there's few users of readahead_expand(), so I don't think it's
worth backporting.

Matthew Wilcox (Oracle) (3):
  filemap: Convert filemap_map_pmd() to take a folio
  filemap: Convert filemap_range_has_page() to use a folio
  readahead: Convert readahead_expand() to use a folio

 mm/filemap.c   | 28 +++++++++++++++-------------
 mm/readahead.c | 39 ++++++++++++++++++++++-----------------
 2 files changed, 37 insertions(+), 30 deletions(-)

-- 
2.35.1



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

* [PATCH 1/3] filemap: Convert filemap_map_pmd() to take a folio
  2023-01-16 19:39 [PATCH 0/3] Some more filemap folio conversions Matthew Wilcox (Oracle)
@ 2023-01-16 19:39 ` Matthew Wilcox (Oracle)
  2023-01-16 19:39 ` [PATCH 2/3] filemap: Convert filemap_range_has_page() to use " Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-01-16 19:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

Save a few calls to compound_head().  We specify exactly which page from
the folio to use by passing in start_pgoff, which means this will work
for a folio which is larger than PMD size.  The rest of the VM isn't
prepared for that yet, but now this function is.

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

diff --git a/mm/filemap.c b/mm/filemap.c
index 31bf18ec6d01..b6b7efc9abc0 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3259,22 +3259,24 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 }
 EXPORT_SYMBOL(filemap_fault);
 
-static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page)
+static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio,
+		pgoff_t start)
 {
 	struct mm_struct *mm = vmf->vma->vm_mm;
 
 	/* Huge page is mapped? No need to proceed. */
 	if (pmd_trans_huge(*vmf->pmd)) {
-		unlock_page(page);
-		put_page(page);
+		folio_unlock(folio);
+		folio_put(folio);
 		return true;
 	}
 
-	if (pmd_none(*vmf->pmd) && PageTransHuge(page)) {
+	if (pmd_none(*vmf->pmd) && folio_test_pmd_mappable(folio)) {
+		struct page *page = folio_file_page(folio, start);
 		vm_fault_t ret = do_set_pmd(vmf, page);
 		if (!ret) {
 			/* The page is mapped successfully, reference consumed. */
-			unlock_page(page);
+			folio_unlock(folio);
 			return true;
 		}
 	}
@@ -3284,8 +3286,8 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page)
 
 	/* See comment in handle_pte_fault() */
 	if (pmd_devmap_trans_unstable(vmf->pmd)) {
-		unlock_page(page);
-		put_page(page);
+		folio_unlock(folio);
+		folio_put(folio);
 		return true;
 	}
 
@@ -3368,7 +3370,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,
 	if (!folio)
 		goto out;
 
-	if (filemap_map_pmd(vmf, &folio->page)) {
+	if (filemap_map_pmd(vmf, folio, start_pgoff)) {
 		ret = VM_FAULT_NOPAGE;
 		goto out;
 	}
-- 
2.35.1



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

* [PATCH 2/3] filemap: Convert filemap_range_has_page() to use a folio
  2023-01-16 19:39 [PATCH 0/3] Some more filemap folio conversions Matthew Wilcox (Oracle)
  2023-01-16 19:39 ` [PATCH 1/3] filemap: Convert filemap_map_pmd() to take a folio Matthew Wilcox (Oracle)
@ 2023-01-16 19:39 ` Matthew Wilcox (Oracle)
  2023-01-16 19:39 ` [PATCH 3/3] readahead: Convert readahead_expand() " Matthew Wilcox (Oracle)
  2023-01-16 23:00 ` [PATCH 0/3] Some more filemap folio conversions William Kucharski
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-01-16 19:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

The folio isn't returned from this function, so this is an entirely
internal change.

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

diff --git a/mm/filemap.c b/mm/filemap.c
index b6b7efc9abc0..c915ded191f0 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -470,7 +470,7 @@ EXPORT_SYMBOL(filemap_flush);
 bool filemap_range_has_page(struct address_space *mapping,
 			   loff_t start_byte, loff_t end_byte)
 {
-	struct page *page;
+	struct folio *folio;
 	XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
 	pgoff_t max = end_byte >> PAGE_SHIFT;
 
@@ -479,11 +479,11 @@ bool filemap_range_has_page(struct address_space *mapping,
 
 	rcu_read_lock();
 	for (;;) {
-		page = xas_find(&xas, max);
-		if (xas_retry(&xas, page))
+		folio = xas_find(&xas, max);
+		if (xas_retry(&xas, folio))
 			continue;
 		/* Shadow entries don't count */
-		if (xa_is_value(page))
+		if (xa_is_value(folio))
 			continue;
 		/*
 		 * We don't need to try to pin this page; we're about to
@@ -494,7 +494,7 @@ bool filemap_range_has_page(struct address_space *mapping,
 	}
 	rcu_read_unlock();
 
-	return page != NULL;
+	return folio != NULL;
 }
 EXPORT_SYMBOL(filemap_range_has_page);
 
-- 
2.35.1



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

* [PATCH 3/3] readahead: Convert readahead_expand() to use a folio
  2023-01-16 19:39 [PATCH 0/3] Some more filemap folio conversions Matthew Wilcox (Oracle)
  2023-01-16 19:39 ` [PATCH 1/3] filemap: Convert filemap_map_pmd() to take a folio Matthew Wilcox (Oracle)
  2023-01-16 19:39 ` [PATCH 2/3] filemap: Convert filemap_range_has_page() to use " Matthew Wilcox (Oracle)
@ 2023-01-16 19:39 ` Matthew Wilcox (Oracle)
  2023-01-16 23:00 ` [PATCH 0/3] Some more filemap folio conversions William Kucharski
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-01-16 19:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

Replace the uses of page with a folio.  Also add a missing test
for workingset in the leading edge expansion.

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

diff --git a/mm/readahead.c b/mm/readahead.c
index b10f0cf81d80..47afbca1d122 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -801,21 +801,25 @@ void readahead_expand(struct readahead_control *ractl,
 	/* Expand the leading edge downwards */
 	while (ractl->_index > new_index) {
 		unsigned long index = ractl->_index - 1;
-		struct page *page = xa_load(&mapping->i_pages, index);
+		struct folio *folio = xa_load(&mapping->i_pages, index);
 
-		if (page && !xa_is_value(page))
-			return; /* Page apparently present */
+		if (folio && !xa_is_value(folio))
+			return; /* Folio apparently present */
 
-		page = __page_cache_alloc(gfp_mask);
-		if (!page)
+		folio = filemap_alloc_folio(gfp_mask, 0);
+		if (!folio)
 			return;
-		if (add_to_page_cache_lru(page, mapping, index, gfp_mask) < 0) {
-			put_page(page);
+		if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) {
+			folio_put(folio);
 			return;
 		}
-
+		if (unlikely(folio_test_workingset(folio)) &&
+				!ractl->_workingset) {
+			ractl->_workingset = true;
+			psi_memstall_enter(&ractl->_pflags);
+		}
 		ractl->_nr_pages++;
-		ractl->_index = page->index;
+		ractl->_index = folio->index;
 	}
 
 	new_len += new_start - readahead_pos(ractl);
@@ -824,19 +828,20 @@ void readahead_expand(struct readahead_control *ractl,
 	/* Expand the trailing edge upwards */
 	while (ractl->_nr_pages < new_nr_pages) {
 		unsigned long index = ractl->_index + ractl->_nr_pages;
-		struct page *page = xa_load(&mapping->i_pages, index);
+		struct folio *folio = xa_load(&mapping->i_pages, index);
 
-		if (page && !xa_is_value(page))
-			return; /* Page apparently present */
+		if (folio && !xa_is_value(folio))
+			return; /* Folio apparently present */
 
-		page = __page_cache_alloc(gfp_mask);
-		if (!page)
+		folio = filemap_alloc_folio(gfp_mask, 0);
+		if (!folio)
 			return;
-		if (add_to_page_cache_lru(page, mapping, index, gfp_mask) < 0) {
-			put_page(page);
+		if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) {
+			folio_put(folio);
 			return;
 		}
-		if (unlikely(PageWorkingset(page)) && !ractl->_workingset) {
+		if (unlikely(folio_test_workingset(folio)) &&
+				!ractl->_workingset) {
 			ractl->_workingset = true;
 			psi_memstall_enter(&ractl->_pflags);
 		}
-- 
2.35.1



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

* Re: [PATCH 0/3] Some more filemap folio conversions
  2023-01-16 19:39 [PATCH 0/3] Some more filemap folio conversions Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2023-01-16 19:39 ` [PATCH 3/3] readahead: Convert readahead_expand() " Matthew Wilcox (Oracle)
@ 2023-01-16 23:00 ` William Kucharski
  3 siblings, 0 replies; 5+ messages in thread
From: William Kucharski @ 2023-01-16 23:00 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle); +Cc: Andrew Morton, linux-mm

These all look good to me.

Reviewed-by: William Kucharski <william.kucharski@oracle.com>


> On Jan 16, 2023, at 12:39 PM, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> Three more places which could easily be converted to folios.  The third
> one fixes a minor bug in readahead_expand(), but it's only a performance
> bug and there's few users of readahead_expand(), so I don't think it's
> worth backporting.
> 
> Matthew Wilcox (Oracle) (3):
>  filemap: Convert filemap_map_pmd() to take a folio
>  filemap: Convert filemap_range_has_page() to use a folio
>  readahead: Convert readahead_expand() to use a folio
> 
> mm/filemap.c   | 28 +++++++++++++++-------------
> mm/readahead.c | 39 ++++++++++++++++++++++-----------------
> 2 files changed, 37 insertions(+), 30 deletions(-)
> 
> -- 
> 2.35.1
> 
> 



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

end of thread, other threads:[~2023-01-16 23:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16 19:39 [PATCH 0/3] Some more filemap folio conversions Matthew Wilcox (Oracle)
2023-01-16 19:39 ` [PATCH 1/3] filemap: Convert filemap_map_pmd() to take a folio Matthew Wilcox (Oracle)
2023-01-16 19:39 ` [PATCH 2/3] filemap: Convert filemap_range_has_page() to use " Matthew Wilcox (Oracle)
2023-01-16 19:39 ` [PATCH 3/3] readahead: Convert readahead_expand() " Matthew Wilcox (Oracle)
2023-01-16 23:00 ` [PATCH 0/3] Some more filemap folio conversions William Kucharski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.