Skip to content

Commit 82c50f8

Browse files
author
Matthew Wilcox (Oracle)
committed
filemap: Add filemap_release_folio()
Reimplement try_to_release_page() as a wrapper around filemap_release_folio(). Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: William Kucharski <[email protected]>
1 parent 960ea97 commit 82c50f8

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

include/linux/mm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,6 @@ int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
19701970
struct page **pages);
19711971
struct page *get_dump_page(unsigned long addr);
19721972

1973-
extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
19741973
extern void do_invalidatepage(struct page *page, unsigned int offset,
19751974
unsigned int length);
19761975

include/linux/pagemap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ static inline void __delete_from_page_cache(struct page *page, void *shadow)
939939
void replace_page_cache_page(struct page *old, struct page *new);
940940
void delete_from_page_cache_batch(struct address_space *mapping,
941941
struct pagevec *pvec);
942+
int try_to_release_page(struct page *page, gfp_t gfp);
943+
bool filemap_release_folio(struct folio *folio, gfp_t gfp);
942944
loff_t mapping_seek_hole_data(struct address_space *, loff_t start, loff_t end,
943945
int whence);
944946

mm/filemap.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,33 +3889,32 @@ ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
38893889
EXPORT_SYMBOL(generic_file_write_iter);
38903890

38913891
/**
3892-
* try_to_release_page() - release old fs-specific metadata on a page
3892+
* filemap_release_folio() - Release fs-specific metadata on a folio.
3893+
* @folio: The folio which the kernel is trying to free.
3894+
* @gfp: Memory allocation flags (and I/O mode).
38933895
*
3894-
* @page: the page which the kernel is trying to free
3895-
* @gfp_mask: memory allocation flags (and I/O mode)
3896+
* The address_space is trying to release any data attached to a folio
3897+
* (presumably at folio->private).
38963898
*
3897-
* The address_space is to try to release any data against the page
3898-
* (presumably at page->private).
3899+
* This will also be called if the private_2 flag is set on a page,
3900+
* indicating that the folio has other metadata associated with it.
38993901
*
3900-
* This may also be called if PG_fscache is set on a page, indicating that the
3901-
* page is known to the local caching routines.
3902+
* The @gfp argument specifies whether I/O may be performed to release
3903+
* this page (__GFP_IO), and whether the call may block
3904+
* (__GFP_RECLAIM & __GFP_FS).
39023905
*
3903-
* The @gfp_mask argument specifies whether I/O may be performed to release
3904-
* this page (__GFP_IO), and whether the call may block (__GFP_RECLAIM & __GFP_FS).
3905-
*
3906-
* Return: %1 if the release was successful, otherwise return zero.
3906+
* Return: %true if the release was successful, otherwise %false.
39073907
*/
3908-
int try_to_release_page(struct page *page, gfp_t gfp_mask)
3908+
bool filemap_release_folio(struct folio *folio, gfp_t gfp)
39093909
{
3910-
struct address_space * const mapping = page->mapping;
3910+
struct address_space * const mapping = folio->mapping;
39113911

3912-
BUG_ON(!PageLocked(page));
3913-
if (PageWriteback(page))
3914-
return 0;
3912+
BUG_ON(!folio_test_locked(folio));
3913+
if (folio_test_writeback(folio))
3914+
return false;
39153915

39163916
if (mapping && mapping->a_ops->releasepage)
3917-
return mapping->a_ops->releasepage(page, gfp_mask);
3918-
return try_to_free_buffers(page);
3917+
return mapping->a_ops->releasepage(&folio->page, gfp);
3918+
return try_to_free_buffers(&folio->page);
39193919
}
3920-
3921-
EXPORT_SYMBOL(try_to_release_page);
3920+
EXPORT_SYMBOL(filemap_release_folio);

mm/folio-compat.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,9 @@ void delete_from_page_cache(struct page *page)
145145
{
146146
return filemap_remove_folio(page_folio(page));
147147
}
148+
149+
int try_to_release_page(struct page *page, gfp_t gfp)
150+
{
151+
return filemap_release_folio(page_folio(page), gfp);
152+
}
153+
EXPORT_SYMBOL(try_to_release_page);

0 commit comments

Comments
 (0)