From: "Zi Yan" <zi.yan@cs.rutgers.edu>
To: Andrea Arcangeli <aarcange@redhat.com>
Cc: huang ying <huang.ying.caritas@gmail.com>,
"Huang, Ying" <ying.huang@intel.com>,
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
Mike Kravetz <mike.kravetz@oracle.com>,
Mike Rapoport <rppt@linux.vnet.ibm.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Alexander Viro <viro@zeniv.linux.org.uk>
Subject: Re: [RFC -mm] mm, userfaultfd, THP: Avoid waiting when PMD under THP migration
Date: Mon, 06 Nov 2017 21:30:54 -0500 [thread overview]
Message-ID: <AA90DD1E-A077-484C-B7B6-738D76CC2F91@cs.rutgers.edu> (raw)
In-Reply-To: <20171106203527.GB26645@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2589 bytes --]
On 6 Nov 2017, at 15:35, Andrea Arcangeli wrote:
> On Mon, Nov 06, 2017 at 10:53:48AM -0500, Zi Yan wrote:
>> Thanks for clarifying it. We both agree that !pmd_present(), which means
>> PMD migration entry, does not get into userfaultfd_must_wait(),
>> then there seems to be no issue with current code yet.
>>
>> However, the if (!pmd_present(_pmd)) in userfaultfd_must_wait() does not
>> match
>> the exact condition. How about the patch below? It can catch pmd
>> migration entries,
>> which are only possible in x86_64 at the moment.
>>
>> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
>> index 1c713fd5b3e6..dda25444a6ee 100644
>> --- a/fs/userfaultfd.c
>> +++ b/fs/userfaultfd.c
>> @@ -294,9 +294,11 @@ static inline bool userfaultfd_must_wait(struct
>> userfaultfd_ctx *ctx,
>> * pmd_trans_unstable) of the pmd.
>> */
>> _pmd = READ_ONCE(*pmd);
>> - if (!pmd_present(_pmd))
>> + if (pmd_none(_pmd))
>> goto out;
>>
>> + VM_BUG_ON(thp_migration_supported() && is_pmd_migration_entry(_pmd));
>> +
>
> As I wrote in prev email I'm not sure about this invariant to be
> correct 100% of the time (plus we'd want a VM_WARN_ON only
> here). Specifically, what does prevent try_to_unmap to run on a THP
> backed mapping with only the mmap_sem for reading?
>
Right. I missed the part that the page table lock is released before
entering handle_userfault(). The pmd_none() can be mapped elsewhere
and migrated, !pmd_present() but not pmd_none() is possible here when
THP migration is enabled.
> I know what prevents to ever reproduce this in practice though (aside
> from the fact the race between the is_swap_pmd() check in the main
> page fault and the above check is small) and it's because compaction
> won't migrate THP and even the numa faults will not use the migration
> entry. So it'd require some more explicit migration numactl while
> userfaults are running to ever see an hang in there.
>
> I think it's a regression since the introduction of THP migration
> around commits 84c3fc4e9c563d8fb91cfdf5948da48fe1af34d3 /
> 616b8371539a6c487404c3b8fb04078016dab4ba /
> 9c670ea37947a82cb6d4df69139f7e46ed71a0ac etc.. before that pmd_none or
> !pmd_present used to be equivalent, not the case any longer. Of course
> pmd_none would have been better before too.
>
Right. Ying’s patch is a fix of the regression.
Fixes: 84c3fc4e9c563 ("mm: thp: check pmd migration entry in common path")
Thanks for pointing all these out.
—
Best Regards,
Yan Zi
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 557 bytes --]
next prev parent reply other threads:[~2017-11-07 2:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-03 7:52 [RFC -mm] mm, userfaultfd, THP: Avoid waiting when PMD under THP migration Huang, Ying
2017-11-03 15:00 ` Zi Yan
2017-11-05 3:01 ` huang ying
2017-11-06 15:53 ` Zi Yan
2017-11-06 20:35 ` Andrea Arcangeli
2017-11-07 2:30 ` Zi Yan [this message]
2017-11-06 20:21 ` Andrea Arcangeli
2017-11-09 7:33 ` Huang, Ying
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=AA90DD1E-A077-484C-B7B6-738D76CC2F91@cs.rutgers.edu \
--to=zi.yan@cs.rutgers.edu \
--cc=aarcange@redhat.com \
--cc=huang.ying.caritas@gmail.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=rppt@linux.vnet.ibm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=ying.huang@intel.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;
as well as URLs for NNTP newsgroup(s).