filemap: Add filemap_release_folio()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 28 Jul 2021 19:14:48 +0000 (15:14 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 4 Jan 2022 18:15:34 +0000 (13:15 -0500)
Reimplement try_to_release_page() as a wrapper around
filemap_release_folio().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
include/linux/mm.h
include/linux/pagemap.h
mm/filemap.c
mm/folio-compat.c

index 72ca04f16711bcd66faf3d2743890dff02a9ff35..145f045b0ddc4f9dd25b5b9db962b3651ac605e9 100644 (file)
@@ -1970,7 +1970,6 @@ int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
                        struct page **pages);
 struct page *get_dump_page(unsigned long addr);
 
-extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
 extern void do_invalidatepage(struct page *page, unsigned int offset,
                              unsigned int length);
 
index 7bef50ea5435b292fd242fc72d5331631eb169fe..eb6e58e106c8c0803492dbe22b48a687df4a31c2 100644 (file)
@@ -939,6 +939,8 @@ static inline void __delete_from_page_cache(struct page *page, void *shadow)
 void replace_page_cache_page(struct page *old, struct page *new);
 void delete_from_page_cache_batch(struct address_space *mapping,
                                  struct pagevec *pvec);
+int try_to_release_page(struct page *page, gfp_t gfp);
+bool filemap_release_folio(struct folio *folio, gfp_t gfp);
 loff_t mapping_seek_hole_data(struct address_space *, loff_t start, loff_t end,
                int whence);
 
index bbe982e64e6242fd71dc7828d96e91b840535d1d..4c39e09a2f518b63720cd19a6f5d2c990778679d 100644 (file)
@@ -3889,33 +3889,32 @@ ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 EXPORT_SYMBOL(generic_file_write_iter);
 
 /**
- * try_to_release_page() - release old fs-specific metadata on a page
+ * filemap_release_folio() - Release fs-specific metadata on a folio.
+ * @folio: The folio which the kernel is trying to free.
+ * @gfp: Memory allocation flags (and I/O mode).
  *
- * @page: the page which the kernel is trying to free
- * @gfp_mask: memory allocation flags (and I/O mode)
+ * The address_space is trying to release any data attached to a folio
+ * (presumably at folio->private).
  *
- * The address_space is to try to release any data against the page
- * (presumably at page->private).
+ * This will also be called if the private_2 flag is set on a page,
+ * indicating that the folio has other metadata associated with it.
  *
- * This may also be called if PG_fscache is set on a page, indicating that the
- * page is known to the local caching routines.
+ * The @gfp argument specifies whether I/O may be performed to release
+ * this page (__GFP_IO), and whether the call may block
+ * (__GFP_RECLAIM & __GFP_FS).
  *
- * The @gfp_mask argument specifies whether I/O may be performed to release
- * this page (__GFP_IO), and whether the call may block (__GFP_RECLAIM & __GFP_FS).
- *
- * Return: %1 if the release was successful, otherwise return zero.
+ * Return: %true if the release was successful, otherwise %false.
  */
-int try_to_release_page(struct page *page, gfp_t gfp_mask)
+bool filemap_release_folio(struct folio *folio, gfp_t gfp)
 {
-       struct address_space * const mapping = page->mapping;
+       struct address_space * const mapping = folio->mapping;
 
-       BUG_ON(!PageLocked(page));
-       if (PageWriteback(page))
-               return 0;
+       BUG_ON(!folio_test_locked(folio));
+       if (folio_test_writeback(folio))
+               return false;
 
        if (mapping && mapping->a_ops->releasepage)
-               return mapping->a_ops->releasepage(page, gfp_mask);
-       return try_to_free_buffers(page);
+               return mapping->a_ops->releasepage(&folio->page, gfp);
+       return try_to_free_buffers(&folio->page);
 }
-
-EXPORT_SYMBOL(try_to_release_page);
+EXPORT_SYMBOL(filemap_release_folio);
index 749a695b421773d04d1f377bab2b6054bb25a3a4..749555a232a880d90c809bc8d46ded5436d9301c 100644 (file)
@@ -145,3 +145,9 @@ void delete_from_page_cache(struct page *page)
 {
        return filemap_remove_folio(page_folio(page));
 }
+
+int try_to_release_page(struct page *page, gfp_t gfp)
+{
+       return filemap_release_folio(page_folio(page), gfp);
+}
+EXPORT_SYMBOL(try_to_release_page);