linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vishal Moola <vishal.moola@gmail.com>
To: Yang Shi <shy828301@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>,
	linux-mm@kvack.org, akpm@linux-foundation.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 2/2] mm/khugepaged: Remove compound_pagelist
Date: Mon, 2 Oct 2023 08:55:34 -0700	[thread overview]
Message-ID: <CAOzc2pyqFZW8zwKKUdY4w-OOfac6t3VMNOrqXx751VDCuLGrCg@mail.gmail.com> (raw)
In-Reply-To: <CAHbLzkqZHJV8j+C1czfDrZ9t8W_9YLDaZ7FnhNKa224ehnH1zA@mail.gmail.com>

On Thu, Sep 28, 2023 at 12:33 PM Yang Shi <shy828301@gmail.com> wrote:
>
> On Thu, Sep 28, 2023 at 2:05 AM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Tue, Sep 26, 2023 at 03:07:18PM -0700, Yang Shi wrote:
> > > On Fri, Sep 22, 2023 at 9:33 PM Vishal Moola (Oracle)
> > > <vishal.moola@gmail.com> wrote:
> > > >
> > > > Currently, khugepaged builds a compound_pagelist while scanning, which
> > > > is used to properly account for compound pages. We can now account
> > > > for a compound page as a singular folio instead, so remove this list.
> > > >
> > > > Large folios are guaranteed to have consecutive ptes and addresses, so
> > > > once the first pte of a large folio is found skip over the rest.
> > >
> > > The address space may just map a partial folio, for example, in the
> > > extreme case the HUGE_PMD size range may have HUGE_PMD_NR folios with
> > > mapping one subpage from each folio per PTE. So assuming the PTE
> > > mapped folio is mapped consecutively may be wrong.
> >
> > How?  You can do that with two VMAs, but this is limited to scanning
> > within a single VMA.  If we've COWed a large folio, we currently do
> > so as a single page folio, and I'm not seeing any demand to change that.
> > If we did COW as a large folio, we'd COW every page in that folio.
> > How do we interleave two large folios in the same VMA?
>
> It is not about COW. The magic from mremap() may cause some corner
> cases. For example,
>
> We have a 2M VMA, every 4K of the VMA may be mapped to a subpage from
> different folios. Like:
>
> 0: #0 subpage of folio #0
> 1: #1 subpage of folio #1
> 2: #2 subpage of folio #2
> ....
> 511: #511 subpage of folio #511
>
> When khugepaged is scanning the VMA, it may just isolate and lock the
> folio #0, but skip all other folios since it assumes the VMA is just
> mapped by folio #0.
>
> This may trigger kernel bug when unlocking other folios which are
> actually not locked and maybe data corruption since the other folios
> may go away under us (unisolated, unlocked and unpinned).

Thanks for the review. I did not know this could happen; I'll drop
this patch for
now until I can think of a better way to iterate through ptes for large folios.


  reply	other threads:[~2023-10-02 15:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 19:36 [RFC PATCH 0/2] Remove compound_pagelist from khugepaged Vishal Moola (Oracle)
2023-09-22 19:36 ` [RFC PATCH 1/2] mm/khugepaged: Convert __collapse_huge_page_isolate() to use folios Vishal Moola (Oracle)
2023-09-22 19:46   ` Matthew Wilcox
2023-09-25  7:18   ` David Hildenbrand
2023-09-25 18:57     ` Vishal Moola
2023-09-22 19:36 ` [RFC PATCH 2/2] mm/khugepaged: Remove compound_pagelist Vishal Moola (Oracle)
2023-09-26 22:07   ` Yang Shi
2023-09-28  9:05     ` Matthew Wilcox
2023-09-28 19:33       ` Yang Shi
2023-10-02 15:55         ` Vishal Moola [this message]
2023-09-29 19:07     ` Yang Shi

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=CAOzc2pyqFZW8zwKKUdY4w-OOfac6t3VMNOrqXx751VDCuLGrCg@mail.gmail.com \
    --to=vishal.moola@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shy828301@gmail.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