[PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios

David Hildenbrand posted 2 patches 1 year, 9 months ago
[PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios
Posted by David Hildenbrand 1 year, 9 months ago
Let's get rid of another page_mapcount() check and simply use
folio_likely_mapped_shared(), which is precise for hugetlb folios.

While at it, also check for PMD table sharing, like we do in
smaps_hugetlb_range().

No functional change intended, except that we would now detect hugetlb
folios shared via PMD table sharing correctly.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 fs/proc/task_mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 8ff79bd427ec6..cd6e45e0cde8e 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1578,12 +1578,13 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,
 
 	pte = huge_ptep_get(ptep);
 	if (pte_present(pte)) {
-		struct page *page = pte_page(pte);
+		struct folio *folio = page_folio(pte_page(pte));
 
-		if (!PageAnon(page))
+		if (!folio_test_anon(folio))
 			flags |= PM_FILE;
 
-		if (page_mapcount(page) == 1)
+		if (!folio_likely_mapped_shared(folio) &&
+		    !hugetlb_pmd_shared(ptep))
 			flags |= PM_MMAP_EXCLUSIVE;
 
 		if (huge_pte_uffd_wp(pte))
-- 
2.44.0
Re: [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios
Posted by Oscar Salvador 1 year, 9 months ago
On Wed, Apr 17, 2024 at 11:23:12AM +0200, David Hildenbrand wrote:
> Let's get rid of another page_mapcount() check and simply use
> folio_likely_mapped_shared(), which is precise for hugetlb folios.
> 
> While at it, also check for PMD table sharing, like we do in
> smaps_hugetlb_range().
> 
> No functional change intended, except that we would now detect hugetlb
> folios shared via PMD table sharing correctly.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Oscar Salvador <osalvador@suse.de>

 

-- 
Oscar Salvador
SUSE Labs