From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DE24C2D0EA for ; Wed, 8 Apr 2020 13:10:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EBC5F206F7 for ; Wed, 8 Apr 2020 13:10:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="nTNqL7ZG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBC5F206F7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 802FE8E0010; Wed, 8 Apr 2020 09:10:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B3EE8E000D; Wed, 8 Apr 2020 09:10:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A2B78E0010; Wed, 8 Apr 2020 09:10:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 4ECB28E000D for ; Wed, 8 Apr 2020 09:10:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 03DC4180AD802 for ; Wed, 8 Apr 2020 13:10:44 +0000 (UTC) X-FDA: 76684722408.09.hose70_408838acc7f14 X-HE-Tag: hose70_408838acc7f14 X-Filterd-Recvd-Size: 5493 Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Apr 2020 13:10:43 +0000 (UTC) Received: by mail-lj1-f194.google.com with SMTP id g27so7507739ljn.10 for ; Wed, 08 Apr 2020 06:10:43 -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=BUHuVlYN6QeyMcVm8WzZFSO8n2QnUECA5HmKCIx/+3LENPj6dRkpHJADw3IZ4/vYvx NyyE+WQMKzjPv6km7tbYqHrTWq3Cszy9sEycc+flv8BawLRBcVAzhdkJ7oOICdYSsCN1 pKWBOEdyfqKFYm9rtHk91WtRqYPufMqMd72/pjvErdCwSbCc1ZpHR4LKU8d5o8P4+u3v cKkSgnR7b3oq0FQ/NIKL71AfdrtpLEEMi8q5NLsZMOqr5T234/Nb/g+v80ZIde4hnFcC W9vXvYtEyBv3sY07GnC75O1v75qf20/+gsJpDHt0WCdYH6dLxqwjEXIB3ZDFpmFa3V/m ei3Q== X-Gm-Message-State: AGi0PuYBRLyDFQOYi8sKxucBpDgOYLTqU7gIgQu5bioZBdOXV4w2EFSJ ciAPqD706i2Khv5aDtoLb3vkT1o3u3Y= X-Google-Smtp-Source: APiQypJPSrbG2Ixz/cE4+xztuwk2rMJ9aobAkR1ZshWniVSffrmzNbf8NLVxf2+u2KqN/5VIJU4LUQ== 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: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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