Received: by 10.223.164.202 with SMTP id h10csp439100wrb; Mon, 6 Nov 2017 09:07:50 -0800 (PST) X-Google-Smtp-Source: ABhQp+SGv0+9hdOy5F3IJofNcgfEyKYaBrYzGClweLmaiK/1lYj9x9hd7EAmavc0imPZaTPavmrf X-Received: by 10.99.116.76 with SMTP id e12mr15732078pgn.126.1509988070798; Mon, 06 Nov 2017 09:07:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509988070; cv=none; d=google.com; s=arc-20160816; b=hj9wDlBFWIWzv6hjcykvWnktMI85qOIOPOMWy30s4ZQaa1hLIzXkt4+mVGHH7x4I5N 0B0V02Xuquy4x1PqTuRNNCwB3ejr4I3PzW/NdLnTTDH4OAhwcHaCnDU6c+snd7OYP5fw WeOWN/4ldcMqs0mEpJ6nfOPC9tf4jZsbPU5Ps7ss94QssXLrr1iw1X9fnTU2LFSnuFig 32sOrlvbQQvSBy/EyystFUAjupQTHP+7h6GfM9EG0jJzTUoWCWzL++2Xbggm1EBNbHIF CQ9KGQT97uX5VHFjo5IJSoG1OqYvawbS1Kn5KkPZE2Q+hsfzJZILbZdwe7Um1enm4qau 5KNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=lVlJU+utkESyEL17AdlD8JH5aU8xpds7aElVGk4Xi4k=; b=EfNdLKndZO5pGm1OQjKeYepxCMfkVWOmM4wdaAitWsVLTtaS5jnAviKouQQ4xz2cti GgxnhtCd96SqeZ/PVFubl7HP631QalETBteWYU4nijeIkHTDcGRtrgxVms62/kV8HL7V Dw6PEIf8Xk0J3lokA5oGfeWVk1Y4ETFmr6j0gRmagomgZZxz3y+sgUalMjZ2athDl6f2 TadI0srjoHOcNTawufpH1+MgJPUWulb7ZNt+/ExQc6LgwpQfVKd9vBsi6dtTKFo72rMP LuKQ05fNZF5dRkSRAVAUwKz2JmG4ewESIL9Jrtl9FcqtFLoyo97jgCOR9CWNjMBlwqfD jUaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 126si12328823pfe.326.2017.11.06.09.07.30; Mon, 06 Nov 2017 09:07:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753958AbdKFPyA (ORCPT + 97 others); Mon, 6 Nov 2017 10:54:00 -0500 Received: from mail-by2nam03on0122.outbound.protection.outlook.com ([104.47.42.122]:57253 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752829AbdKFPx6 (ORCPT ); Mon, 6 Nov 2017 10:53:58 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=zi.yan@cs.rutgers.edu; Received: from [172.27.38.128] (128.6.36.231) by BN6PR14MB1652.namprd14.prod.outlook.com (10.171.176.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Mon, 6 Nov 2017 15:53:54 +0000 From: "Zi Yan" To: "huang ying" Cc: "Huang, Ying" , "Naoya Horiguchi" , linux-mm@kvack.org, LKML , "Andrea Arcangeli" , "Mike Kravetz" , "Mike Rapoport" , "Kirill A. Shutemov" , "Alexander Viro" Subject: Re: [RFC -mm] mm, userfaultfd, THP: Avoid waiting when PMD under THP migration Date: Mon, 06 Nov 2017 10:53:48 -0500 Message-ID: In-Reply-To: References: <20171103075231.25416-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailer: MailMate (2.0BETAr6093) X-Originating-IP: [128.6.36.231] X-ClientProxiedBy: MWHPR0201CA0014.namprd02.prod.outlook.com (10.167.160.155) To BN6PR14MB1652.namprd14.prod.outlook.com (10.171.176.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 062cc502-530e-41e1-0671-08d5252e961e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603249);SRVR:BN6PR14MB1652; X-Microsoft-Exchange-Diagnostics: 1;BN6PR14MB1652;3:NLElF6iSsPymmvssrEBzPLTec8B+e3W3OJp4J+nrHYCG5pPIXt7oKLoEzz4dgG33lGEcs8y64Y4Iw7fHTv0dcepGXnLDzPdI42F+sMwH1K7N+ZVUpjryeT3DvVpxUyOhdcA0DcLBqrnH+rggT8MwDz2AP/Kh2xWootx7qAHAS4gRX29eNxLmwfV5rLE3ZnMbiIcCeHMvo2l3sFAMfKaK0iPwrI04ZhAgIPkCHHuI3I7jWDqlkSzJgZqGHVLAzoH4;25:bIYZKwtWVatfOf1j86h0vkPd1in0S017QLgJmCHfdgGQvaNTAvj6Sl8JkwfkTgtvMbeshVtlBrxxLb0j5El5j809Iy5XuleDmfOAPlCsaDCKnpYBhgkoRFpA/t7r5VMlXbWGnyZpacW9LN9/MSvKOoc4l7gnYT7ONLoyMaRW4IsS3n7leCYwTO8Lpm5AJpNP2ZPMD/KRL+l3xJOYtrVS3iob8K9zgXkCllGrqTX2FiewnB4LGrFKTqq2WVmuFEUqryjVxfAiQpq3LrcK52uHj77hu+IgKoAwgdwhvC+gZdkmcHddJv8AOlhG4HQl2Ru0lW4tyYAjOFacZx9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twTMxEqUSE3pbrWOlJ8m0GRx0mUKIT2f552YLEfSZLGgaRdBJGDXWq6M9H+0jS7JmR2ZHO2VIyeuDjdSupgfhmoxjCG0hcjAro8i+GAyNCo= X-Exchange-Antispam-Report-Test: UriScan:(228905959029699)(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(11241501159)(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231021)(93006095)(93001095)(100000703101)(100105400095)(6041248)(20161123555025)(20161123558100)(20161123564025)(20161123562025)(201703131423075)(201702281528075)(201702281529075)(201703061421075)(201703061406153)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BN6PR14MB1652;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BN6PR14MB1652; X-Forefront-PRVS: 048396AFA0 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(6009001)(39860400002)(376002)(346002)(24454002)(199003)(189002)(8676002)(47776003)(75432002)(86362001)(2906002)(66066001)(305945005)(50226002)(229853002)(8936002)(189998001)(67846002)(23676003)(25786009)(88552002)(83716003)(90366009)(97736004)(6486002)(77096006)(50466002)(81156014)(81166006)(2870700001)(76176999)(50986999)(7736002)(53546010)(33656002)(3846002)(6116002)(5660300001)(101416001)(105586002)(478600001)(316002)(16576012)(6916009)(39060400002)(54906003)(42882006)(16526018)(6666003)(106356001)(2950100002)(4326008)(53936002)(7416002)(6246003)(68736007)(786003)(82746002);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR14MB1652;H:[172.27.38.128];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: cs.rutgers.edu does not designate permitted sender hosts) X-Microsoft-Exchange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z+/wRnx8xitRVyZKp4bwLTpWY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cs.rutgers.edu X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2017 15:53:54.0535 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 062cc502-530e-41e1-0671-08d5252e961e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b92d2b23-4d35-4470-93ff-69aca6632ffe X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR14MB1652 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4 Nov 2017, at 23:01, huang ying wrote: > On Fri, Nov 3, 2017 at 11:00 PM, Zi Yan wrote: >> On 3 Nov 2017, at 3:52, Huang, Ying wrote: >> >>> From: Huang Ying >>> >>> If THP migration is enabled, the following situation is possible, >>> >>> - A THP is mapped at source address >>> - Migration is started to move the THP to another node >>> - Page fault occurs >>> - The PMD (migration entry) is copied to the destination address in >>> mremap >>> >> >> You mean the page fault path follows the source address and sees >> pmd_none() now >> because mremap() clears it and remaps the page with dest address. >> Otherwise, it seems not possible to get into handle_userfault(), >> since it is called in >> pmd_none() branch inside do_huge_pmd_anonymous_page(). >> >> >>> That is, it is possible for handle_userfault() encounter a PMD entry >>> which has been handled but !pmd_present(). In the current >>> implementation, we will wait for such PMD entries, which may cause >>> unnecessary waiting, and potential soft lockup. >> >> handle_userfault() should only see pmd_none() in the situation you >> describe, >> whereas !pmd_present() (migration entry case) should lead to >> pmd_migration_entry_wait(). > > Yes. This is my understanding of the source code too. And I > described it in the original patch description too. I just want to > make sure whether it is possible that !pmd_none() and !pmd_present() > for a PMD in userfaultfd_must_wait(). And, whether it is possible for > us to implement PMD mapping copying in UFFDIO_COPY in the future? > 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)); + ret = false; if (pmd_trans_huge(_pmd)) goto out; — Best Regards, Yan Zi From 1583193509499365560@xxx Sun Nov 05 03:03:07 +0000 2017 X-GM-THRID: 1583030690684131137 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread