All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] fs/proc/task_mmu: convert hugetlb functions to work on folis
@ 2024-04-17  9:23 David Hildenbrand
  2024-04-17  9:23 ` [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios David Hildenbrand
  2024-04-17  9:23 ` [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() " David Hildenbrand
  0 siblings, 2 replies; 7+ messages in thread
From: David Hildenbrand @ 2024-04-17  9:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, linux-fsdevel, David Hildenbrand, Andrew Morton, Muchun Song

Let's convert two more functions, getting rid of two more page_mapcount()
calls.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Muchun Song <muchun.song@linux.dev>

David Hildenbrand (2):
  fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios
  fs/proc/task_mmu: convert smaps_hugetlb_range() to work on folios

 fs/proc/task_mmu.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

-- 
2.44.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios
  2024-04-17  9:23 [PATCH v1 0/2] fs/proc/task_mmu: convert hugetlb functions to work on folis David Hildenbrand
@ 2024-04-17  9:23 ` David Hildenbrand
  2024-04-17 10:21   ` Oscar Salvador
  2024-04-17  9:23 ` [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() " David Hildenbrand
  1 sibling, 1 reply; 7+ messages in thread
From: David Hildenbrand @ 2024-04-17  9:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, linux-fsdevel, David Hildenbrand, Andrew Morton, Muchun Song

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() to work on folios
  2024-04-17  9:23 [PATCH v1 0/2] fs/proc/task_mmu: convert hugetlb functions to work on folis David Hildenbrand
  2024-04-17  9:23 ` [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios David Hildenbrand
@ 2024-04-17  9:23 ` David Hildenbrand
  2024-04-17 12:09   ` Oscar Salvador
  1 sibling, 1 reply; 7+ messages in thread
From: David Hildenbrand @ 2024-04-17  9:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, linux-fsdevel, David Hildenbrand, Andrew Morton, Muchun Song

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, use huge_ptep_get() + pte_page() instead of ptep_get() +
vm_normal_page(), just like we do in pagemap_hugetlb_range().

No functional change intended.

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

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index cd6e45e0cde8e..f4259b7edfded 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -730,19 +730,20 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
 {
 	struct mem_size_stats *mss = walk->private;
 	struct vm_area_struct *vma = walk->vma;
-	struct page *page = NULL;
-	pte_t ptent = ptep_get(pte);
+	pte_t ptent = huge_ptep_get(pte);
+	struct folio *folio = NULL;
 
 	if (pte_present(ptent)) {
-		page = vm_normal_page(vma, addr, ptent);
+		folio = page_folio(pte_page(ptent));
 	} else if (is_swap_pte(ptent)) {
 		swp_entry_t swpent = pte_to_swp_entry(ptent);
 
 		if (is_pfn_swap_entry(swpent))
-			page = pfn_swap_entry_to_page(swpent);
+			folio = pfn_swap_entry_folio(swpent);
 	}
-	if (page) {
-		if (page_mapcount(page) >= 2 || hugetlb_pmd_shared(pte))
+	if (folio) {
+		if (folio_likely_mapped_shared(folio) ||
+		    hugetlb_pmd_shared(pte))
 			mss->shared_hugetlb += huge_page_size(hstate_vma(vma));
 		else
 			mss->private_hugetlb += huge_page_size(hstate_vma(vma));
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios
  2024-04-17  9:23 ` [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios David Hildenbrand
@ 2024-04-17 10:21   ` Oscar Salvador
  0 siblings, 0 replies; 7+ messages in thread
From: Oscar Salvador @ 2024-04-17 10:21 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, linux-fsdevel, Andrew Morton, Muchun Song

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() to work on folios
  2024-04-17  9:23 ` [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() " David Hildenbrand
@ 2024-04-17 12:09   ` Oscar Salvador
  2024-04-17 12:18     ` David Hildenbrand
  0 siblings, 1 reply; 7+ messages in thread
From: Oscar Salvador @ 2024-04-17 12:09 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, linux-fsdevel, Andrew Morton, Muchun Song

On Wed, Apr 17, 2024 at 11:23:13AM +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, use huge_ptep_get() + pte_page() instead of ptep_get() +
> vm_normal_page(), just like we do in pagemap_hugetlb_range().

That is fine because vm_normal_page() tries to be clever about  mappings which
hugetlb does not support, right?

> 
> No functional change intended.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

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


-- 
Oscar Salvador
SUSE Labs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() to work on folios
  2024-04-17 12:09   ` Oscar Salvador
@ 2024-04-17 12:18     ` David Hildenbrand
  2024-04-17 12:31       ` Oscar Salvador
  0 siblings, 1 reply; 7+ messages in thread
From: David Hildenbrand @ 2024-04-17 12:18 UTC (permalink / raw)
  To: Oscar Salvador
  Cc: linux-kernel, linux-mm, linux-fsdevel, Andrew Morton, Muchun Song

On 17.04.24 14:09, Oscar Salvador wrote:
> On Wed, Apr 17, 2024 at 11:23:13AM +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, use huge_ptep_get() + pte_page() instead of ptep_get() +
>> vm_normal_page(), just like we do in pagemap_hugetlb_range().
> 
> That is fine because vm_normal_page() tries to be clever about  mappings which
> hugetlb does not support, right?

Right, using vm_normal_page() is even completely bogus. Usually (but not 
always) we have PMDs/PUDs and not PTEs for mapping hugetlb pages -- 
where vm_normal_folio_pmd() would be the right thing to do.

That's also the reason why hugetlb.c has not a single user of 
vm_normal_page() and friends ... it doesn't apply to hugetlb, but likely 
also isn't currently harmful to use it.

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() to work on folios
  2024-04-17 12:18     ` David Hildenbrand
@ 2024-04-17 12:31       ` Oscar Salvador
  0 siblings, 0 replies; 7+ messages in thread
From: Oscar Salvador @ 2024-04-17 12:31 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, linux-fsdevel, Andrew Morton, Muchun Song

On Wed, Apr 17, 2024 at 02:18:10PM +0200, David Hildenbrand wrote:
> On 17.04.24 14:09, Oscar Salvador wrote:
> > On Wed, Apr 17, 2024 at 11:23:13AM +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, use huge_ptep_get() + pte_page() instead of ptep_get() +
> > > vm_normal_page(), just like we do in pagemap_hugetlb_range().
> > 
> > That is fine because vm_normal_page() tries to be clever about  mappings which
> > hugetlb does not support, right?
> 
> Right, using vm_normal_page() is even completely bogus. Usually (but not
> always) we have PMDs/PUDs and not PTEs for mapping hugetlb pages -- where
> vm_normal_folio_pmd() would be the right thing to do.
> 
> That's also the reason why hugetlb.c has not a single user of
> vm_normal_page() and friends ... it doesn't apply to hugetlb, but likely
> also isn't currently harmful to use it.

I guess not because we skip the special handling, but I agree that
replacing it is the right thing to do.
Thanks for explaining!
 

-- 
Oscar Salvador
SUSE Labs

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-17 12:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17  9:23 [PATCH v1 0/2] fs/proc/task_mmu: convert hugetlb functions to work on folis David Hildenbrand
2024-04-17  9:23 ` [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios David Hildenbrand
2024-04-17 10:21   ` Oscar Salvador
2024-04-17  9:23 ` [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() " David Hildenbrand
2024-04-17 12:09   ` Oscar Salvador
2024-04-17 12:18     ` David Hildenbrand
2024-04-17 12:31       ` Oscar Salvador

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.