linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>,
	linux-mm@kvack.org,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Hugh Dickins <hughd@google.com>, Andi Kleen <ak@linux.intel.com>
Subject: Re: File THP and HWPoison
Date: Thu, 18 Mar 2021 14:57:16 +0000	[thread overview]
Message-ID: <20210318145716.GO3420@casper.infradead.org> (raw)
In-Reply-To: <20210318140843.7dv3wnxg4geplrjx@box>

On Thu, Mar 18, 2021 at 05:08:43PM +0300, Kirill A. Shutemov wrote:
> On Tue, Mar 16, 2021 at 02:09:47PM +0000, Matthew Wilcox wrote:
> > If we get a memory failure in the middle of a file THP, I think we handle
> > it poorly.
> > 
> > int memory_failure(unsigned long pfn, int flags)
> > ...
> >         if (TestSetPageHWPoison(p)) {
> > ...
> >         orig_head = hpage = compound_head(p);
> > ...
> >         if (PageTransHuge(hpage)) {
> >                 if (try_to_split_thp_page(p, "Memory Failure") < 0) {
> >                         action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
> >                         return -EBUSY;
> >                 }
> > 
> > static int try_to_split_thp_page(struct page *page, const char *msg)
> > {
> >         lock_page(page);
> >         if (!PageAnon(page) || unlikely(split_huge_page(page))) {
> >                 unsigned long pfn = page_to_pfn(page);
> > 
> >                 unlock_page(page);
> >                 if (!PageAnon(page))
> >                         pr_info("%s: %#lx: non anonymous thp\n", msg, pfn);
> >                 else
> >                         pr_info("%s: %#lx: thp split failed\n", msg, pfn);
> >                 put_page(page);
> >                 return -EBUSY;
> > 
> > So (for some reason) we don't even try to split a file THP.  But then,
> > if we take a page fault on a file THP:
> > 
> > static struct page *next_uptodate_page(struct page *page,
> > ...
> >                 if (PageHWPoison(page))
> >                         goto skip;
> > (... but we're only testing the head page here, which isn't necessarily
> > the one which got the error ...)
> > 
> >         if (pmd_none(*vmf->pmd) && PageTransHuge(page)) {
> >             vm_fault_t ret = do_set_pmd(vmf, page);
> > 
> > So we now map the PMD-sized page into userspace, even though it has a
> > HWPoison in it.
> > 
> > I think there are two things that we should be doing:
> > 
> > 1. Attempt to split THPs which are file-backed.  That makes most of this
> > problem disappear because there won't be THPs with HWPoison, mostly.
> 
> +Naoya. Could you give more context here?

I did some git archaeology and found this check was introduced in
7f6bf39bbdd1 ("mm/hwpoison: fix panic due to split huge zero page") where
it wasn't intended to catch _file_ pages at all, but the zero page.
I suspect that nobody thought to look at this when introducing THP
for shmem.

> > 2. When the THP fails to split, use a spare page flag to indicate that
> > the THP contains a HWPoison bit in one of its subpages.  There are a
> > lot of PF_SECOND flags available for this purpose.
> > 
> > but I know almost nothing about the memory-failure subsystem and I'm
> > still learning all the complexities of THPs, so it's entirely possible
> > I've overlooked something important.
> 
> I wounder if it would be cleaner to switch PG_hwpoison to PF_HEAD: if
> split failed we posion whole compound page. Yes, we will waste more
> memory, but it makes it much cleaner for user: just check if the page is
> poisoned.

I think that's a poor quality implementation ... it'd cause processes
to die that weren't even touching the page that had hwpoison.  Using
a PF_SECOND bit lets us do the check as cheaply as if we made hwpoison
PF_HEAD.


  reply	other threads:[~2021-03-18 14:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 14:09 Matthew Wilcox
2021-03-16 16:36 ` Andi Kleen
2021-03-16 16:52   ` Matthew Wilcox
2021-03-18 14:08 ` Kirill A. Shutemov
2021-03-18 14:57   ` Matthew Wilcox [this message]
2021-03-18 17:25     ` HORIGUCHI NAOYA(堀口 直也)
2021-03-18 18:05       ` 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=20210318145716.GO3420@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=hughd@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-mm@kvack.org \
    --cc=naoya.horiguchi@nec.com \
    /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