From d2329aa0c78f4a8dd368bb706f196ab99f692eaa Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Sun, 1 May 2022 07:35:31 -0400 Subject: fs: Add free_folio address space operation Include documentation and convert the callers to use ->free_folio as well as ->freepage. Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 9 ++++++++- mm/vmscan.c | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'mm') diff --git a/mm/filemap.c b/mm/filemap.c index d335a154a0d9..adcdef56890f 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -226,8 +226,12 @@ void __filemap_remove_folio(struct folio *folio, void *shadow) void filemap_free_folio(struct address_space *mapping, struct folio *folio) { void (*freepage)(struct page *); + void (*free_folio)(struct folio *); int refs = 1; + free_folio = mapping->a_ops->free_folio; + if (free_folio) + free_folio(folio); freepage = mapping->a_ops->freepage; if (freepage) freepage(&folio->page); @@ -807,6 +811,7 @@ void replace_page_cache_page(struct page *old, struct page *new) struct folio *fold = page_folio(old); struct folio *fnew = page_folio(new); struct address_space *mapping = old->mapping; + void (*free_folio)(struct folio *) = mapping->a_ops->free_folio; void (*freepage)(struct page *) = mapping->a_ops->freepage; pgoff_t offset = old->index; XA_STATE(xas, &mapping->i_pages, offset); @@ -835,9 +840,11 @@ void replace_page_cache_page(struct page *old, struct page *new) if (PageSwapBacked(new)) __inc_lruvec_page_state(new, NR_SHMEM); xas_unlock_irq(&xas); + if (free_folio) + free_folio(fold); if (freepage) freepage(old); - put_page(old); + folio_put(fold); } EXPORT_SYMBOL_GPL(replace_page_cache_page); diff --git a/mm/vmscan.c b/mm/vmscan.c index f3f7ce2c4068..d8a031128ad0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1282,8 +1282,10 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio, xa_unlock_irq(&mapping->i_pages); put_swap_page(&folio->page, swap); } else { + void (*free_folio)(struct folio *); void (*freepage)(struct page *); + free_folio = mapping->a_ops->free_folio; freepage = mapping->a_ops->freepage; /* * Remember a shadow entry for reclaimed file cache in @@ -1310,7 +1312,9 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio, inode_add_lru(mapping->host); spin_unlock(&mapping->host->i_lock); - if (freepage != NULL) + if (free_folio) + free_folio(folio); + if (freepage) freepage(&folio->page); } -- cgit v1.2.3