Skip to content

Commit 1e12cbb

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: make mapping_evict_folio() the preferred way to evict clean folios
Patch series "Fix fault handler's handling of poisoned tail pages". Since introducing the ability to have large folios in the page cache, it's been possible to have a hwpoisoned tail page returned from the fault handler. We handle this situation poorly; failing to remove the affected page from use. This isn't a minimal patch to fix it, it's a full conversion of all the code surrounding it. This patch (of 6): invalidate_inode_page() does very little beyond calling mapping_evict_folio(). Move the check for mapping being NULL into mapping_evict_folio() and make it available to the rest of the MM for use in the next few patches. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Naoya Horiguchi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b5612c3 commit 1e12cbb

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

mm/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void filemap_free_folio(struct address_space *mapping, struct folio *folio);
138138
int truncate_inode_folio(struct address_space *mapping, struct folio *folio);
139139
bool truncate_inode_partial_folio(struct folio *folio, loff_t start,
140140
loff_t end);
141+
long mapping_evict_folio(struct address_space *mapping, struct folio *folio);
141142
long invalidate_inode_page(struct page *page);
142143
unsigned long mapping_try_invalidate(struct address_space *mapping,
143144
pgoff_t start, pgoff_t end, unsigned long *nr_failed);

mm/truncate.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,22 @@ int generic_error_remove_page(struct address_space *mapping, struct page *page)
266266
}
267267
EXPORT_SYMBOL(generic_error_remove_page);
268268

269-
static long mapping_evict_folio(struct address_space *mapping,
270-
struct folio *folio)
269+
/**
270+
* mapping_evict_folio() - Remove an unused folio from the page-cache.
271+
* @mapping: The mapping this folio belongs to.
272+
* @folio: The folio to remove.
273+
*
274+
* Safely remove one folio from the page cache.
275+
* It only drops clean, unused folios.
276+
*
277+
* Context: Folio must be locked.
278+
* Return: The number of pages successfully removed.
279+
*/
280+
long mapping_evict_folio(struct address_space *mapping, struct folio *folio)
271281
{
282+
/* The page may have been truncated before it was locked */
283+
if (!mapping)
284+
return 0;
272285
if (folio_test_dirty(folio) || folio_test_writeback(folio))
273286
return 0;
274287
/* The refcount will be elevated if any page in the folio is mapped */
@@ -281,25 +294,11 @@ static long mapping_evict_folio(struct address_space *mapping,
281294
return remove_mapping(mapping, folio);
282295
}
283296

284-
/**
285-
* invalidate_inode_page() - Remove an unused page from the pagecache.
286-
* @page: The page to remove.
287-
*
288-
* Safely invalidate one page from its pagecache mapping.
289-
* It only drops clean, unused pages.
290-
*
291-
* Context: Page must be locked.
292-
* Return: The number of pages successfully removed.
293-
*/
294297
long invalidate_inode_page(struct page *page)
295298
{
296299
struct folio *folio = page_folio(page);
297-
struct address_space *mapping = folio_mapping(folio);
298300

299-
/* The page may have been truncated before it was locked */
300-
if (!mapping)
301-
return 0;
302-
return mapping_evict_folio(mapping, folio);
301+
return mapping_evict_folio(folio_mapping(folio), folio);
303302
}
304303

305304
/**

0 commit comments

Comments
 (0)