Re: [PATCH v2 3/4] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps

From: Kiryl Shutsemau (Meta)

Date: Tue Nov 17 2026 - 06:08:30 EST


On Sun, Nov 15, 2026 at 10:34:57PM -0800, Usama Arif wrote:
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 164b4efc5e093..ad9fdcdaa2c40 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1029,13 +1029,15 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
> struct vm_area_struct *vma = walk->vma;
> bool locked = !!(vma->vm_flags & VM_LOCKED);
> struct page *page = NULL;
> - bool present = false;
> + bool present = false, young = false, dirty = false;
> struct folio *folio;
>
> if (pmd_none(*pmd))
> return;
> if (pmd_present(*pmd)) {
> page = vm_normal_page_pmd(vma, addr, *pmd);
> + young = pmd_young(*pmd);
> + dirty = pmd_dirty(*pmd);
> present = true;
> } else if (unlikely(thp_migration_supported())) {
> const softleaf_t entry = softleaf_from_pmd(*pmd);

smaps_pmd_entry() dereferences pmd six times :/

Could you read it once with pmdp_get() in a separate patch before this
one, the way smaps_pte_entry() does with ptep_get()?

This patch would then only move pmd_young() and pmd_dirty() under the
present branch.

--
Kiryl Shutsemau / Kirill A. Shutemov