Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2780681ybb; Fri, 27 Mar 2020 11:56:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvlOjPQ/h/C1Pe94pc2AGCnC/mTJzoZ1DWd0E55rXkSbSBRzyfQ1P87Yxd2ts/1fVhV7kEX X-Received: by 2002:a4a:1ec3:: with SMTP id 186mr709573ooq.66.1585335378292; Fri, 27 Mar 2020 11:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585335378; cv=none; d=google.com; s=arc-20160816; b=zpe07YAvXs8jZ0Q2iiPsIH8iq0JX3hZiR6IvwwQIc8KtlJRCfjjax+BVAN1IN9OLHz byJpP6MH3ScA6e78dTKgGEvopToVdmY7Yn2rD6CwiYxbfrvyCR4bB98bjd59pYzJe+uw Sx8IgGJvVrr1JtH0i+/Sfa4U82gr6NRkusS1nqycAAFcatZZU8wjKD7n+RnPlxan4f1r yTWZ2xpgzI38jnO01pLb5DyTJFtOKt5tyxCNpvzb4vK0F1p25qCy4NoBh1Wdjr4nWKuW N4vsIRafk6hq33ZMs6wOP4DvXTp++mQnc0AwNuWv2wjxTySpzWRjaK6Hz2IYkU1jLFPc 4SpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=db8inRFEgCho5kZGVFCanLkzLlprHBygNGihcIGUiMg=; b=rVER/vVPyReOhmEQOFM9wfI1iZasW4ivHVT4U/oPkHu65eVbJbtYAwq8zPi82yRtqF kmT3p4yRJQQjYh7yj/4BUcGpgNJcEvBZgXOwtVzslv4fyrjCB4jY0k/YB5xR7P+dCzSF YcLLhijdalcUlJzgHYAm5qXKMgA0hJau0waz3PWr5v0fOUOHBirvbC03x871qf55HPW5 ORldlbMq8SlALMBKt/+wbcza4At/CcoDadIaPw1x/Hx29ffaPkf59rTRTheVMpTegp5s EXEN9qiqR6zm+jhI5OEYUM60xCjc1SkCR6I0mFhnP0V857+JugpKYB3XuXBrEc/cOhSe qNsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ZIyaxiqt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si717534otg.196.2020.03.27.11.56.03; Fri, 27 Mar 2020 11:56:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ZIyaxiqt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727352AbgC0SzK (ORCPT + 99 others); Fri, 27 Mar 2020 14:55:10 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:12072 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgC0SzK (ORCPT ); Fri, 27 Mar 2020 14:55:10 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 27 Mar 2020 11:53:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 27 Mar 2020 11:55:09 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 27 Mar 2020 11:55:09 -0700 Received: from [10.2.174.211] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 27 Mar 2020 18:55:08 +0000 From: Zi Yan To: "Kirill A. Shutemov" CC: , Andrea Arcangeli , , , "Kirill A. Shutemov" Subject: Re: [PATCH 5/7] khugepaged: Allow to collapse PTE-mapped compound pages Date: Fri, 27 Mar 2020 14:55:06 -0400 X-Mailer: MailMate (1.13.1r5680) Message-ID: In-Reply-To: <20200327170601.18563-6-kirill.shutemov@linux.intel.com> References: <20200327170601.18563-1-kirill.shutemov@linux.intel.com> <20200327170601.18563-6-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: multipart/signed; boundary="=_MailMate_FD5AA855-FE04-4B04-8942-69FED85DC9DD_="; micalg=pgp-sha512; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585335216; bh=db8inRFEgCho5kZGVFCanLkzLlprHBygNGihcIGUiMg=; h=X-PGP-Universal:From:To:CC:Subject:Date:X-Mailer:Message-ID: In-Reply-To:References:MIME-Version:X-Originating-IP: X-ClientProxiedBy:Content-Type; b=ZIyaxiqtBQCr/conptCOf99BleVeIjm0n973tA+PpJfQq8pqJ/V8eT/5JucOvazXf knsERFAHsz/cFbxH0tQ+OqEyAoAOEDuY8vMK/LuDK1Pxl2LgaM54lHhtm/9Fz6uUZO zsBHVlZiKjkiQa5E9tnv/3oH/pwzbmjugN0JvX2AwJr6C31U55v7VG9naQ2vV/ij/S wEzpFe7iFc/DT1O6NAgV03lw1B6mIc0cNXSWfX4I4O13mwhT5teQAh/pZMzqTSHPy4 ocES8drit3FxQYScHdrIVQXEzmeAqBZkZ9VhdC5Arszqfp1cBjuyVzc4GB3ukrb2j/ xB7gexDzVynzA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=_MailMate_FD5AA855-FE04-4B04-8942-69FED85DC9DD_= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 27 Mar 2020, at 13:05, 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 presen= t > in the PMD range multiple times as it handled on compound level. The > same goes for LRU isolation and putpack. s/putpack/putback/ > > 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); It only checks base pages. Add VM_BUG_ON_PAGE(PageCompound(page) && PageLocked(page) && PageLRU(page), p= age); to check for compound pages. > + > + if (!PageLocked(page)) > + return; > + > + page =3D 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_a= rea_struct *vma, > pte_t *_pte; > int none_or_zero =3D 0, result =3D 0, referenced =3D 0; > bool writable =3D false; > + LIST_HEAD(compound_pagelist); > > for (_pte =3D pte; _pte < pte+HPAGE_PMD_NR; > _pte++, address +=3D 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 =3D SCAN_PAGE_COMPOUND; > - goto out; > - } > + struct page *p; > + page =3D 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 =3D=3D p) > + break; > + } > + if (page =3D=3D p) > + continue; > + } > > /* > * We can do it before isolate_lru_page because the > @@ -640,6 +662,9 @@ static int __collapse_huge_page_isolate(struct vm_a= rea_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)) { Do we need a list here? There should be at most one compound page we will= see here, right? If a compound page is seen here, can we bail out the loop early? I guess = not, because we can a partially mapped compound page at the beginning or the e= nd of a VMA, right? > @@ -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 =3D SCAN_PAGE_COMPOUND; > - goto out_unmap; > - } > + page =3D compound_head(page); > > /* > * Record which node the original page is from and save this > -- = > 2.26.0 =E2=80=94 Best Regards, Yan Zi --=_MailMate_FD5AA855-FE04-4B04-8942-69FED85DC9DD_= Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEEh7yFAW3gwjwQ4C9anbJR82th+ooFAl5+TAoPHHppeUBudmlk aWEuY29tAAoJEJ2yUfNrYfqKQPUP/Asndkpg6Oz1IwSvvKjmXoaCK8VTGM5DmGeZ KGr8ndYiS9JfOiOCoxX7dpj3XjnpV9t3Xe9Ih6UdDRuBirk+ZX779TVbTbajX+Z4 dkfr84PTx0iag6P4CWp451V3CaDPp5eM9eR68hzU1xhAyJ3Rj3/GjFs0eYASDS7e lPNkvNS/1I0tBfz125QYOoD4KBxXcTkeJCSIxOWbJ0+k80tASeYoBDSb+xA+zjCV 8xO6k9X4Oqy61VuBMyZvxFoyAnOuKaAKGc6BmKLe254ks/ki5ckDi/6R4Vix+qcy Ler16LdQOE1oveVg1pPK2r0fSb0JNiaOlzZ5x9G97SCdUh6uCzj0HPq7ljUnK3DA dwI3IH63JcB1lrIhQJIUOaEiC3QGrd4W04IhUEdDQOa0+l7Ulk01G3ewDFdP1mI3 qFm20DAutMHp3RxL5U08inqsm6s9telXL9mSCKTM5xXnCr1yw5USsRXPAinK9NqG 0EcC5E1YmG9weiCNKshulTpIj7vqQiOCOc/RJdu3Fy10LGZ1ZdO/rLuQPtU3MESv +8E7+C0UGloFFif6OqxQ1mdr4hG7SEb0peGkrgMe30rwmnvhSZ0ACAu22n3bQE87 A8+jF7OP/BLCRqx1nr8ngFsMWAfb0I8KikHdX3gGT3xQWq38ZnwN7tKl27BJ60pl UCOwgrSG =gfhJ -----END PGP SIGNATURE----- --=_MailMate_FD5AA855-FE04-4B04-8942-69FED85DC9DD_=--