Message ID | 167172131368.2334525.8569808925687731937.stgit@warthog.procyon.org.uk |
---|---|
Headers | show |
Series | mm, netfs, fscache: Stop read optimisation when folio removed from pagecache | expand |
On Thu, Dec 22, 2022 at 03:02:29PM +0000, David Howells wrote: > Make filemap_release_folio() return one of three values: > > (0) FILEMAP_CANT_RELEASE_FOLIO > > Couldn't release the folio's private data, so the folio can't itself > be released. > > (1) FILEMAP_RELEASED_FOLIO > > The private data on the folio was released and the folio can be > released. > > (2) FILEMAP_FOLIO_HAD_NO_PRIVATE These names read really odd, due to the different placementments of FOLIO, the present vs past tense and the fact that 2 also released the folio, and the reliance of callers that one value of an enum must be 0, while no unprecedented, is a bit ugly. But do we even need them? What abut just open coding filemap_release_folio (which is a mostly trivial function) in shrink_folio_list, which is the only place that cares? if (folio_has_private(folio) && folio_needs_release(folio)) { if (folio_test_writeback(folio)) goto activate_locked; if (mapping && mapping->a_ops->release_folio) { if (!mapping->a_ops->release_folio(folio, gfp)) goto activate_locked; } else { if (!try_to_free_buffers(folio)) goto activate_locked; } if (!mapping && folio_ref_count(folio) == 1) { ... alternatively just keep using filemap_release_folio and just add the folio_needs_release in the first branch. That duplicates the test, but makes the change a one-liner.
On Fri, Dec 23, 2022 at 07:31:14AM -0800, Christoph Hellwig wrote: > On Thu, Dec 22, 2022 at 03:02:29PM +0000, David Howells wrote: > > Make filemap_release_folio() return one of three values: > > > > (0) FILEMAP_CANT_RELEASE_FOLIO > > > > Couldn't release the folio's private data, so the folio can't itself > > be released. > > > > (1) FILEMAP_RELEASED_FOLIO > > > > The private data on the folio was released and the folio can be > > released. > > > > (2) FILEMAP_FOLIO_HAD_NO_PRIVATE > > These names read really odd, due to the different placementments > of FOLIO, the present vs past tense and the fact that 2 also released > the folio, and the reliance of callers that one value of an enum > must be 0, while no unprecedented, is a bit ugly. Agreed. The thing is that it's not the filemap that's being released, it's the folio. So these should be: FOLIO_RELEASE_SUCCESS FOLIO_RELEASE_FAILED FOLIO_RELEASE_NO_PRIVATE ... but of course, NO_PRIVATE is also a success. So it's a really weird thing to be reporting. I'm with you on the latter half of this email: > But do we even need them? What abut just open coding > filemap_release_folio (which is a mostly trivial function) in > shrink_folio_list, which is the only place that cares? > > if (folio_has_private(folio) && folio_needs_release(folio)) { > if (folio_test_writeback(folio)) > goto activate_locked; > > if (mapping && mapping->a_ops->release_folio) { > if (!mapping->a_ops->release_folio(folio, gfp)) > goto activate_locked; > } else { > if (!try_to_free_buffers(folio)) > goto activate_locked; > } > > if (!mapping && folio_ref_count(folio) == 1) { > ... > > alternatively just keep using filemap_release_folio and just add the > folio_needs_release in the first branch. That duplicates the test, > but makes the change a one-liner. Or just drop patch 3 entirely?
On Thu, Dec 22, 2022 at 03:02:02PM +0000, David Howells wrote: > Make filemap_release_folio() check folio_has_private(). Then, in most > cases, where a call to folio_has_private() is immediately followed by a > call to filemap_release_folio(), we can get rid of the test in the pair. > > The same is done to page_has_private()/try_to_release_page() call pairs. This line is now obsolete. > There are a couple of sites in mm/vscan.c that this can't so easily be > done. In shrink_folio_list(), there are actually three cases (something > different is done for incompletely invalidated buffers), but > filemap_release_folio() elides two of them. > > In shrink_active_list(), we don't have have the folio lock yet, so the > check allows us to avoid locking the page unnecessarily. > > A wrapper function to check if a folio needs release is provided for those > places that still need to do it in the mm/ directory. This will acquire > additional parts to the condition in a future patch. > > After this, the only remaining caller of folio_has_private() outside of mm/ > is a check in fuse. But there are a few remaining places which check page_has_private(). I think they're all wrong and should be PagePrivate(), but I'll look at them more next week.