mm/readahead: Convert page_cache_async_readahead to take a folio
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 18 Mar 2021 02:38:26 +0000 (22:38 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sun, 8 May 2022 18:45:56 +0000 (14:45 -0400)
Removes a couple of calls to compound_head and saves a few bytes.
Also convert verity's read_file_data_page() to be folio-based.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/btrfs/relocation.c
fs/btrfs/send.c
fs/verity/enable.c
include/linux/pagemap.h

index fdc2c4b..9ae0689 100644 (file)
@@ -2967,8 +2967,9 @@ static int relocate_one_page(struct inode *inode, struct file_ra_state *ra,
                goto release_page;
 
        if (PageReadahead(page))
-               page_cache_async_readahead(inode->i_mapping, ra, NULL, page,
-                                  page_index, last_index + 1 - page_index);
+               page_cache_async_readahead(inode->i_mapping, ra, NULL,
+                               page_folio(page), page_index,
+                               last_index + 1 - page_index);
 
        if (!PageUptodate(page)) {
                btrfs_readpage(NULL, page);
index 7d16429..b327dbe 100644 (file)
@@ -4986,7 +4986,8 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
 
                if (PageReadahead(page)) {
                        page_cache_async_readahead(inode->i_mapping, &sctx->ra,
-                               NULL, page, index, last_index + 1 - index);
+                                               NULL, page_folio(page), index,
+                                               last_index + 1 - index);
                }
 
                if (!PageUptodate(page)) {
index 60a4372..f75d2c0 100644 (file)
  * Read a file data page for Merkle tree construction.  Do aggressive readahead,
  * since we're sequentially reading the entire file.
  */
-static struct page *read_file_data_page(struct file *filp, pgoff_t index,
+static struct page *read_file_data_page(struct file *file, pgoff_t index,
                                        struct file_ra_state *ra,
                                        unsigned long remaining_pages)
 {
-       struct page *page;
+       DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, index);
+       struct folio *folio;
 
-       page = find_get_page_flags(filp->f_mapping, index, FGP_ACCESSED);
-       if (!page || !PageUptodate(page)) {
-               if (page)
-                       put_page(page);
+       folio = __filemap_get_folio(ractl.mapping, index, FGP_ACCESSED, 0);
+       if (!folio || !folio_test_uptodate(folio)) {
+               if (folio)
+                       folio_put(folio);
                else
-                       page_cache_sync_readahead(filp->f_mapping, ra, filp,
-                                                 index, remaining_pages);
-               page = read_mapping_page(filp->f_mapping, index, NULL);
-               if (IS_ERR(page))
-                       return page;
+                       page_cache_sync_ra(&ractl, remaining_pages);
+               folio = read_cache_folio(ractl.mapping, index, NULL, file);
+               if (IS_ERR(folio))
+                       return &folio->page;
        }
-       if (PageReadahead(page))
-               page_cache_async_readahead(filp->f_mapping, ra, filp, page,
-                                          index, remaining_pages);
-       return page;
+       if (folio_test_readahead(folio))
+               page_cache_async_ra(&ractl, folio, remaining_pages);
+       return folio_file_page(folio, index);
 }
 
 static int build_merkle_tree_level(struct file *filp, unsigned int level,
index 6065713..b70192f 100644 (file)
@@ -1242,7 +1242,7 @@ void page_cache_sync_readahead(struct address_space *mapping,
  * @mapping: address_space which holds the pagecache and I/O vectors
  * @ra: file_ra_state which holds the readahead state
  * @file: Used by the filesystem for authentication.
- * @page: The page at @index which triggered the readahead call.
+ * @folio: The folio at @index which triggered the readahead call.
  * @index: Index of first page to be read.
  * @req_count: Total number of pages being read by the caller.
  *
@@ -1254,10 +1254,10 @@ void page_cache_sync_readahead(struct address_space *mapping,
 static inline
 void page_cache_async_readahead(struct address_space *mapping,
                struct file_ra_state *ra, struct file *file,
-               struct page *page, pgoff_t index, unsigned long req_count)
+               struct folio *folio, pgoff_t index, unsigned long req_count)
 {
        DEFINE_READAHEAD(ractl, file, ra, mapping, index);
-       page_cache_async_ra(&ractl, page_folio(page), req_count);
+       page_cache_async_ra(&ractl, folio, req_count);
 }
 
 static inline struct folio *__readahead_folio(struct readahead_control *ractl)