linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] ITER_XARRAY cleanups and consequences
@ 2025-03-03 17:53 Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 1/6] iov_iter: Convert iter_xarray_populate_pages() to use folios Matthew Wilcox (Oracle)
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

iov_iter currently extracts pages from the xarray when only folios have
been stored there.  This needs to be fixed before we can separate struct
folio from struct page.  __readahead_batch() is in the same situation,
and converting all three of these places lets us remove find_subpage()
and thp_nr_pages().  Removing readahead_page_batch() isn't particularly
related to these changes, but it may as well go in with this batch.

Matthew Wilcox (Oracle) (6):
  iov_iter: Convert iter_xarray_populate_pages() to use folios
  iov_iter: Convert iov_iter_extract_xarray_pages() to use folios
  pagemap: Remove find_subpage()
  filemap: Convert __readahead_batch() to use a folio
  pagemap: Remove readahead_page_batch()
  mm: Delete thp_nr_pages()

 include/linux/mm.h      |  9 ---------
 include/linux/pagemap.h | 40 ++++++----------------------------------
 lib/iov_iter.c          | 30 +++++++++++++++---------------
 3 files changed, 21 insertions(+), 58 deletions(-)

-- 
2.47.2



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

* [PATCH 1/6] iov_iter: Convert iter_xarray_populate_pages() to use folios
  2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
@ 2025-03-03 17:53 ` Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 2/6] iov_iter: Convert iov_iter_extract_xarray_pages() " Matthew Wilcox (Oracle)
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

ITER_XARRAY is exclusively used with xarrays that contain folios,
not pages, so extract folio pointers from it, not page pointers.
Removes a hidden call to compound_head() and a use of find_subpage().

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

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 65f550cb5081..92642f517999 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1059,22 +1059,22 @@ static ssize_t iter_xarray_populate_pages(struct page **pages, struct xarray *xa
 					  pgoff_t index, unsigned int nr_pages)
 {
 	XA_STATE(xas, xa, index);
-	struct page *page;
+	struct folio *folio;
 	unsigned int ret = 0;
 
 	rcu_read_lock();
-	for (page = xas_load(&xas); page; page = xas_next(&xas)) {
-		if (xas_retry(&xas, page))
+	for (folio = xas_load(&xas); folio; folio = xas_next(&xas)) {
+		if (xas_retry(&xas, folio))
 			continue;
 
-		/* Has the page moved or been split? */
-		if (unlikely(page != xas_reload(&xas))) {
+		/* Has the folio moved or been split? */
+		if (unlikely(folio != xas_reload(&xas))) {
 			xas_reset(&xas);
 			continue;
 		}
 
-		pages[ret] = find_subpage(page, xas.xa_index);
-		get_page(pages[ret]);
+		pages[ret] = folio_file_page(folio, xas.xa_index);
+		folio_get(folio);
 		if (++ret == nr_pages)
 			break;
 	}
-- 
2.47.2



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

* [PATCH 2/6] iov_iter: Convert iov_iter_extract_xarray_pages() to use folios
  2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 1/6] iov_iter: Convert iter_xarray_populate_pages() to use folios Matthew Wilcox (Oracle)
@ 2025-03-03 17:53 ` Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 3/6] pagemap: Remove find_subpage() Matthew Wilcox (Oracle)
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

ITER_XARRAY is exclusively used with xarrays that contain folios,
not pages, so extract folio pointers from it, not page pointers.
Removes a use of find_subpage().

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

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 92642f517999..c85ae372bc05 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1646,11 +1646,11 @@ static ssize_t iov_iter_extract_xarray_pages(struct iov_iter *i,
 					     iov_iter_extraction_t extraction_flags,
 					     size_t *offset0)
 {
-	struct page *page, **p;
+	struct page **p;
+	struct folio *folio;
 	unsigned int nr = 0, offset;
 	loff_t pos = i->xarray_start + i->iov_offset;
-	pgoff_t index = pos >> PAGE_SHIFT;
-	XA_STATE(xas, i->xarray, index);
+	XA_STATE(xas, i->xarray, pos >> PAGE_SHIFT);
 
 	offset = pos & ~PAGE_MASK;
 	*offset0 = offset;
@@ -1661,17 +1661,17 @@ static ssize_t iov_iter_extract_xarray_pages(struct iov_iter *i,
 	p = *pages;
 
 	rcu_read_lock();
-	for (page = xas_load(&xas); page; page = xas_next(&xas)) {
-		if (xas_retry(&xas, page))
+	for (folio = xas_load(&xas); folio; folio = xas_next(&xas)) {
+		if (xas_retry(&xas, folio))
 			continue;
 
-		/* Has the page moved or been split? */
-		if (unlikely(page != xas_reload(&xas))) {
+		/* Has the folio moved or been split? */
+		if (unlikely(folio != xas_reload(&xas))) {
 			xas_reset(&xas);
 			continue;
 		}
 
-		p[nr++] = find_subpage(page, xas.xa_index);
+		p[nr++] = folio_file_page(folio, xas.xa_index);
 		if (nr == maxpages)
 			break;
 	}
-- 
2.47.2



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

* [PATCH 3/6] pagemap: Remove find_subpage()
  2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 1/6] iov_iter: Convert iter_xarray_populate_pages() to use folios Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 2/6] iov_iter: Convert iov_iter_extract_xarray_pages() " Matthew Wilcox (Oracle)
@ 2025-03-03 17:53 ` Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 4/6] filemap: Convert __readahead_batch() to use a folio Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

All users of this function now call folio_file_page() instead.
Delete it.

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

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 798e2e39c6e2..e51c0febd036 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -945,19 +945,6 @@ static inline bool folio_contains(struct folio *folio, pgoff_t index)
 	return index - folio_index(folio) < folio_nr_pages(folio);
 }
 
-/*
- * Given the page we found in the page cache, return the page corresponding
- * to this index in the file
- */
-static inline struct page *find_subpage(struct page *head, pgoff_t index)
-{
-	/* HugeTLBfs wants the head page regardless */
-	if (PageHuge(head))
-		return head;
-
-	return head + (index & (thp_nr_pages(head) - 1));
-}
-
 unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
 		pgoff_t end, struct folio_batch *fbatch);
 unsigned filemap_get_folios_contig(struct address_space *mapping,
-- 
2.47.2



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

* [PATCH 4/6] filemap: Convert __readahead_batch() to use a folio
  2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2025-03-03 17:53 ` [PATCH 3/6] pagemap: Remove find_subpage() Matthew Wilcox (Oracle)
@ 2025-03-03 17:53 ` Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 5/6] pagemap: Remove readahead_page_batch() Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 6/6] mm: Delete thp_nr_pages() Matthew Wilcox (Oracle)
  5 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

Extract folios from i_mapping, not pages.  Removes a hidden call to
compound_head(), a use of thp_nr_pages() and an unnecessary assertion
that we didn't find a tail page in the page cache.

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

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index e51c0febd036..f4b875b561e5 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1449,7 +1449,7 @@ static inline unsigned int __readahead_batch(struct readahead_control *rac,
 {
 	unsigned int i = 0;
 	XA_STATE(xas, &rac->mapping->i_pages, 0);
-	struct page *page;
+	struct folio *folio;
 
 	BUG_ON(rac->_batch_count > rac->_nr_pages);
 	rac->_nr_pages -= rac->_batch_count;
@@ -1458,13 +1458,12 @@ static inline unsigned int __readahead_batch(struct readahead_control *rac,
 
 	xas_set(&xas, rac->_index);
 	rcu_read_lock();
-	xas_for_each(&xas, page, rac->_index + rac->_nr_pages - 1) {
-		if (xas_retry(&xas, page))
+	xas_for_each(&xas, folio, rac->_index + rac->_nr_pages - 1) {
+		if (xas_retry(&xas, folio))
 			continue;
-		VM_BUG_ON_PAGE(!PageLocked(page), page);
-		VM_BUG_ON_PAGE(PageTail(page), page);
-		array[i++] = page;
-		rac->_batch_count += thp_nr_pages(page);
+		VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
+		array[i++] = folio_page(folio, 0);
+		rac->_batch_count += folio_nr_pages(folio);
 		if (i == array_sz)
 			break;
 	}
-- 
2.47.2



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

* [PATCH 5/6] pagemap: Remove readahead_page_batch()
  2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
                   ` (3 preceding siblings ...)
  2025-03-03 17:53 ` [PATCH 4/6] filemap: Convert __readahead_batch() to use a folio Matthew Wilcox (Oracle)
@ 2025-03-03 17:53 ` Matthew Wilcox (Oracle)
  2025-03-03 17:53 ` [PATCH 6/6] mm: Delete thp_nr_pages() Matthew Wilcox (Oracle)
  5 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

This function has no more callers; delete it.

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

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index f4b875b561e5..4a1c9dc92d82 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1472,20 +1472,6 @@ static inline unsigned int __readahead_batch(struct readahead_control *rac,
 	return i;
 }
 
-/**
- * readahead_page_batch - Get a batch of pages to read.
- * @rac: The current readahead request.
- * @array: An array of pointers to struct page.
- *
- * Context: The pages are locked and have an elevated refcount.  The caller
- * should decreases the refcount once the page has been submitted for I/O
- * and unlock the page once all I/O to that page has completed.
- * Return: The number of pages placed in the array.  0 indicates the request
- * is complete.
- */
-#define readahead_page_batch(rac, array)				\
-	__readahead_batch(rac, array, ARRAY_SIZE(array))
-
 /**
  * readahead_pos - The byte offset into the file of this readahead request.
  * @rac: The readahead request.
-- 
2.47.2



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

* [PATCH 6/6] mm: Delete thp_nr_pages()
  2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
                   ` (4 preceding siblings ...)
  2025-03-03 17:53 ` [PATCH 5/6] pagemap: Remove readahead_page_batch() Matthew Wilcox (Oracle)
@ 2025-03-03 17:53 ` Matthew Wilcox (Oracle)
  5 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-03-03 17:53 UTC (permalink / raw)
  To: David Howells; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

All callers now use folio_nr_pages().  Delete this wrapper.

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

diff --git a/include/linux/mm.h b/include/linux/mm.h
index d5844ade822c..39eef633d725 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2129,15 +2129,6 @@ static inline unsigned long compound_nr(struct page *page)
 #endif
 }
 
-/**
- * thp_nr_pages - The number of regular pages in this huge page.
- * @page: The head page of a huge page.
- */
-static inline int thp_nr_pages(struct page *page)
-{
-	return folio_nr_pages((struct folio *)page);
-}
-
 /**
  * folio_next - Move to the next physical folio.
  * @folio: The folio we're currently operating on.
-- 
2.47.2



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

end of thread, other threads:[~2025-03-03 18:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-03 17:53 [PATCH 0/6] ITER_XARRAY cleanups and consequences Matthew Wilcox (Oracle)
2025-03-03 17:53 ` [PATCH 1/6] iov_iter: Convert iter_xarray_populate_pages() to use folios Matthew Wilcox (Oracle)
2025-03-03 17:53 ` [PATCH 2/6] iov_iter: Convert iov_iter_extract_xarray_pages() " Matthew Wilcox (Oracle)
2025-03-03 17:53 ` [PATCH 3/6] pagemap: Remove find_subpage() Matthew Wilcox (Oracle)
2025-03-03 17:53 ` [PATCH 4/6] filemap: Convert __readahead_batch() to use a folio Matthew Wilcox (Oracle)
2025-03-03 17:53 ` [PATCH 5/6] pagemap: Remove readahead_page_batch() Matthew Wilcox (Oracle)
2025-03-03 17:53 ` [PATCH 6/6] mm: Delete thp_nr_pages() 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