On Mon, Feb 14, 2022 at 11:19:22PM -0800, Christoph Hellwig wrote: > On Mon, Feb 14, 2022 at 08:00:11PM +0000, Matthew Wilcox (Oracle) wrote: > > 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 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. > > I wonder if something like this should also be in a comment near > the check in the code. /* The refcount will be elevated if any page in the folio is mapped */ is what I've added for now.