Re: [PATCH v3 3/5] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry()
From: Lorenzo Stoakes (ARM)
Date: Mon Nov 23 2026 - 12:24:50 EST
On Mon, Nov 23, 2026 at 08:32:09AM -0800, Usama Arif wrote:
> smaps_pmd_entry() dereferences the pmd pointer six times. Read it once
> into a local with pmdp_get(), the way smaps_pte_entry() already does
> with ptep_get(), so that every test sees the same value.
>
> No functional change intended.
>
> Suggested-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
LGTM so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> ---
> fs/proc/task_mmu.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 540c936aad4714..105c4998eef48f 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1022,14 +1022,15 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
> struct page *page = NULL;
> bool present = false;
> struct folio *folio;
> + pmd_t pmdval = pmdp_get(pmd);
NIT: Can this be const or are the helpers not safe for it?
>
> - if (pmd_none(*pmd))
> + if (pmd_none(pmdval))
> return;
> - if (pmd_present(*pmd)) {
> - page = vm_normal_page_pmd(vma, addr, *pmd);
> + if (pmd_present(pmdval)) {
> + page = vm_normal_page_pmd(vma, addr, pmdval);
> present = true;
> } else if (unlikely(thp_migration_supported())) {
> - const softleaf_t entry = softleaf_from_pmd(*pmd);
> + const softleaf_t entry = softleaf_from_pmd(pmdval);
>
> if (softleaf_has_pfn(entry))
> page = softleaf_to_page(entry);
> @@ -1046,7 +1047,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
> else
> mss->file_thp += HPAGE_PMD_SIZE;
>
> - smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd),
> + smaps_account(mss, page, true, pmd_young(pmdval), pmd_dirty(pmdval),
> locked, present);
> }
> #else
> --
> 2.53.1-Meta
>
--
Cheers, Lorenzo