diff mbox series

[v9,81/96] mm/filemap: Add filemap_get_stable_folio

Message ID 20210505150628.111735-82-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Memory folios | expand

Commit Message

Matthew Wilcox (Oracle) May 5, 2021, 3:06 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 03125035077c..726cfc61b9e5 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -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);
 
diff --git a/mm/filemap.c b/mm/filemap.c
index 3d8715a6dd08..8399deb678f6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -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)
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index df0038c65da9..940fe515a3a2 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -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);