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=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 1FCD8C2D0ED for ; Fri, 27 Mar 2020 17:06:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D84B220714 for ; Fri, 27 Mar 2020 17:06:07 +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 D84B220714 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) Received: by kanga.kvack.org (Postfix, from userid 40) id 8ABF16B0071; Fri, 27 Mar 2020 13:06:06 -0400 (EDT) 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-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-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 Content-Transfer-Encoding: quoted-printable 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_a= rea_struct *vma, } =20 /* - * 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) !=3D 1 + PageSwapCache(page)) { + if (total_mapcount(page) + PageSwapCache(page) !=3D + 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) !=3D 1 + PageSwapCache(page)) { + if (total_mapcount(page) + PageSwapCache(page) !=3D + page_count(page)) { unlock_page(page); result =3D SCAN_PAGE_COUNT; goto out; @@ -680,7 +688,6 @@ static void __collapse_huge_page_copy(pte_t *pte, str= uct page *page, } else { src_page =3D pte_page(pteval); copy_user_highpage(page, src_page, address, vma); - VM_BUG_ON_PAGE(page_mapcount(src_page) !=3D 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 *m= m, goto out_unmap; } =20 - /* - * 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) !=3D 1 + PageSwapCache(page)) { + /* Check if the page has any GUP (or other external) pins */ + if (total_mapcount(page) + PageSwapCache(page) !=3D + page_count(page)) { result =3D SCAN_PAGE_COUNT; goto out_unmap; } --=20 2.26.0