Re: [RFC] mm/thp: Update mm's MM_ANONPAGES stat in set_huge_zero_page()

From: Zi Yan
Date: Thu May 13 2021 - 10:12:17 EST


On 13 May 2021, at 3:20, Anshuman Khandual wrote:

> Although the zero huge page is being shared across various processes, each
> mapping needs to update its mm's MM_ANONPAGES stat by HPAGE_PMD_NR in order
> to be consistent. This just updates the stats in set_huge_zero_page() after
> the mapping gets created.

In addition, MM_ANONPAGES stats should be decreased at zap_huge_pmd() and
__split_huge_pmd_locked() when the zero huge page mapping is removed from
a process, right?

>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Zi Yan <ziy@xxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
> ---
> Should it update MM_SHMEM_PAGES instead ? Applies on latest mainline.

zero huge page is added via do_huge_pmd_anonymous_page(), I think MM_ANONPAGES
is appropriate.

>
> mm/huge_memory.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 63ed6b25deaa..262703304807 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -706,6 +706,7 @@ static void set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
> if (pgtable)
> pgtable_trans_huge_deposit(mm, pmd, pgtable);
> set_pmd_at(mm, haddr, pmd, entry);
> + add_mm_counter(mm, MM_ANONPAGES, HPAGE_PMD_NR);
> mm_inc_nr_ptes(mm);
> }
>
> --
> 2.20.1



Best Regards,
Yan Zi

Attachment: signature.asc
Description: OpenPGP digital signature