From patchwork Fri Mar 27 17:05:59 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: 11462713 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 393AD913 for ; Fri, 27 Mar 2020 17:06:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F160F2073B for ; Fri, 27 Mar 2020 17:06:25 +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="fNHTd/MA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F160F2073B 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 633C86B0074; Fri, 27 Mar 2020 13:06:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 553EF6B0071; Fri, 27 Mar 2020 13:06:09 -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 044146B0074; Fri, 27 Mar 2020 13:06:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id 9E5726B0070 for ; Fri, 27 Mar 2020 13:06:08 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 82100180AD815 for ; Fri, 27 Mar 2020 17:06:08 +0000 (UTC) X-FDA: 76641770016.29.scent39_6fc3656982401 X-Spam-Summary: 2,0,0,8e003c3fca8abb9a,d41d8cd98f00b204,kirill@shutemov.name,,RULES_HIT:41:69:355:379:541:960:973:981:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3353:3608:3865:3866:3867:3868:3870:3871:3872:4117:4250:5007:6119:6261:6653:8957:10004:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14096:14110:14181:14394:14721:21063:21080:21444:21451:21524:21627:21987:21990:30003:30054:30070,0,RBL:209.85.208.196:@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: scent39_6fc3656982401 X-Filterd-Recvd-Size: 6126 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 17:06:07 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id r7so3324775ljg.13 for ; Fri, 27 Mar 2020 10:06:07 -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=ThpcVoxxySBsyGDL9yqIPPj2mnnyBXzq6rEXvZDPIuA=; b=fNHTd/MARGBDdMO/5j8pGyv1gV0nBmX6x3XXpQnpq1EssAZZ1iPmkK24TfgSdoIPZ7 zB+EDT1S8pUEnv4AU2xKOt/qRJw7Brw6WoyxvFeKej16Mv20jxP8xGZSLsE04KJhwz4m zYuRXoJsT3WE0gMGKx2NqYQYonIYj6KDAwwAQhsB5sQtLXcKsWmZWMxgNfqbXoENWLYj Tm/dpS/UUQagNliXw1OPspoP8YQYKKKbnrditaiksEOnKWJoYKu/QLPfwqOn4FsZ8nZN FLuhSnDFJgoGb2EI79yLSfh49rnhZPCtq6WLO1L+oSgIMgFPJbbJ0n7490F2GybiezZ8 TWQQ== 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=ThpcVoxxySBsyGDL9yqIPPj2mnnyBXzq6rEXvZDPIuA=; b=e+tiWkj4niLZ8eg5uVpc53YfyAUSU/PNdonLPazD8jsBJm+OxfpoK4HeeNTSuz9WNN Ko9awEb01YpC1r7YcKkYNI+pyL/Yi31GtvOigP2SJfTk+Tnw+nShGIJoxSIJLk+wbIHm tt6gk3kJhu/nP9xNOiArq8pYewRrZqPGf0gohVkJrXiZ5hbvXo0EzA1eef1YoW0CdpC3 mRdXukrRjvotGL2JPKwiLijcSSChcx0ev6/lvPQd6izcw+gUUia/oVsFvZdTlKegmRH9 DKpf9aDxnb1Ng3NDQYsshQb/RzD8Pq/LuI7aPtYfkhZ6P8p/xX5YPrcOsRZDsvH75yFs c3Gw== X-Gm-Message-State: ANhLgQ0Z9FcwutuSewUw+XxBpVgDPvnH8Tjit+2t+8Lr2VEBwj0qcf11 xUiweQQGEhlBNm/8sYNhMAZWJEeXV5Q= X-Google-Smtp-Source: APiQypLtn/NpXZCnCXpoQScUjDIxmuhP+tRIc0nLOzigxrfVLxvwc+v9+cf1EYMqS3kUQzsle5YSxQ== X-Received: by 2002:a2e:730e:: with SMTP id o14mr8917059ljc.273.1585328765915; Fri, 27 Mar 2020 10:06:05 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id u8sm3272039lfi.12.2020.03.27.10.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 10:06:05 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 7673A100D2A; 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 5/7] khugepaged: Allow to collapse PTE-mapped compound pages Date: Fri, 27 Mar 2020 20:05:59 +0300 Message-Id: <20200327170601.18563-6-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: We can collapse PTE-mapped compound pages. We only need to avoid handling them more than once: lock/unlock page only once if it's present in the PMD range multiple times as it handled on compound level. The same goes for LRU isolation and putpack. Signed-off-by: Kirill A. Shutemov --- mm/khugepaged.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b47edfe57f7b..c8c2c463095c 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -515,6 +515,17 @@ void __khugepaged_exit(struct mm_struct *mm) static void release_pte_page(struct page *page) { + /* + * We need to unlock and put compound page on LRU only once. + * The rest of the pages have to be locked and not on LRU here. + */ + VM_BUG_ON_PAGE(!PageCompound(page) && + (!PageLocked(page) && PageLRU(page)), page); + + if (!PageLocked(page)) + return; + + page = compound_head(page); dec_node_page_state(page, NR_ISOLATED_ANON + page_is_file_cache(page)); unlock_page(page); putback_lru_page(page); @@ -537,6 +548,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, pte_t *_pte; int none_or_zero = 0, result = 0, referenced = 0; bool writable = false; + LIST_HEAD(compound_pagelist); for (_pte = pte; _pte < pte+HPAGE_PMD_NR; _pte++, address += PAGE_SIZE) { @@ -561,13 +573,23 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, goto out; } - /* TODO: teach khugepaged to collapse THP mapped with pte */ + VM_BUG_ON_PAGE(!PageAnon(page), page); + if (PageCompound(page)) { - result = SCAN_PAGE_COMPOUND; - goto out; - } + struct page *p; + page = compound_head(page); - VM_BUG_ON_PAGE(!PageAnon(page), page); + /* + * Check if we have dealt with the compount page + * already + */ + list_for_each_entry(p, &compound_pagelist, lru) { + if (page == p) + break; + } + if (page == p) + continue; + } /* * We can do it before isolate_lru_page because the @@ -640,6 +662,9 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, page_is_young(page) || PageReferenced(page) || mmu_notifier_test_young(vma->vm_mm, address)) referenced++; + + if (PageCompound(page)) + list_add_tail(&page->lru, &compound_pagelist); } if (likely(writable)) { if (likely(referenced)) { @@ -1185,11 +1210,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, goto out_unmap; } - /* TODO: teach khugepaged to collapse THP mapped with pte */ - if (PageCompound(page)) { - result = SCAN_PAGE_COMPOUND; - goto out_unmap; - } + page = compound_head(page); /* * Record which node the original page is from and save this