lkml.org 
[lkml]   [2023]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/2] mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps
From
On 26.01.23 23:27, Mike Kravetz wrote:
> A hugetlb page will have a mapcount of 1 if mapped by multiple processes
> via a shared PMD. This is because only the first process increases the
> map count, and subsequent processes just add the shared PMD page to
> their page table.
>
> page_mapcount is being used to decide if a hugetlb page is shared or
> private in /proc/PID/smaps. Pages referenced via a shared PMD were
> incorrectly being counted as private.
>
> To fix, check for a shared PMD if mapcount is 1. If a shared PMD is
> found count the hugetlb page as shared. A new helper to check for a
> shared PMD is added.
>
> Fixes: 25ee01a2fca0 ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
> fs/proc/task_mmu.c | 10 ++++++++--
> include/linux/hugetlb.h | 12 ++++++++++++
> 2 files changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index e35a0398db63..cb9539879402 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -749,8 +749,14 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
>
> if (mapcount >= 2)
> mss->shared_hugetlb += huge_page_size(hstate_vma(vma));
> - else
> - mss->private_hugetlb += huge_page_size(hstate_vma(vma));
> + else {

Better:

if (mapcount >= 2 || hugetlb_pmd_shared(pte))
mss->shared_hugetlb += huge_page_size(hstate_vma(vma));
else
mss->private_hugetlb += huge_page_size(hstate_vma(vma));



--
Thanks,

David / dhildenb

\
 
 \ /
  Last update: 2023-03-26 23:58    [W:0.073 / U:3.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site