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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4137CC433EF for ; Mon, 13 Jun 2022 15:07:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 839D58D0199; Mon, 13 Jun 2022 11:07:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E92A8D0171; Mon, 13 Jun 2022 11:07:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 663C38D0199; Mon, 13 Jun 2022 11:07:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 54C188D0171 for ; Mon, 13 Jun 2022 11:07:07 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 80A21120A94 for ; Mon, 13 Jun 2022 15:07:06 +0000 (UTC) X-FDA: 79573540452.15.6B4DB61 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf06.hostedemail.com (Postfix) with ESMTP id 7EFDF180451 for ; Mon, 13 Jun 2022 15:06:34 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id 187so5982426pfu.9 for ; Mon, 13 Jun 2022 08:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=8PQPUHpVWVwb+bX67lyMSYeYh55gX9xcLW43w4Hc6KU=; b=c6qZDpn7DLwowOeL8dJN9EYIRWD5396xzrOn9EScmonmPdcKuPrzKN1ShS4yTwz6zQ NSm9ZGACg2ynKXWFWhDUR3rMVJ66KLvNEqb66o5nck2dkxtu/Vm0nvapTbYLgd0pg6f+ 9LaGD+yuKYj2cAuXG6TmGWJpuD5vdkFtTVWiMNhB3bvcDFqEE8epoRGkbkDjMkw12rqQ 4D+e7gU2OQlYw3Um8yIeKH42vRb7jRg6PCcZV6j0k9pc8BVrYxEONlzir+h7FvaocUyM /xc4+y9H2chuTlxPeG1c9y+cXWE0YOVejzGMr/urTsyRKyS4iyP/2mclDSdLdOAI0JDH I59A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8PQPUHpVWVwb+bX67lyMSYeYh55gX9xcLW43w4Hc6KU=; b=Lp0pm5NjhubIqm9Fl2aadG2RruOx4XcYhmbsDexdCESBP7Vm0ee1OYhll+AyF0Z8Lx Z+eoEWsdVa2VLi0lvK4xmWhRrWojQV0eYRbuvXBACMvXBSRU4oCSZ9DepwzIztpGt8ns 7qnRo+l5rOCgK9fuL7dstDfShsLCzcMW/4pkJUwUvhLPi+7aeRgonqoX3s3RSEPQMaJ7 p7TF8tIJsO6d3eVVyv0sbWUrySe3y3nzZJ/BQxCN0p4gxBYsDS1e0mSX95G2RibrPEU6 lnW9e/lP89L3lyNujwfGHRI06Ma01Vkkvi+oUOmvk9Qj6u5ept+jNUcX0pMYSlG+6R+Y 7j/g== X-Gm-Message-State: AOAM530QcCUEH6sUgDM1nPDABpGIPW/+Xeqz0s6D17n1rCcoh5KYMwDS 81IL6NQ0hLk8EjotCMvz11ZHbg== X-Google-Smtp-Source: ABdhPJwz4BoGkxtnPV1zwkaN63/vpdssplWLpbggcLBZmc//cbWai08ZujLSXfOb8EFvM7Uk5KnoTA== X-Received: by 2002:a65:4809:0:b0:3fc:878:49df with SMTP id h9-20020a654809000000b003fc087849dfmr34626pgs.557.1655132792835; Mon, 13 Jun 2022 08:06:32 -0700 (PDT) Received: from google.com (55.212.185.35.bc.googleusercontent.com. [35.185.212.55]) by smtp.gmail.com with ESMTPSA id oa11-20020a17090b1bcb00b001e280f58d02sm5396560pjb.24.2022.06.13.08.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 08:06:31 -0700 (PDT) Date: Mon, 13 Jun 2022 08:06:27 -0700 From: Zach O'Keefe To: Yang Shi Cc: Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , Andrew Morton , Linux MM , Linux Kernel Mailing List Subject: Re: [v3 PATCH 5/7] mm: thp: kill transparent_hugepage_active() Message-ID: References: <20220606214414.736109-1-shy828301@gmail.com> <20220606214414.736109-6-shy828301@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655132793; a=rsa-sha256; cv=none; b=b3C1etRKqxjXpSEP5NGvCxAtftHYearlrskD4bp/yaPrWFCENgkH72+IukcVnt15BrVpw6 RpRppGD8aWvRTpBLgaYkwiAXhb9otfaeond6jq8inpeA5ZYHvZKU3484PMngZtbj46KZYt gUidH3rE0CUoxDZrx7brw/YCH9DbPZU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=c6qZDpn7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of zokeefe@google.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zokeefe@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655132793; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8PQPUHpVWVwb+bX67lyMSYeYh55gX9xcLW43w4Hc6KU=; b=XGAfHg9xHUbPTEeLfy6QYoqqkzbFE70Bbpt5koaO3aPwid9HwBgrMIMz8354pH03xhpN6H veWuECVspbqu3HVAn8PGw3ZRMuIjeOuGenCZ79Gc8fHkIw1tb99lzzhIkmI/YYNxtHnuSs V0HEp92Ybqbb5LzWSxohpaM3dI2528A= X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=c6qZDpn7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of zokeefe@google.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zokeefe@google.com X-Stat-Signature: 1dyo9e9rju4f9a44fcqaygsos9icodp5 X-Rspamd-Queue-Id: 7EFDF180451 X-Rspamd-Server: rspam12 X-HE-Tag: 1655132794-644435 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 10 Jun 10:02, Yang Shi wrote: > On Thu, Jun 9, 2022 at 6:03 PM Zach O'Keefe wrote: > > > > On Mon, Jun 6, 2022 at 2:44 PM Yang Shi wrote: > > > > > > The transparent_hugepage_active() was introduced to show THP eligibility > > > bit in smaps in proc, smaps is the only user. But it actually does the > > > similar check as hugepage_vma_check() which is used by khugepaged. We > > > definitely don't have to maintain two similar checks, so kill > > > transparent_hugepage_active(). > > > > I never realized smaps was the only user! Great! > > > > > Also move hugepage_vma_check() to huge_memory.c and huge_mm.h since it > > > is not only for khugepaged anymore. > > > > > > Signed-off-by: Yang Shi > > > --- > > > fs/proc/task_mmu.c | 2 +- > > > include/linux/huge_mm.h | 16 +++++++----- > > > include/linux/khugepaged.h | 4 +-- > > > mm/huge_memory.c | 50 ++++++++++++++++++++++++++++++++----- > > > mm/khugepaged.c | 51 +++----------------------------------- > > > 5 files changed, 60 insertions(+), 63 deletions(-) > > > > > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > > > index 2dd8c8a66924..fd79566e204c 100644 > > > --- a/fs/proc/task_mmu.c > > > +++ b/fs/proc/task_mmu.c > > > @@ -860,7 +860,7 @@ static int show_smap(struct seq_file *m, void *v) > > > __show_smap(m, &mss, false); > > > > > > seq_printf(m, "THPeligible: %d\n", > > > - transparent_hugepage_active(vma)); > > > + hugepage_vma_check(vma, vma->vm_flags, true)); > > > > > > if (arch_pkeys_enabled()) > > > seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); > > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > > > index 79d5919beb83..f561c3e16def 100644 > > > --- a/include/linux/huge_mm.h > > > +++ b/include/linux/huge_mm.h > > > @@ -209,7 +209,9 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma) > > > !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode); > > > } > > > > > > -bool transparent_hugepage_active(struct vm_area_struct *vma); > > > +bool hugepage_vma_check(struct vm_area_struct *vma, > > > + unsigned long vm_flags, > > > + bool smaps); > > > > > > #define transparent_hugepage_use_zero_page() \ > > > (transparent_hugepage_flags & \ > > > @@ -358,11 +360,6 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) > > > return false; > > > } > > > > > > -static inline bool transparent_hugepage_active(struct vm_area_struct *vma) > > > -{ > > > - return false; > > > -} > > > - > > > static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) > > > { > > > return false; > > > @@ -380,6 +377,13 @@ static inline bool transhuge_vma_enabled(struct vm_area_struct *vma, > > > return false; > > > } > > > > > > +static inline bool hugepage_vma_check(struct vm_area_struct *vma, > > > + unsigned long vm_flags, > > > + bool smaps) > > > +{ > > > + return false; > > > +} > > > + > > > static inline void prep_transhuge_page(struct page *page) {} > > > > > > #define transparent_hugepage_flags 0UL > > > diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h > > > index 392d34c3c59a..8a6452e089ca 100644 > > > --- a/include/linux/khugepaged.h > > > +++ b/include/linux/khugepaged.h > > > @@ -10,8 +10,6 @@ extern struct attribute_group khugepaged_attr_group; > > > extern int khugepaged_init(void); > > > extern void khugepaged_destroy(void); > > > extern int start_stop_khugepaged(void); > > > -extern bool hugepage_vma_check(struct vm_area_struct *vma, > > > - unsigned long vm_flags); > > > extern void __khugepaged_enter(struct mm_struct *mm); > > > extern void __khugepaged_exit(struct mm_struct *mm); > > > extern void khugepaged_enter_vma(struct vm_area_struct *vma, > > > @@ -57,7 +55,7 @@ static inline void khugepaged_enter(struct vm_area_struct *vma, > > > { > > > if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && > > > khugepaged_enabled()) { > > > - if (hugepage_vma_check(vma, vm_flags)) > > > + if (hugepage_vma_check(vma, vm_flags, false)) > > > __khugepaged_enter(vma->vm_mm); > > > } > > > } > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > > index 36ada544e494..bc8370856e85 100644 > > > --- a/mm/huge_memory.c > > > +++ b/mm/huge_memory.c > > > @@ -69,18 +69,56 @@ static atomic_t huge_zero_refcount; > > > struct page *huge_zero_page __read_mostly; > > > unsigned long huge_zero_pfn __read_mostly = ~0UL; > > > > > > -bool transparent_hugepage_active(struct vm_area_struct *vma) > > > +bool hugepage_vma_check(struct vm_area_struct *vma, > > > + unsigned long vm_flags, > > > + bool smaps) > > > { > > > + if (!transhuge_vma_enabled(vma, vm_flags)) > > > + return false; > > > + > > > + if (vm_flags & VM_NO_KHUGEPAGED) > > > + return false; > > > + > > > + /* Don't run khugepaged against DAX vma */ > > > + if (vma_is_dax(vma)) > > > + return false; > > > + > > > + if (vma->vm_file && !IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - > > > + vma->vm_pgoff, HPAGE_PMD_NR)) > > > + return false; > > > + > > > if (!transhuge_vma_size_ok(vma)) > > > return false; I know we just introduced transhuge_vma_size_ok(), but is there a way to consolidate the above two checks into a single transhuge_vma_suitable(), the same way it used to be done in transparent_hugepage_active()? I.e. transhuge_vma_suitable(vma, vma->vm_end - HPAGE_PMD_SIZE). Which checks if the vma can hold an aligned hugepage, as well as centralizes the (what I think to be) complicated file mapping check. > > > - if (vma_is_anonymous(vma)) > > > - return __transparent_hugepage_enabled(vma); > > > - if (vma_is_shmem(vma)) > > > + > > > + /* Enabled via shmem mount options or sysfs settings. */ > > > + if (shmem_file(vma->vm_file)) > > > return shmem_huge_enabled(vma); > > > - if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma)) > > > + > > > + if (!khugepaged_enabled()) > > > + return false; > > > + > > > + /* THP settings require madvise. */ > > > + if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) > > > + return false; > > > + > > > + /* Only regular file is valid */ > > > + if (file_thp_enabled(vma)) > > > return true; > > > > > > - return false; > > > + if (!vma_is_anonymous(vma)) > > > + return false; > > > + > > > + if (vma_is_temporary_stack(vma)) > > > + return false; > > > + > > > + /* > > > + * THPeligible bit of smaps should show 1 for proper VMAs even > > > + * though anon_vma is not initialized yet. > > > + */ > > > + if (!vma->anon_vma) > > > + return smaps; > > > + > > > + return true; > > > } > > > > There are a few cases where the return value for smaps will be > > different from before. I presume this won't be an issue, and that any > > difference resulting from this change is actually a positive > > difference, given it more accurately reflects the thp eligibility of > > the vma? For example, a VM_NO_KHUGEPAGED-marked vma might now show 0 > > where it otherwise showed 1. > > Yes, returning 1 for VM_NO_KHUGEPAGED vmas is wrong. Actually TBH I > suspect very few people actually use this bit. Anyway I will elaborate > this in the commit log. > > > > > > static bool get_huge_zero_page(void) > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > > > index ca1754d3a827..aa0769e3b0d9 100644 > > > --- a/mm/khugepaged.c > > > +++ b/mm/khugepaged.c > > > @@ -437,49 +437,6 @@ static inline int khugepaged_test_exit(struct mm_struct *mm) > > > return atomic_read(&mm->mm_users) == 0; > > > } > > > > > > -bool hugepage_vma_check(struct vm_area_struct *vma, > > > - unsigned long vm_flags) > > > -{ > > > - if (!transhuge_vma_enabled(vma, vm_flags)) > > > - return false; > > > - > > > - if (vm_flags & VM_NO_KHUGEPAGED) > > > - return false; > > > - > > > - /* Don't run khugepaged against DAX vma */ > > > - if (vma_is_dax(vma)) > > > - return false; > > > - > > > - if (vma->vm_file && !IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - > > > - vma->vm_pgoff, HPAGE_PMD_NR)) > > > - return false; > > > - > > > - if (!transhuge_vma_size_ok(vma)) > > > - return false; > > > - > > > - /* Enabled via shmem mount options or sysfs settings. */ > > > - if (shmem_file(vma->vm_file)) > > > - return shmem_huge_enabled(vma); > > > - > > > - if (!khugepaged_enabled()) > > > - return false; > > > - > > > - /* THP settings require madvise. */ > > > - if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) > > > - return false; > > > - > > > - /* Only regular file is valid */ > > > - if (file_thp_enabled(vma)) > > > - return true; > > > - > > > - if (!vma->anon_vma || !vma_is_anonymous(vma)) > > > - return false; > > > - if (vma_is_temporary_stack(vma)) > > > - return false; > > > - > > > - return true; > > > -} > > > - > > > void __khugepaged_enter(struct mm_struct *mm) > > > { > > > struct mm_slot *mm_slot; > > > @@ -516,7 +473,7 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, > > > { > > > if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && > > > khugepaged_enabled()) { > > > - if (hugepage_vma_check(vma, vm_flags)) > > > + if (hugepage_vma_check(vma, vm_flags, false)) > > > __khugepaged_enter(vma->vm_mm); > > > } > > > } > > > @@ -961,7 +918,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > > > > > > if (!transhuge_vma_suitable(vma, address)) > > > return SCAN_ADDRESS_RANGE; > > > - if (!hugepage_vma_check(vma, vma->vm_flags)) > > > + if (!hugepage_vma_check(vma, vma->vm_flags, false)) > > > return SCAN_VMA_CHECK; > > > return 0; > > > } > > > @@ -1442,7 +1399,7 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) > > > * the valid THP. Add extra VM_HUGEPAGE so hugepage_vma_check() > > > * will not fail the vma for missing VM_HUGEPAGE > > > */ > > > - if (!hugepage_vma_check(vma, vma->vm_flags | VM_HUGEPAGE)) > > > + if (!hugepage_vma_check(vma, vma->vm_flags | VM_HUGEPAGE, false)) > > > return; > > > > > > /* Keep pmd pgtable for uffd-wp; see comment in retract_page_tables() */ > > > @@ -2132,7 +2089,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > > > progress++; > > > break; > > > } > > > - if (!hugepage_vma_check(vma, vma->vm_flags)) { > > > + if (!hugepage_vma_check(vma, vma->vm_flags, false)) { > > > skip: > > > progress++; > > > continue; > > > -- > > > 2.26.3 > > > > > >