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, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 9EAECC43331 for ; Sat, 28 Mar 2020 00:40:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B7B32073B for ; Sat, 28 Mar 2020 00:40:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="fNWCum4i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B7B32073B 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 D97596B0010; Fri, 27 Mar 2020 20:40:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D47616B0032; Fri, 27 Mar 2020 20:40:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C37816B0036; Fri, 27 Mar 2020 20:40:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id A6B8C6B0010 for ; Fri, 27 Mar 2020 20:40:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 72EE83A91 for ; Sat, 28 Mar 2020 00:40:32 +0000 (UTC) X-FDA: 76642915104.14.stick89_4ac558779e59 X-HE-Tag: stick89_4ac558779e59 X-Filterd-Recvd-Size: 8045 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Sat, 28 Mar 2020 00:40:31 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id g12so12121958ljj.3 for ; Fri, 27 Mar 2020 17:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+FisWhjqWo1PYA76QaCjNqAm84UyJGPrz4RPzV+5jag=; b=fNWCum4iIucDNFNtaTAo0xyU7ZzsBFF0ZNjfREajSDxvAovepQrRxQ0saZ/XgCWkaU tnuW7wFXQR2Y9XxPZpELDCckaiVYPBnY4nQQGaSS3BRlnZH78CZgqpKWvWpJZZIMtnEz iT9iBXzUFfwfxNCZuJBjWo5ZlPYbqOA0vosq+N/9nb6JJGC30WkDeVBsMRoYXNJRitMw WLgjIwj8icmlQk8trvjGNFNYRYTo5iZ9A4mvdD2CGey9ss0+/lNXTlzL6BCaJi7vmhdc lMo+uJpiAlKK8j08RMaUFJfD0fuJbJnQ0OkqMP/0O0Hu/LL5gLdGps8E/kJV9/KD45ar WWuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+FisWhjqWo1PYA76QaCjNqAm84UyJGPrz4RPzV+5jag=; b=IcWcgWNVSt5lZh44uqBuWvzZ4kJPRJIsHBOrrrCzQKXNy4encUVm0hRUgyztfKEmp1 IO7n/Bj7dQRkzewbCVjSxA448gegTQHdeALH8wv/2UzcrG6tmL1vuBqt5eVCZ8eoHv/P qyDIOLC9dmyB2hk4B8TiVw8xqpEnGNHlPxCieqFrEasijZX1Sq9c3RxtxhtdvHmBqR2u 470r8KSRhxWW20EWvs5xcK5DevLYoe/CwJTqWBZD11iZBwRc6zocy4FUjs/0GQKiaP7D RZXflTW64hc8V1X3JS2LAh9j90AN3HF/aFfJI6L+HI3JEbEZKoEen9Y/vFI9UqDXFReB JRFw== X-Gm-Message-State: AGi0PuYXm4uKvtKDs1xyZOEVDtm41ZazDFs/iVvsj53wx1GwBuoKuJrz TF6RrIja/lMgUzZos5vAFd3M9w== X-Google-Smtp-Source: APiQypKII5PlcD+0XsbaFHGaLwcnfoyhNCINWx5abcH54LdNV/gY6lDr0VV7H7Glunh971IwSqNGmw== X-Received: by 2002:a2e:b4cc:: with SMTP id r12mr889019ljm.50.1585356030580; Fri, 27 Mar 2020 17:40:30 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id w29sm4119341lfq.27.2020.03.27.17.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 17:40:30 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 7A757101C38; Sat, 28 Mar 2020 03:40:34 +0300 (+03) Date: Sat, 28 Mar 2020 03:40:34 +0300 From: "Kirill A. Shutemov" To: Yang Shi Cc: Andrew Morton , Andrea Arcangeli , Linux MM , Linux Kernel Mailing List , "Kirill A. Shutemov" Subject: Re: [PATCH 5/7] khugepaged: Allow to collapse PTE-mapped compound pages Message-ID: <20200328004034.jhzpqlv4riid27mh@box> References: <20200327170601.18563-1-kirill.shutemov@linux.intel.com> <20200327170601.18563-6-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 01:45:55PM -0700, Yang Shi wrote: > 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)); > > unlock_page(page); > > putback_lru_page(page); > > BTW, wouldn't this unlock the whole THP and put it back to LRU? It is the intention. > Then we may copy the following PTE mapped pages with page unlocked and > on LRU. I don't see critical problem, just the pages might be on and off > LRU by others, i.e. vmscan, compaction, migration, etc. But no one could > take the page away since try_to_unmap() would fail, but not very > productive. > > > > @@ -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 > > -- > > 2.26.0 > > > > -- Kirill A. Shutemov