Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3673452ybb; Mon, 6 Apr 2020 13:17:42 -0700 (PDT) X-Google-Smtp-Source: APiQypJfPgFce9+yt2lGAkqz1RATtIU0M530mQDClB7lKuivA3HrMNlqNM7pO7VKJsoPXwms2NPu X-Received: by 2002:a9d:69d5:: with SMTP id v21mr19518811oto.197.1586204262331; Mon, 06 Apr 2020 13:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586204262; cv=none; d=google.com; s=arc-20160816; b=w/BkopsrhQ0Mop9ujUZWisAp0wE59wxbVUnG/n8Vl3KuMP8z8B1juwEZoS9dRKRAgK 1vKZb6f4OQ+7oglBAox5rqeEtTmcwIWKk5sFl9LFXDfFYPrTiYU3UTBNHolPfrOAwC1d A9dj/WbBr4wuOo2qc6eiXcquB+/xt0RlZ94RvsQF6S8bJgmDMY1gc4pMMi3nexbwV4JU sFLAQwXfwjTKBVIbMrSw+PqCpfvj9Jo7oBfUiCoQXVVAI7D7WVnU3cPzG7Cb3Qj/QJ6q fe5eNEvL3VYhgWKHVJGYEx8AW/7+w1KJXUDdLzWKR2uhgBGaN8AXSqWUygv16d3fq9BD //Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=hFuW01LWHzr2dqJom6FxWQGnFY1OhyVXI3oYPFLQ59E=; b=wkNu0ZTj5xTqDhMK2kCX0uyp3b05Y0emji8AwvsE71coBlnqB0aaHXyujAkCKAzCWg p2nK5OE1cQXSx0SEu7LumHaBVbndUO8bWbsLxrGovGPNSiERydfQ1+zeck2QVTL6Hvur sTDMN+0Y93jfXXk6ag0ZbarX9R3inlBeTkMNlFvjixMf9hPNTaRVbyxhkFNlRS7aSNOc RdQbY4/f2cSrXZIU+zSE0BtLcurK9U7BVnFYa/TZgvXWjYUrgEnyDBfMiBjS6KxQL52I AHVwBLzyEJ1WlQOGmJNI2Vpk0PP8tLgs6Bc9nbnijUwZNRgNWgYtUQdB3oP0CxeIaUi+ xi4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=jbJjCCKR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si266313otm.212.2020.04.06.13.17.29; Mon, 06 Apr 2020 13:17:42 -0700 (PDT) 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; dkim=pass header.i=@nvidia.com header.s=n1 header.b=jbJjCCKR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbgDFUPk (ORCPT + 99 others); Mon, 6 Apr 2020 16:15:40 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:2734 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbgDFUPk (ORCPT ); Mon, 6 Apr 2020 16:15:40 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 06 Apr 2020 13:15:26 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 06 Apr 2020 13:15:39 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 06 Apr 2020 13:15:39 -0700 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 6 Apr 2020 20:15:39 +0000 Received: from rcampbell-dev.nvidia.com (10.124.1.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 6 Apr 2020 20:15:38 +0000 Subject: Re: [PATCHv2 5/8] khugepaged: Allow to callapse a page shared across fork To: "Kirill A. Shutemov" , , Andrea Arcangeli CC: Zi Yan , Yang Shi , , , "Kirill A. Shutemov" References: <20200403112928.19742-1-kirill.shutemov@linux.intel.com> <20200403112928.19742-6-kirill.shutemov@linux.intel.com> X-Nvconfidentiality: public From: Ralph Campbell Message-ID: Date: Mon, 6 Apr 2020 13:15:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200403112928.19742-6-kirill.shutemov@linux.intel.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To DRHQMAIL107.nvidia.com (10.27.9.16) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1586204126; bh=hFuW01LWHzr2dqJom6FxWQGnFY1OhyVXI3oYPFLQ59E=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=jbJjCCKR0rIwyP0jP9LUfP8gwmlKrlfhc+qy4ikTldzH//xZo1teBxU+QFeWnR3oC 5pxPEkak2rlSEedJR6NMijUevh0UjCpuv+vFIk/935VIKD/FQrQqP1dTvqIeV+gdun f1tx9nox2zGqZ7Zf1nOHkfGWilBqVgsSBErruMZNVjbqDKQAF6UICM80pf5gEUdn5E NMT7rq/neenzraOVssAHE3gn0eLU1NXkH0hjHj6o0jFtPgDEgs7SgOf4HzF7qKZ37E RUEUfdu/H1DrDjWE1qoTERXpvPbbldFVDzfqsA+9y+luj77wLIez1l2yXfbPWSeQxf jhgVbweO2CmfA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/3/20 4:29 AM, Kirill A. Shutemov wrote: > The page can be included into collapse as long as it doesn't have extra > pins (from GUP or otherwise). > > Signed-off-by: Kirill A. Shutemov > --- > mm/khugepaged.c | 25 ++++++++++++++----------- > 1 file changed, 14 insertions(+), 11 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 57ff287caf6b..1e7e6543ebca 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -581,11 +581,18 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, > } > > /* > - * cannot use mapcount: can't collapse if there's a gup pin. > - * The page must only be referenced by the scanned process > - * and page swap cache. > + * Check if the page has any GUP (or other external) pins. > + * > + * The page table that maps the page has been already unlinked > + * from the page table tree and this process cannot get > + * additinal pin on the page. s/additinal/an additional > + * > + * New pins can come later if the page is shared across fork, > + * but not for the this process. It is fine. The other process > + * cannot write to the page, only trigger CoW. > */ > - if (page_count(page) != 1 + PageSwapCache(page)) { > + if (total_mapcount(page) + PageSwapCache(page) != > + page_count(page)) { > unlock_page(page); > result = SCAN_PAGE_COUNT; > goto out; > @@ -672,7 +679,6 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page, > } else { > src_page = pte_page(pteval); > copy_user_highpage(page, src_page, address, vma); > - VM_BUG_ON_PAGE(page_mapcount(src_page) != 1, src_page); > release_pte_page(src_page); > /* > * ptl mostly unnecessary, but preempt has to > @@ -1206,12 +1212,9 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, > goto out_unmap; > } > > - /* > - * cannot use mapcount: can't collapse if there's a gup pin. > - * The page must only be referenced by the scanned process > - * and page swap cache. > - */ > - if (page_count(page) != 1 + PageSwapCache(page)) { > + /* Check if the page has any GUP (or other external) pins */ > + if (total_mapcount(page) + PageSwapCache(page) != > + page_count(page)) { > result = SCAN_PAGE_COUNT; > goto out_unmap; > } >