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, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 5E11DC43331 for ; Fri, 27 Mar 2020 18:54:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DE9C206F2 for ; Fri, 27 Mar 2020 18:54:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uKk3zRzH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DE9C206F2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B64D56B0032; Fri, 27 Mar 2020 14:54:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3DAD6B0036; Fri, 27 Mar 2020 14:54:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A52CC6B0037; Fri, 27 Mar 2020 14:54:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id 8FD946B0032 for ; Fri, 27 Mar 2020 14:54:14 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A915A40EE for ; Fri, 27 Mar 2020 18:54:14 +0000 (UTC) X-FDA: 76642042428.11.skate46_2505697ab323a X-HE-Tag: skate46_2505697ab323a X-Filterd-Recvd-Size: 7280 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 18:54:14 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id i24so12576054eds.1 for ; Fri, 27 Mar 2020 11:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pcrGpCxgH824Ygm9MUy2KnbWGWn400IfTnGNSoBI9xg=; b=uKk3zRzH1OEHCX1RtvyvcGzx4E3IEIVp5Ohw1N+N9Y1iPwnw2kMZh+c/F1fsBA57y2 lZ/Ybmr4jwUr6FEVYolcsxSkK42qr8fBdzm1kJzKyQg3H9RPbKs4Bxd4G0LZICCwurvb Cxfrjj0UpC3t3sV/Uht6AkGJFnk7Zj/nG9EwxZnKmQcRBd5Oy2Tz+b6+eum3DS3VNnl5 KBTJtJx20X+WihMudbsY4Q+A1Z3cYUw51JQwg1X1YhQpaxJqCFmW3gzaibprmdvLPAGK fhbn9gelY7ap+eihtT/nwwpYf1p+LnSmqPNaX2yxhX72xBxuZ3bSMq7XUFt3CMMhnS2m h2Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pcrGpCxgH824Ygm9MUy2KnbWGWn400IfTnGNSoBI9xg=; b=UG3i/Q4dWWTiM+dVuoaFCe1Dobpy9Q+J9mqaFkSwsGsCcl6D1g64N0QPVY5jdEfytS ABl3CauQZzic7xcGweUSwU5f47n9M72z/hZCGyiCdxZ1HCcJaedqzzLq9E00fBydtFGm r59UFClkgTZUUeAWWz1R7oVVibveVe3BmXooJMT6S11tAVuXZCrbWN0oQGOqiKkEbFg3 hHuweyA8wlEJoU35p2j2VDXrJ47KTl3ZywwJ1Wv62BTDP3r/ThlzSDsCzP+6tLFL+FzS OMEEkqg4y9lcglYYRu1s7D8cIkBsEDUGxO//+BCwrBF7L7xChWo2ThbhOZDbgPusn8JO l5Zw== X-Gm-Message-State: ANhLgQ0TO0H2luW07rrOWU03vaPMGCR4gYptgpcI7RT7BYWvIjInFDP7 +PwI+v/JFKFhIZFNOa2q0DbOJ+uSOOD978uM7hc= X-Google-Smtp-Source: ADFU+vuyIsUnBLuES5LHtMZa05T+VdrxUHyHV72oRhfnbRBc6BJbZATK158iRJsCXSSwUGtlnYSLS17pAGgDZaLgDrg= X-Received: by 2002:a17:906:3e0c:: with SMTP id k12mr369897eji.309.1585335252748; Fri, 27 Mar 2020 11:54:12 -0700 (PDT) MIME-Version: 1.0 References: <20200327170601.18563-1-kirill.shutemov@linux.intel.com> <20200327170601.18563-6-kirill.shutemov@linux.intel.com> In-Reply-To: <20200327170601.18563-6-kirill.shutemov@linux.intel.com> From: Yang Shi Date: Fri, 27 Mar 2020 11:53:57 -0700 Message-ID: Subject: Re: [PATCH 5/7] khugepaged: Allow to collapse PTE-mapped compound pages To: "Kirill A. Shutemov" Cc: Andrew Morton , Andrea Arcangeli , Linux MM , Linux Kernel Mailing List , "Kirill A. Shutemov" Content-Type: text/plain; charset="UTF-8" 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 Fri, Mar 27, 2020 at 10:06 AM Kirill A. Shutemov wrote: > > 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)); We need count in the number of base pages. The same counter is modified by vmscan in base page unit. Also need modify the inc path. > 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 s/compount/compound > + * already > + */ > + list_for_each_entry(p, &compound_pagelist, lru) { > + if (page == p) > + break; > + } > + if (page == p) > + continue; I don't quite understand why we need the above check. My understanding is when we scan the ptes, once the first PTE mapped subpage is found, then the THP would be added into compound_pagelist, then the later loop would find the same THP on the list then just break the loop. Did I miss anything? > + } > > /* > * 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 > -- > 2.26.0 > >