From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Matthew Wilcox <willy@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
John Hubbard <jhubbard@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-mm@kvack.org, cai@lca.pw, rppt@linux.ibm.com,
william.kucharski@oracle.com,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH v2] mm, dump_page: do not crash with bad compound_mapcount()
Date: Fri, 7 Aug 2020 17:53:59 +0300 [thread overview]
Message-ID: <20200807145359.oxwzjkhv5pqinam5@box> (raw)
In-Reply-To: <20200806171500.GA17456@casper.infradead.org>
On Thu, Aug 06, 2020 at 06:15:00PM +0100, Matthew Wilcox wrote:
> On Thu, Aug 06, 2020 at 05:53:10PM +0200, Vlastimil Babka wrote:
> > On 8/6/20 5:39 PM, Matthew Wilcox wrote:
> > >> >> +++ b/mm/huge_memory.c
> > >> >> @@ -2125,7 +2125,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
> > >> >> * Set PG_double_map before dropping compound_mapcount to avoid
> > >> >> * false-negative page_mapped().
> > >> >> */
> > >> >> - if (compound_mapcount(page) > 1 && !TestSetPageDoubleMap(page)) {
> > >> >> + if (head_mapcount(page) > 1 && !TestSetPageDoubleMap(page)) {
> > >> >
> > >> > I'm a little nervous about this one. The page does actually come from
> > >> > pmd_page(), and today that's guaranteed to be a head page. But I'm
> > >> > not convinced that's going to still be true in twenty years. With the
> > >> > current THP patchset, I won't allocate pages larger than PMD order, but
> > >> > I can see there being interest in tracking pages in chunks larger than
> > >> > 2MB in the future. And then pmd_page() might well return a tail page.
> > >> > So it might be a good idea to not convert this one.
> > >>
> > >> Hmm the function converts the compound mapcount of the whole page to a
> > >> HPAGE_PMD_NR of base pages. If suddenly the compound page was bigger than a pmd,
> > >> then I guess this wouldn't work properly anymore without changes anyway?
> > >> Maybe we could stick something like VM_BUG_ON(PageTransHuge(page)) there as
> > >> "enforced documentation" for now?
> > >
> > > I think it would work as-is. But also I may have totally misunderstood it.
> > > I'll write this declaratively and specifically for x86 (PMD order is 9)
> > > ... tell me when I've made a mistake ;-)
> > >
> > > This function is for splitting the PMD. We're leaving the underlying
> > > page intact and just changing the page table. So if, say, we have an
> > > underlying 4MB page (and maybe the pages are mapped as PMDs in this
> > > process), we might get subpage number 512 of this order-10 page. We'd
> > > need to check the DoubleMap bit on subpage 1, and the compound_mapcount
> > > also stored in page 1, but we'd only want to spread the mapcount out
> > > over the 512 subpages from 512-1023; we wouldn't want to spread it out
> > > over 0-511 because they aren't affected by this particular PMD.
> >
> > Yeah, and then we decrease the compound mapcount, which is a counter of "how
> > many times is this compound page mapped as a whole". But we only removed (the
> > second) half of the compound mapping, so imho that would be wrong?
>
> I'd expect that count to be incremented by 1 for each PMD that it's
> mapped to? ie change the definition of that counter slightly.
>
> > > Having to reason about stuff like this is why I limited the THP code to
> > > stop at PMD order ... I don't want to make my life even more complicated
> > > than I have to!
> >
> > Kirill might correct me but I'd expect the THP code right now has baked in many
> > assumptions about THP pages being exactly HPAGE_PMD_ORDER large?
That will be true for PMD-mapped THP pages after applying Matthew's
patchset.
> There are somewhat fewer places that make that assumption after applying
> the ~80 patches here ... http://git.infradead.org/users/willy/pagecache.git
The patchset allows for THP to be anywhere between order-2 and
order-9 (on x86-64).
> I have mostly not touched the anonymous THPs (obviously some of the code
> paths are shared), although both Kirill & I think there's a win to be
> had there too.
Yeah. Reducing LRU handling overhead alone should be enough to justify the
effort. But we still would need to have numbers.
--
Kirill A. Shutemov
next prev parent reply other threads:[~2020-08-07 14:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-04 21:48 [PATCH v2] mm, dump_page: do not crash with bad compound_mapcount() John Hubbard
2020-08-06 11:45 ` Vlastimil Babka
2020-08-06 13:48 ` Matthew Wilcox
2020-08-06 15:13 ` Vlastimil Babka
2020-08-06 15:39 ` Matthew Wilcox
2020-08-06 15:53 ` Vlastimil Babka
2020-08-06 17:15 ` Matthew Wilcox
2020-08-07 14:53 ` Kirill A. Shutemov [this message]
2020-08-07 14:35 ` Kirill A. Shutemov
2020-08-07 15:10 ` Matthew Wilcox
2020-08-07 16:48 ` Kirill A. Shutemov
2020-08-07 18:33 ` [PATCH] mm, dump_page: rename head_mapcount() --> head_compound_mapcount() John Hubbard
2020-08-07 22:40 ` [PATCH v2] mm, dump_page: do not crash with bad compound_mapcount() John Hubbard
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=20200807145359.oxwzjkhv5pqinam5@box \
--to=kirill@shutemov.name \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=jhubbard@nvidia.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@linux.ibm.com \
--cc=vbabka@suse.cz \
--cc=william.kucharski@oracle.com \
--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).