2024-03-27 18:45:31

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [RFC PATCH v2] mm, netfs: Provide a means of invalidation without using launder_folio

On Wed, Mar 27, 2024 at 05:55:45PM +0000, David Howells wrote:
> +int filemap_invalidate_inode(struct inode *inode, bool flush)
> +{
> + struct address_space *mapping = inode->i_mapping;
> +
> + if (!mapping || !mapping->nrpages)
> + goto out;
> +
> + /* Prevent new folios from being added to the inode. */
> + filemap_invalidate_lock(mapping);

I'm kind of surprised that the callers wouldn't want to hold that lock
over a call to this function. I guess you're working on the callers,
so you'd know better than I would, but I would have used lockdep to
assert that invalidate_lock was held.

> + if (!mapping->nrpages)
> + goto unlock;
> +
> + /* Assume there are probably PTEs only if there are mmaps. */
> + if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root)))
> + unmap_mapping_pages(mapping, 0, ULONG_MAX, false);

Is this optimisation worth it? We're already doing some expensive
operations here, does saving cycling the i_mmap_lock really help
anything? You'll note that unmap_mapping_pages() already does this
check inside the lock.



2024-03-27 20:38:06

by David Howells

[permalink] [raw]
Subject: Re: [RFC PATCH v2] mm, netfs: Provide a means of invalidation without using launder_folio

Matthew Wilcox <[email protected]> wrote:

> > + /* Prevent new folios from being added to the inode. */
> > + filemap_invalidate_lock(mapping);
>
> I'm kind of surprised that the callers wouldn't want to hold that lock
> over a call to this function. I guess you're working on the callers,
> so you'd know better than I would, but I would have used lockdep to
> assert that invalidate_lock was held.

I'm not sure. None of the places that look like they'd be calling this
currently take that lock (though possibly they should).

Also, should I provide it with explicit range, I wonder?

> > + if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root)))
> > + unmap_mapping_pages(mapping, 0, ULONG_MAX, false);
>
> Is this optimisation worth it?

Perhaps not.

David