From patchwork Fri Mar 27 17:05:58 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: 11462703 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 863B71667 for ; Fri, 27 Mar 2020 17:06:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 494E320774 for ; Fri, 27 Mar 2020 17:06:09 +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="kGB2Kiza" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 494E320774 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 929A06B006C; Fri, 27 Mar 2020 13:06:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8ABF16B0071; Fri, 27 Mar 2020 13:06:06 -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 708006B0070; Fri, 27 Mar 2020 13:06:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 524776B000E for ; Fri, 27 Mar 2020 13:06:06 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 394C8181AD0A4 for ; Fri, 27 Mar 2020 17:06:06 +0000 (UTC) X-FDA: 76641769932.26.dress79_6f726c8250122 X-Spam-Summary: 2,0,0,b21dc21858f9de8d,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:3866:3867:3868:3870: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.193:@shutemov.name:.lbl8.mailshell.net-62.8.0.100 66.201.201.201,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:23,LUA_SUMMARY:none X-HE-Tag: dress79_6f726c8250122 X-Filterd-Recvd-Size: 5733 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 17:06:05 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id q19so10921954ljp.9 for ; Fri, 27 Mar 2020 10:06:05 -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=fCQS2NypN0JhzS0ypfUQeVkn+9tCE2dlRA9LI38iq5A=; b=kGB2Kiza8RBWjYqxA3azU6g8J+6XrN9ulu4WXST9nTuu7lCP+8CM9665C9vnVCYq54 a54sLLad2b2bTddxdKbxR7qHl+0LKFhsMw61E1fYfXl7LzKcj+gX4gaotJhuZNR4aKUF s2u6W4nwNqfG9/o7+MBxAp0NSDCKH6hAROgHEnlVip56MyiJ7W3YZYHlgIvp9m2ZyLuG Ah2k+r1+ivnzGTsaJwo5xxCsuEd7s3YIYTHKWJJnhB38iR2aXTLScV37U1ksZN6YNXMX 6IiWaat9A/HJGfNaanM/u784X4QNsGw7Uit8DElFc6L58KRu9Br4VDrfkFVrR0M8FTzW rS9A== 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=fCQS2NypN0JhzS0ypfUQeVkn+9tCE2dlRA9LI38iq5A=; b=isF//rFbRxiC9sjcUamujbB/ebNp3ZQdeB8Wn23zmbq2hIP/o0WJ/Oj8wQ6MT2utbc uU1Jbiz1Ee7XbMiFbc1SOWb2/BTrhSYjpKiUAwvOkAR1uFX/T3dOhMneltdsP/zpcgBg grFa4fS1qscHokq3JmcljjBJ4tYXOhMzLJVMWD/NVomrlT2xUp7LXCXJ2y8YlEjbdj9f jgn/J+xgvgMz7unlxK7OHyK9hCTxPfMlUA4dgB0URMQG/R76K/K6URj6U9vNR2JI/Lrv ogZ1ex11/Ca2SzCgRDGB0pU86R4VwXqUgWYuppHWh76t3HbBpcEXDzF06HEzSaZZVRs1 +ZJA== X-Gm-Message-State: AGi0PuadaXa5TbB8q4o7gBtlPshHeF0jhzrxIkGoQwT2GR32kt10yabn qofau8UTGT0QPrAkoR1a6WmKBtNfhI0= X-Google-Smtp-Source: APiQypKBQAwVwbRAVi/qZWZFWn/tOxio6lk6NKivsgpAW6fPbyvc3MwwRJKbLPJvgEySXhgoHQQ6lQ== X-Received: by 2002:a2e:854e:: with SMTP id u14mr8553799ljj.182.1585328763840; Fri, 27 Mar 2020 10:06:03 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id o68sm3692303lff.81.2020.03.27.10.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 10:06:03 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 6FEFD100D29; Fri, 27 Mar 2020 20:06:07 +0300 (+03) To: akpm@linux-foundation.org, Andrea Arcangeli Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 4/7] khugepaged: Allow to callapse a page shared across fork Date: Fri, 27 Mar 2020 20:05:58 +0300 Message-Id: <20200327170601.18563-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200327170601.18563-1-kirill.shutemov@linux.intel.com> References: <20200327170601.18563-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 | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 39e0994abeb8..b47edfe57f7b 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -581,18 +581,26 @@ 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)) { /* * Drain pagevec and retry just in case we can get rid * of the extra pin, like in swapin case. */ lru_add_drain(); } - 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; @@ -680,7 +688,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 @@ -1209,12 +1216,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; }