diff mbox series

[39/48] filemap: Convert filemap_read() to use a folio

Message ID 20211208042256.1923824-40-willy@infradead.org (mailing list archive)
State New
Headers show
Series Folios for 5.17 | expand

Commit Message

Matthew Wilcox Dec. 8, 2021, 4:22 a.m. UTC
We know the pagevec always contains folios, but use page_folio() anyway
instead of casting.  Removes a few calls to legacy functions.

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

Comments

Matthew Wilcox Jan. 1, 2022, 4:14 p.m. UTC | #1
On Thu, Dec 23, 2021 at 09:22:02AM +0100, Christoph Hellwig wrote:
> On Wed, Dec 08, 2021 at 04:22:47AM +0000, Matthew Wilcox (Oracle) wrote:
> >  		for (i = 0; i < pagevec_count(&pvec); i++) {
> > -			struct page *page = pvec.pages[i];
> > -			size_t page_size = thp_size(page);
> > -			size_t offset = iocb->ki_pos & (page_size - 1);
> > +			struct folio *folio = page_folio(pvec.pages[i]);
> > +			size_t fsize = folio_size(folio);
> 
> Any reason for fsize vs folio_size?

  CC      mm/filemap.o
../mm/filemap.c: In function ‘filemap_read’:
../mm/filemap.c:2672:45: error: called object ‘folio_size’ is not a function or function pointer
 2672 |                         size_t folio_size = folio_size(folio);
      |                                             ^~~~~~~~~~
../mm/filemap.c:2672:32: note: declared here
 2672 |                         size_t folio_size = folio_size(folio);
      |                                ^~~~~~~~~~
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index fb3cdb7aeffc..91399027b349 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2668,30 +2668,26 @@  ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
 			mark_page_accessed(pvec.pages[0]);
 
 		for (i = 0; i < pagevec_count(&pvec); i++) {
-			struct page *page = pvec.pages[i];
-			size_t page_size = thp_size(page);
-			size_t offset = iocb->ki_pos & (page_size - 1);
+			struct folio *folio = page_folio(pvec.pages[i]);
+			size_t fsize = folio_size(folio);
+			size_t offset = iocb->ki_pos & (fsize - 1);
 			size_t bytes = min_t(loff_t, end_offset - iocb->ki_pos,
-					     page_size - offset);
+					     fsize - offset);
 			size_t copied;
 
-			if (end_offset < page_offset(page))
+			if (end_offset < folio_pos(folio))
 				break;
 			if (i > 0)
-				mark_page_accessed(page);
+				folio_mark_accessed(folio);
 			/*
-			 * If users can be writing to this page using arbitrary
-			 * virtual addresses, take care about potential aliasing
-			 * before reading the page on the kernel side.
+			 * If users can be writing to this folio using arbitrary
+			 * virtual addresses, take care of potential aliasing
+			 * before reading the folio on the kernel side.
 			 */
-			if (writably_mapped) {
-				int j;
-
-				for (j = 0; j < thp_nr_pages(page); j++)
-					flush_dcache_page(page + j);
-			}
+			if (writably_mapped)
+				flush_dcache_folio(folio);
 
-			copied = copy_page_to_iter(page, offset, bytes, iter);
+			copied = copy_folio_to_iter(folio, offset, bytes, iter);
 
 			already_read += copied;
 			iocb->ki_pos += copied;