From: David Howells <dhowells@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: dhowells@redhat.com, willy@infradead.org, dwysocha@redhat.com,
Rohith Surabattula <rohiths.msft@gmail.com>,
Steve French <sfrench@samba.org>,
Shyam Prasad N <nspmangalore@gmail.com>,
Dominique Martinet <asmadeus@codewreck.org>,
Ilya Dryomov <idryomov@gmail.com>,
linux-cachefs@redhat.com, linux-cifs@vger.kernel.org,
linux-afs@lists.infradead.org,
v9fs-developer@lists.sourceforge.net, ceph-devel@vger.kernel.org,
linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] mm, netfs, fscache: Stop read optimisation when folio removed from pagecache
Date: Wed, 23 Nov 2022 20:03:03 +0000 [thread overview]
Message-ID: <1619343.1669233783@warthog.procyon.org.uk> (raw)
In-Reply-To: <CAHk-=wghJtq-952e_8jd=vtV68y_HsDJ8=e0=C3-AsU2WL-8YA@mail.gmail.com>
Linus Torvalds <torvalds@linux-foundation.org> wrote:
> But I also think it's strange in another way, with that odd placement of
>
> mapping_clear_release_always(inode->i_mapping);
>
> at inode eviction time. That just feels very random.
I was under the impression that a warning got splashed if unexpected
address_space flags were set when ->evict_inode() returned. I may be thinking
of page flags. If it doesn't, fine, this isn't required.
> Similarly, that change to shrink_folio_list() looks strange, with the
> nasty folio_needs_release() helper. It seems entirely pointless, with
> the use then being
>
> if (folio_needs_release(folio)) {
> if (!filemap_release_folio(folio, sc->gfp_mask))
> goto activate_locked;
Unfortunately, that can't be simply folded down. It actually does something
extra if folio_has_private() was set, filemap_release_folio() succeeds but
there was no mapping:
* Rarely, folios can have buffers and no ->mapping.
* These are the folios which were not successfully
* invalidated in truncate_cleanup_folio(). We try to
* drop those buffers here and if that worked, and the
* folio is no longer mapped into process address space
* (refcount == 1) it can be freed. Otherwise, leave
* the folio on the LRU so it is swappable.
Possibly I could split the if-statement and make it two separate cases:
/*
* If the folio has buffers, try to free the buffer
* mappings associated with this folio. If we succeed
* we try to free the folio as well.
*
* We do this even if the folio is dirty.
* filemap_release_folio() does not perform I/O, but it
* is possible for a folio to have the dirty flag set,
* but it is actually clean (all its buffers are clean).
* This happens if the buffers were written out directly,
* with submit_bh(). ext3 will do this, as well as
* the blockdev mapping. filemap_release_folio() will
* discover that cleanness and will drop the buffers
* and mark the folio clean - it can be freed.
*/
if (!filemap_release_folio(folio, sc->gfp_mask))
goto activate_locked;
filemap_release_folio() will return true if folio_has_private() is false,
which would allow us to reach the next part, which we would then skip.
/*
* Rarely, folios can have buffers and no ->mapping.
* These are the folios which were not successfully
* invalidated in truncate_cleanup_folio(). We try to
* drop those buffers here and if that worked, and the
* folio is no longer mapped into process address space
* (refcount == 1) it can be freed. Otherwise, leave
* the folio on the LRU so it is swappable.
*/
if (!mapping && folio_has_private(folio) &&
folio_ref_count(folio) == 1) {
folio_unlock(folio);
if (folio_put_testzero(folio))
goto free_it;
/*
* rare race with speculative reference.
* the speculative reference will free
* this folio shortly, so we may
* increment nr_reclaimed here (and
* leave it off the LRU).
*/
nr_reclaimed += nr_pages;
continue;
}
But that will malfunction if try_to_free_buffers(), as called from
folio_has_private(), manages to clear the private bits. I wonder if it might
be possible to fold this bit into filemap_release_folio() somehow.
I really need a three-state return from filemap_release_folio() - maybe:
0 couldn't release
1 released
2 there was no private
The ordinary "if (filemap_release_folio()) { ... }" would work as expected.
shrink_folio_list() could do something different between case 1 and case 2.
> And the change to mm/filemap.c is completely unacceptable in all
> forms, and this added test
>
> + if ((!mapping || !mapping_release_always(mapping)) &&
> + !folio_test_private(folio) &&
> + !folio_test_private_2(folio))
> + return true;
>
> will not be accepted even during the merge window. That code makes no
> sense what-so-ever, and is in no way acceptable.
>
> That code makes no sense what-so-ever. Why isn't it using
> "folio_has_private()"?
It should be, yes.
> Why is this done as an open-coded - and *badly* so - version of
> !folio_needs_release() that you for some reason made private to mm/vmscan.c?
Yeah, in retrospect, I should have put that in mm/internal.h.
David
next prev parent reply other threads:[~2022-11-23 20:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 13:02 David Howells
2022-11-23 18:26 ` Linus Torvalds
2022-11-23 20:03 ` David Howells [this message]
2022-11-23 20:25 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1619343.1669233783@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=asmadeus@codewreck.org \
--cc=ceph-devel@vger.kernel.org \
--cc=dwysocha@redhat.com \
--cc=idryomov@gmail.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-cachefs@redhat.com \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=nspmangalore@gmail.com \
--cc=rohiths.msft@gmail.com \
--cc=sfrench@samba.org \
--cc=torvalds@linux-foundation.org \
--cc=v9fs-developer@lists.sourceforge.net \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox