Skip to content

Commit d2329aa

Browse files
author
Matthew Wilcox (Oracle)
committed
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) <[email protected]>
1 parent 6439476 commit d2329aa

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

Documentation/filesystems/locking.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ prototypes::
250250
sector_t (*bmap)(struct address_space *, sector_t);
251251
void (*invalidate_folio) (struct folio *, size_t start, size_t len);
252252
bool (*release_folio)(struct folio *, gfp_t);
253-
void (*freepage)(struct page *);
253+
void (*free_folio)(struct folio *);
254254
int (*direct_IO)(struct kiocb *, struct iov_iter *iter);
255255
bool (*isolate_page) (struct page *, isolate_mode_t);
256256
int (*migratepage)(struct address_space *, struct page *, struct page *);
@@ -262,10 +262,10 @@ prototypes::
262262
int (*swap_deactivate)(struct file *);
263263

264264
locking rules:
265-
All except dirty_folio and freepage may block
265+
All except dirty_folio and free_folio may block
266266

267267
====================== ======================== ========= ===============
268-
ops PageLocked(page) i_rwsem invalidate_lock
268+
ops folio locked i_rwsem invalidate_lock
269269
====================== ======================== ========= ===============
270270
writepage: yes, unlocks (see below)
271271
read_folio: yes, unlocks shared
@@ -277,7 +277,7 @@ write_end: yes, unlocks exclusive
277277
bmap:
278278
invalidate_folio: yes exclusive
279279
release_folio: yes
280-
freepage: yes
280+
free_folio: yes
281281
direct_IO:
282282
isolate_page: yes
283283
migratepage: yes (both)
@@ -377,7 +377,7 @@ buffers from the folio in preparation for freeing it. It returns false to
377377
indicate that the buffers are (or may be) freeable. If ->release_folio is
378378
NULL, the kernel assumes that the fs has no private interest in the buffers.
379379

380-
->freepage() is called when the kernel is done dropping the page
380+
->free_folio() is called when the kernel has dropped the folio
381381
from the page cache.
382382

383383
->launder_folio() may be called prior to releasing a folio if

Documentation/filesystems/vfs.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ cache in your filesystem. The following members are defined:
735735
sector_t (*bmap)(struct address_space *, sector_t);
736736
void (*invalidate_folio) (struct folio *, size_t start, size_t len);
737737
bool (*release_folio)(struct folio *, gfp_t);
738-
void (*freepage)(struct page *);
738+
void (*free_folio)(struct folio *);
739739
ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter);
740740
/* isolate a page for migration */
741741
bool (*isolate_page) (struct page *, isolate_mode_t);
@@ -891,8 +891,8 @@ cache in your filesystem. The following members are defined:
891891
its release_folio will need to ensure this. Possibly it can
892892
clear the uptodate flag if it cannot free private data yet.
893893

894-
``freepage``
895-
freepage is called once the page is no longer visible in the
894+
``free_folio``
895+
free_folio is called once the folio is no longer visible in the
896896
page cache in order to allow the cleanup of any private data.
897897
Since it may be called by the memory reclaimer, it should not
898898
assume that the original address_space mapping still exists, and

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ struct address_space_operations {
356356
sector_t (*bmap)(struct address_space *, sector_t);
357357
void (*invalidate_folio) (struct folio *, size_t offset, size_t len);
358358
bool (*release_folio)(struct folio *, gfp_t);
359+
void (*free_folio)(struct folio *folio);
359360
void (*freepage)(struct page *);
360361
ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter);
361362
/*

mm/filemap.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,12 @@ void __filemap_remove_folio(struct folio *folio, void *shadow)
226226
void filemap_free_folio(struct address_space *mapping, struct folio *folio)
227227
{
228228
void (*freepage)(struct page *);
229+
void (*free_folio)(struct folio *);
229230
int refs = 1;
230231

232+
free_folio = mapping->a_ops->free_folio;
233+
if (free_folio)
234+
free_folio(folio);
231235
freepage = mapping->a_ops->freepage;
232236
if (freepage)
233237
freepage(&folio->page);
@@ -807,6 +811,7 @@ void replace_page_cache_page(struct page *old, struct page *new)
807811
struct folio *fold = page_folio(old);
808812
struct folio *fnew = page_folio(new);
809813
struct address_space *mapping = old->mapping;
814+
void (*free_folio)(struct folio *) = mapping->a_ops->free_folio;
810815
void (*freepage)(struct page *) = mapping->a_ops->freepage;
811816
pgoff_t offset = old->index;
812817
XA_STATE(xas, &mapping->i_pages, offset);
@@ -835,9 +840,11 @@ void replace_page_cache_page(struct page *old, struct page *new)
835840
if (PageSwapBacked(new))
836841
__inc_lruvec_page_state(new, NR_SHMEM);
837842
xas_unlock_irq(&xas);
843+
if (free_folio)
844+
free_folio(fold);
838845
if (freepage)
839846
freepage(old);
840-
put_page(old);
847+
folio_put(fold);
841848
}
842849
EXPORT_SYMBOL_GPL(replace_page_cache_page);
843850

mm/vmscan.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,10 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio,
12821282
xa_unlock_irq(&mapping->i_pages);
12831283
put_swap_page(&folio->page, swap);
12841284
} else {
1285+
void (*free_folio)(struct folio *);
12851286
void (*freepage)(struct page *);
12861287

1288+
free_folio = mapping->a_ops->free_folio;
12871289
freepage = mapping->a_ops->freepage;
12881290
/*
12891291
* Remember a shadow entry for reclaimed file cache in
@@ -1310,7 +1312,9 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio,
13101312
inode_add_lru(mapping->host);
13111313
spin_unlock(&mapping->host->i_lock);
13121314

1313-
if (freepage != NULL)
1315+
if (free_folio)
1316+
free_folio(folio);
1317+
if (freepage)
13141318
freepage(&folio->page);
13151319
}
13161320

0 commit comments

Comments
 (0)