Skip to content

Commit e41c81d

Browse files
author
Matthew Wilcox (Oracle)
committed
mm/truncate: Replace page_mapped() call in invalidate_inode_page()
folio_mapped() is expensive because it has to check each page's mapcount field. A cheaper check is whether there are any extra references to the page, other than the one we own, one from the page private data and the ones held by the page cache. The call to remove_mapping() will fail in any case if it cannot freeze the refcount, but failing here avoids cycling the i_pages spinlock. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Miaohe Lin <[email protected]>
1 parent 4418481 commit e41c81d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mm/truncate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ int invalidate_inode_page(struct page *page)
287287
return 0;
288288
if (folio_test_dirty(folio) || folio_test_writeback(folio))
289289
return 0;
290-
if (page_mapped(page))
290+
/* The refcount will be elevated if any page in the folio is mapped */
291+
if (folio_ref_count(folio) >
292+
folio_nr_pages(folio) + folio_has_private(folio) + 1)
291293
return 0;
292294
if (folio_has_private(folio) && !filemap_release_folio(folio, 0))
293295
return 0;

0 commit comments

Comments
 (0)