From patchwork Fri Apr 3 11:29:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 11472567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 607941805 for ; Fri, 3 Apr 2020 11:29:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D40920857 for ; Fri, 3 Apr 2020 11:29:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="e7D7Emgb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D40920857 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 3EEF68E000D; Fri, 3 Apr 2020 07:29:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 39FD58E0007; Fri, 3 Apr 2020 07:29:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DEB68E000D; Fri, 3 Apr 2020 07:29:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id CD4F48E000D for ; Fri, 3 Apr 2020 07:29:38 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 600358245571 for ; Fri, 3 Apr 2020 11:29:38 +0000 (UTC) X-FDA: 76666323636.21.skirt96_3704d82ab9250 X-Spam-Summary: 2,0,0,f07e3b49ce5735b5,d41d8cd98f00b204,kirill@shutemov.name,,RULES_HIT:41:69:355:379:541:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3354:3865:3867:3868:3871:3872:3874:4250:5007:6119:6261:6653:7903:8957:10004:11026:11232:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13161:13229:13894:14096:14181:14394:14721:21080:21212:21444:21451:21627:21987:30003:30054:30070,0,RBL:209.85.208.175:@shutemov.name:.lbl8.mailshell.net-66.201.201.201 62.8.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: skirt96_3704d82ab9250 X-Filterd-Recvd-Size: 5510 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Apr 2020 11:29:37 +0000 (UTC) Received: by mail-lj1-f175.google.com with SMTP id b1so6587979ljp.3 for ; Fri, 03 Apr 2020 04:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JyG4ZK4aUipdi7l1+T9raGPiyVfjwGerp10mgDADK/g=; b=e7D7EmgbeOg4wV7XYkB6LstaOwCRw67bTZ64C4M23mg6OujN+tMKmAkpzQ9jKTpyTJ KxuyKX9jKpE+54QURhvJKVl6D91OVqshcTmGntYjrpOrRN9Xsa79rJBPFl++qnp484tX yBPZQRoEesmxEQBb0ohdDqb3FYEhmSTuA+D7bmCVanFSAg/leJEfQp0/rkFHjc90Rt8c Gqx37GTb6CIFM2nz/wuMUUNIOqtHWTIyWKf341A4xRTJUCW7nBhwDmF8W8hdgaK756YS DvqxrRwGJHAQxWysJkOlgVwFrOiRaA+HpZNlWBVQsoPfZUOoK0G3KQYxrNB8ePQT6Hyy BtRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JyG4ZK4aUipdi7l1+T9raGPiyVfjwGerp10mgDADK/g=; b=QliGYEsVpy6O44AitdaoYUeZERcI7NJ+ZNCBunNYt5mqnnFO3HGMkMc/KCFoS6gRSx g5hGnI75nUzV62lwoEIWNRRy6xhrPafM/xCSHRU5KvXBVWBqQyPO53nXZPI7XnU4dkZe 2FeBDiIpCoUwHWmD2PZ5JlzNqTvnv1VYjvhVMXLtqxqNLW7kqlbXz9oEWRBKAtjImuio cLQYp3TnDOggPfLOIYEBrruEWEFjpPKNf+ktDYr2HmgDfodmq5x/sRAfaLQNiRL/6XHj Rr6cXrEP+3VYcs/3F0sfJr49Dg0+knPC2fsMkV9i4MfKsbgkGYBdcMMvGdyl6ZaIcNlF IKSg== X-Gm-Message-State: AGi0PuaqJZZuJK5cGp4Tjf0goYxbUQVj99LgwVY1aXy/auHv/wnYEbmu WTW6lCXSnP6CHUX22fDcdTRFA+qEJTI= X-Google-Smtp-Source: APiQypJ8HECNkEXU+lf1IzeCv/XpLsXDQZbo2YR6k66TkqgEGuWkHBHPcBP20GcHpu4L0lv61PyUhA== X-Received: by 2002:a2e:7a0b:: with SMTP id v11mr4343569ljc.120.1585913376132; Fri, 03 Apr 2020 04:29:36 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id c2sm6070260lfb.43.2020.04.03.04.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 04:29:34 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 7FF00101333; Fri, 3 Apr 2020 14:29:31 +0300 (+03) To: akpm@linux-foundation.org, Andrea Arcangeli Cc: Zi Yan , Yang Shi , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 5/8] khugepaged: Allow to callapse a page shared across fork Date: Fri, 3 Apr 2020 14:29:25 +0300 Message-Id: <20200403112928.19742-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200403112928.19742-1-kirill.shutemov@linux.intel.com> References: <20200403112928.19742-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 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: 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)) { 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; }