Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp627138ybb; Wed, 8 Apr 2020 06:51:04 -0700 (PDT) X-Google-Smtp-Source: APiQypID/YkspT+ci1s+3nfwGHSjzk9qTkIgdL14Tg6BhqXrqspE9xo5GvhNLkj2I6ix54D27g7V X-Received: by 2002:a9d:1c8e:: with SMTP id l14mr6007211ota.151.1586353864803; Wed, 08 Apr 2020 06:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586353864; cv=none; d=google.com; s=arc-20160816; b=ojrg8XOgfCDVViBHqIFHF6/1YlRkEw5cqNt4C8u2LIuqPH3brb1pBOV/jbBXZDjmT3 mS/jCIN5Yizoi+IvQa/ID54HeaWVQzUBhjhCkSl3Y2FC763BXognQ1KjkW3BNF3mtyQa +5sG/CilHX0G08H6s2VMDE1DF788KZAfCDNzat3UdaBDOaMQjpcFt4q19UxNPZxnDO8z QI6ALsVzjTDggIRpxOieyXYjvX6IMkvd0c1vDWCUb/W3wwgDblVJasfQ2NqS1I7hN9Q/ uMFMSbvOSRX47LGtWdsfJNv6fjtfnFbwhg6hfwWH9ppIKCMrSh7lzmM7YRwuJFt5DKGo Q0fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HeDObZJxLV3Baeqk/9dArQNSiUzldFhMXAdfdoz3UVU=; b=ByxlKP948DQpQg2SJ7YuCpZPaJRmoUoGUmRkoZaSvOQ8aLd3ndYW7HEQqVZaXJeBDn JqENTwBASq2EpCJfGhMv+cJgYltdqXmQ0v6OzRHaIq4FfDekj5TYPejy2XbDpp749acu vGunS2+9TwVPk0LK8N7+zmvgHzUQFTP1Eb8exH6n1XeQOhbAPa+cnLc3N6MDPCNiPRMX jo4NV50PV8irkdf0V9jkmr1DXp9tYpePKkJK39yoJsBd5vRFoQzjuJDO+Cvc2fv0pIVD 4LtLPeDq84IHbAt2Rk5Y+PZYOb67Af6XjhV/TsozFaBBH+f+C5YL4WemUGsu3yg6sr4t W8Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=nTNqL7ZG; 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 y19si1904024oie.128.2020.04.08.06.50.50; Wed, 08 Apr 2020 06:51:04 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=nTNqL7ZG; 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 S1728986AbgDHNKo (ORCPT + 99 others); Wed, 8 Apr 2020 09:10:44 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38557 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727942AbgDHNKo (ORCPT ); Wed, 8 Apr 2020 09:10:44 -0400 Received: by mail-lj1-f194.google.com with SMTP id v16so7575330ljg.5 for ; Wed, 08 Apr 2020 06:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=HeDObZJxLV3Baeqk/9dArQNSiUzldFhMXAdfdoz3UVU=; b=nTNqL7ZGNrn6gUWwrJC1pZtcbV0TqdYBTWeApxSsfG6b73fSXTA6kNuCcKl0xKeVck YQkApC8olrtu2QQoUMlLN3xrBP/vZO61Jb/iqUFsWSo8EnKbPSe24f43UyhI/mzbrnNo vpxzrV2zX0WfTTBRop+3OjEgWq9MgUOP5Noj+lJkeyvLUMTFNrlMXI5lWOh3s2sODvdN LCexAWqE35hes7CrTYyXhXfHFYlPa34iXo1xXu78YzXznKaaXUXz6tl56UX33UfixWBr OuPhJtKTEhBVZaKlMkcG8ohFMR/272JG/UgHOR3Su0SluZYzUdDN0l0JV03p9ieNwH4y 6TVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HeDObZJxLV3Baeqk/9dArQNSiUzldFhMXAdfdoz3UVU=; b=uGAFRHPEd6Rq9tC0AEkUnzhEhg9/6pRseiwyYpOj8HmLqrsdt0Sac01bQcvnPTDwWZ ntcAY2UY5WTaeark1GwfZ1RMrRDqHYqfp9KURp2K6qS91iFEQJo1LtOdV0GwX8flKcIo vcBr+Pp8drm894bg/MJagOlPoCyvnaC2RlD4CSfnqMzCUUq05+p2a3r6MHo3ddn26z+/ 5pMUp/9gCVfLQ7MYBuHuGmp3F3WpdHysVMJAYRd/GOH+JPCRkEtAoXj97edl6LXza3IA OP68/Nlvbaqn7TUg+/kD3Ppb7pvCEpvWPJkgdeeEnfwTzQVCPmPV4QX10GBa3E0RLTcB 1gLQ== X-Gm-Message-State: AGi0PuaUCNmKshdB3MRrr7fKrKIojhJD2mwd6c1gldHCd3WDSgWNz5tS mHD+yse8Z/PHrSrPbU02ZVNoIQ== X-Received: by 2002:a2e:8015:: with SMTP id j21mr4725392ljg.165.1586351441627; Wed, 08 Apr 2020 06:10:41 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id z9sm13932102lfd.9.2020.04.08.06.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 06:10:40 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 75143101C47; Wed, 8 Apr 2020 16:10:44 +0300 (+03) Date: Wed, 8 Apr 2020 16:10:44 +0300 From: "Kirill A. Shutemov" To: Yang Shi Cc: akpm@linux-foundation.org, Andrea Arcangeli , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [PATCHv2 5/8] khugepaged: Allow to callapse a page shared across fork Message-ID: <20200408131044.xzlheacvslrbwrja@box> References: <20200403112928.19742-1-kirill.shutemov@linux.intel.com> <20200403112928.19742-6-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 06, 2020 at 01:50:56PM -0700, Yang Shi wrote: > > > 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. > > + * > > + * 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)) { > > This check looks fine for base page, but what if the page is PTE-mapped THP? > The following patch made this possible. > > If it is PTE-mapped THP and the page is in swap cache, the refcount would be > 512 + the number of PTE-mapped pages. > > Shall we do the below change in the following patch? > > extra_pins = PageSwapCache(page) ? nr_ccompound(page) - 1 : 0; > if (total_mapcount(page) + PageSwapCache(page) != page_count(page) - > extra_pins) { > ... Looks like you're right. It would be nice to have a test case to demonstrate the issue. Is there any way to trigger moving the page to swap cache? I don't see it immediately. -- Kirill A. Shutemov