@@ -589,6 +589,8 @@ static inline unsigned find_get_pages_tag(struct address_space *mapping,
nr_pages, pages);
}
+struct folio *filemap_get_stable_folio(struct address_space *mapping,
+ pgoff_t index, unsigned flags);
struct page *grab_cache_page_write_begin(struct address_space *mapping,
pgoff_t index, unsigned flags);
@@ -3574,26 +3574,26 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
EXPORT_SYMBOL(generic_file_direct_write);
/*
- * Find or create a page at the given pagecache position. Return the locked
- * page. This function is specifically for buffered writes.
+ * Find or create a folio at the given pagecache position. Return the locked
+ * folio once there are no pending writes.
*/
-struct page *grab_cache_page_write_begin(struct address_space *mapping,
+struct folio *filemap_get_stable_folio(struct address_space *mapping,
pgoff_t index, unsigned flags)
{
- struct page *page;
- int fgp_flags = FGP_LOCK|FGP_WRITE|FGP_CREAT;
+ struct folio *folio;
+ int fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT;
if (flags & AOP_FLAG_NOFS)
fgp_flags |= FGP_NOFS;
- page = pagecache_get_page(mapping, index, fgp_flags,
+ folio = filemap_get_folio(mapping, index, fgp_flags,
mapping_gfp_mask(mapping));
- if (page)
- wait_for_stable_page(page);
+ if (folio)
+ folio_wait_stable(folio);
- return page;
+ return folio;
}
-EXPORT_SYMBOL(grab_cache_page_write_begin);
+EXPORT_SYMBOL(filemap_get_stable_folio);
ssize_t generic_perform_write(struct file *file,
struct iov_iter *i, loff_t pos)
@@ -96,3 +96,12 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
return folio_file_page(folio, index);
}
EXPORT_SYMBOL(pagecache_get_page);
+
+struct page *grab_cache_page_write_begin(struct address_space *mapping,
+ pgoff_t index, unsigned flags)
+{
+ struct folio *folio = filemap_get_stable_folio(mapping, index, flags);
+
+ return folio ? folio_file_page(folio, index) : NULL;
+}
+EXPORT_SYMBOL(grab_cache_page_write_begin);
This is the folio equivalent of grab_cache_page_write_begin(), which is reimplemented as a wrapper around it. Kernel grows by 88 bytes. filemap_get_stable_folio() is the same size as the old grab_cache_page_write_begin(), but the wrapper is 80 bytes, plus the 8 bytes for the EXPORT_SYMBOL. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 20 ++++++++++---------- mm/folio-compat.c | 9 +++++++++ 3 files changed, 21 insertions(+), 10 deletions(-)