From: Zach O'Keefe <zokeefe@google.com>
To: Yang Shi <shy828301@gmail.com>
Cc: vbabka@suse.cz, kirill.shutemov@linux.intel.com,
willy@infradead.org, linmiaohe@huawei.com,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [v4 PATCH 4/7] mm: thp: kill transparent_hugepage_active()
Date: Wed, 15 Jun 2022 17:17:19 -0700 [thread overview]
Message-ID: <Yqp2j6sf7m3wmwou@google.com> (raw)
In-Reply-To: <20220615172926.546974-5-shy828301@gmail.com>
On 15 Jun 10:29, 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().
>
> This patch also fixed the wrong behavior for VM_NO_KHUGEPAGED vmas.
>
> 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 <shy828301@gmail.com>
> ---
> fs/proc/task_mmu.c | 2 +-
> include/linux/huge_mm.h | 11 ++++++++-
> include/linux/khugepaged.h | 2 --
> mm/huge_memory.c | 50 +++++++++++++++++++++++++++++++-------
> mm/khugepaged.c | 48 +++---------------------------------
> 5 files changed, 56 insertions(+), 57 deletions(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 37ccb5c9f4f8..39a40ec181e7 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -863,7 +863,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 8a5a8bfce0f5..aeb13119ee28 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -202,7 +202,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);
Like v3, I think this also needs to be deleted from !CONFIG_TRANSPARENT_HUGEPAGE
Otherwise can add
Reviewed-by: Zach O'Keefe <zokeefe@google.com>
> +bool hugepage_vma_check(struct vm_area_struct *vma,
> + unsigned long vm_flags,
> + bool smaps);
>
> #define transparent_hugepage_use_zero_page() \
> (transparent_hugepage_flags & \
> @@ -368,6 +370,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 31ca8a7f78f4..ea5fd4c398f7 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,
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index b530462c4493..a28c6100b491 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -69,21 +69,53 @@ 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)
> {
> - /* The addr is used to check if the vma size fits */
> - unsigned long addr = (vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE;
> + 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 (!transhuge_vma_suitable(vma, addr))
> + /* Check alignment for file vma and size for both file and anon vma */
> + if (!transhuge_vma_suitable(vma, (vma->vm_end - HPAGE_PMD_SIZE)))
> return false;
> - 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;
> }
>
> static bool get_huge_zero_page(void)
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 5baa394e34c8..3afd87f8c0b1 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -437,46 +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;
> -
> - /* Check alignment for file vma and size for both file and anon vma */
> - if (!transhuge_vma_suitable(vma, (vma->vm_end - HPAGE_PMD_SIZE)))
> - 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;
> @@ -513,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);
> }
> }
> @@ -958,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;
> /*
> * Anon VMA expected, the address may be unmapped then
> @@ -1448,7 +1408,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() */
> @@ -2143,7 +2103,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
>
next prev parent reply other threads:[~2022-06-16 0:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-15 17:29 [mm-unstable v4 PATCH 0/7] Cleanup transhuge_xxx helpers Yang Shi
2022-06-15 17:29 ` [v4 PATCH 1/7] mm: khugepaged: check THP flag in hugepage_vma_check() Yang Shi
2022-06-15 17:29 ` [v4 PATCH 2/7] mm: thp: consolidate vma size check to transhuge_vma_suitable Yang Shi
2022-06-15 23:55 ` Zach O'Keefe
2022-06-15 17:29 ` [v4 PATCH 3/7] mm: khugepaged: better comments for anon vma check in hugepage_vma_revalidate Yang Shi
2022-06-15 23:57 ` Zach O'Keefe
2022-06-15 17:29 ` [v4 PATCH 4/7] mm: thp: kill transparent_hugepage_active() Yang Shi
2022-06-16 0:17 ` Zach O'Keefe [this message]
2022-06-16 0:32 ` Yang Shi
2022-06-15 17:29 ` [v4 PATCH 5/7] mm: thp: kill __transhuge_page_enabled() Yang Shi
2022-06-16 0:56 ` Zach O'Keefe
2022-06-15 17:29 ` [v4 PATCH 6/7] mm: khugepaged: reorg some khugepaged helpers Yang Shi
2022-06-16 0:27 ` Zach O'Keefe
2022-06-15 17:29 ` [v4 PATCH 7/7] doc: proc: fix the description to THPeligible Yang Shi
2022-06-16 0:20 ` Zach O'Keefe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yqp2j6sf7m3wmwou@google.com \
--to=zokeefe@google.com \
--cc=akpm@linux-foundation.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.