Skip to content

Commit

Permalink
mm/truncate: Replace page_mapped() call in invalidate_inode_page()
Browse files Browse the repository at this point in the history
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) <willy@infradead.org>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
  • Loading branch information
Matthew Wilcox (Oracle) committed Mar 21, 2022
1 parent 4418481 commit e41c81d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mm/truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ int invalidate_inode_page(struct page *page)
return 0;
if (folio_test_dirty(folio) || folio_test_writeback(folio))
return 0;
if (page_mapped(page))
/* The refcount will be elevated if any page in the folio is mapped */
if (folio_ref_count(folio) >
folio_nr_pages(folio) + folio_has_private(folio) + 1)
return 0;
if (folio_has_private(folio) && !filemap_release_folio(folio, 0))
return 0;
Expand Down

0 comments on commit e41c81d

Please sign in to comment.