From: Peter Xu <peterx@redhat.com>
To: David Stevens <stevensd@chromium.org>
Cc: Matthew Wilcox <willy@infradead.org>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
"Kirill A . Shutemov" <kirill@shutemov.name>,
Yang Shi <shy828301@gmail.com>,
David Hildenbrand <david@redhat.com>,
Hugh Dickins <hughd@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/khugepaged: set THP as uptodate earlier for shmem
Date: Wed, 15 Feb 2023 17:05:45 -0500 [thread overview]
Message-ID: <Y+1XOS88M+Pigqtq@x1n> (raw)
In-Reply-To: <CAD=HUj76eeScAKkX=uf03KnGcVvyzz_kJ4sYVx8XeFqwTVhDow@mail.gmail.com>
On Wed, Feb 15, 2023 at 10:33:15AM +0900, David Stevens wrote:
> On Wed, Feb 15, 2023 at 12:44 AM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Tue, Feb 14, 2023 at 04:57:09PM +0900, David Stevens wrote:
> > > /*
> > > - * At this point the hpage is locked and not up-to-date.
> > > - * It's safe to insert it into the page cache, because nobody would
> > > - * be able to map it or use it in another way until we unlock it.
> > > + * Mark hpage as up-to-date before inserting it into the page cache to
> > > + * prevent it from being mistaken for an fallocated but unwritten page.
> > > + * Inserting the unfinished hpage into the page cache is safe because
> > > + * it is locked, so nobody can map it or use it in another way until we
> > > + * unlock it.
> >
> > No, that's not true. The data has to be there before we mark it
> > uptodate. See filemap_get_pages() for example, used as part of
> > read(). We don't lock the page unless we need to bring it uptodate
> > ourselves.
>
> I've been focusing on the shmem case for collapse_file and forgot to
> think about the !is_shmem case. As far as I could tell, shmem doesn't
> use filemap_get_pages() and everything else in filemap.c/shmem.c that
> checks folio_test_uptodate also locks the folio. But yeah, this would
> break the !is_shmem case and is kind of sketchy anyway. I'll put
> together a better patch.
AFAIU we lock the page iff !uptodate and we want to wait it to be uptodate,
or as Matthew said when we want to modify !uptodate->uptodate.
Take the same example of folio_seek_hole_data() that you mentioned:
if (xa_is_value(folio) || folio_test_uptodate(folio))
return seek_data ? start : end;
--
Peter Xu
prev parent reply other threads:[~2023-02-15 22:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 7:57 [PATCH 1/2] mm/khugepaged: set THP as uptodate earlier for shmem David Stevens
2023-02-14 7:57 ` [PATCH 2/2] mm/khugepaged: skip shmem with userfaultfd David Stevens
2023-02-14 22:35 ` Peter Xu
2023-02-15 1:57 ` David Stevens
2023-02-15 22:27 ` Peter Xu
2023-02-15 22:48 ` Peter Xu
2023-02-16 1:37 ` David Stevens
2023-02-16 14:41 ` Peter Xu
2023-02-16 21:58 ` Yang Shi
2023-02-16 23:07 ` Peter Xu
2023-02-16 23:52 ` Yang Shi
2023-02-17 2:00 ` David Stevens
2023-02-17 3:20 ` Yang Shi
2023-02-14 15:44 ` [PATCH 1/2] mm/khugepaged: set THP as uptodate earlier for shmem Matthew Wilcox
2023-02-15 1:33 ` David Stevens
2023-02-15 22:05 ` Peter Xu [this message]
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=Y+1XOS88M+Pigqtq@x1n \
--to=peterx@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=stevensd@chromium.org \
--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;
as well as URLs for NNTP newsgroup(s).