Skip to contentSkip to conversation

mm/smaps: Use vma->vm_pgoff directly when counting partial swap

PATCH In review Peter Xu 2 participants 3 messages Sep 16, 2021 – Sep 17, 2021

Subsystems (2)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 mm/smaps: Use vma->vm_pgoff directly when counting partial swap

linear_page_index(vma, vma->vm_start) of a shmem vma is exactly vm_pgoff.

Cc Vlastimil Babka <[email protected]>
Cc Hugh Dickins <[email protected]>
---
 mm/shmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/shmem.c +1 -2
index 96ccf6e941aa..2aef5b8e17c9 100644
@@ -856,8 +856,7 @@ unsigned long shmem_swap_usage(struct vm_area_struct *vma)
 		return swapped << PAGE_SHIFT;
 
 	/* Here comes the more involved part */
-	return shmem_partial_swap_usage(mapping,
-			linear_page_index(vma, vma->vm_start),
+	return shmem_partial_swap_usage(mapping, vma->vm_pgoff,
 			linear_page_index(vma, vma->vm_end));
 }
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 1 line · Peter Xu

linear_page_index(vma, vma->vm_start) of a shmem vma is exactly vm_pgoff.

Could you use "vma->vm_pgoff + vma_pages(vma)" instead of the other linear_page_index() then?

But now I wonder, is smaps_pte_hole() broken? it calls shmem_partial_swap_usage with addresses, not pgoffs?

Quoted 22 lines
Cc Vlastimil Babka <[email protected]>
Cc Hugh Dickins <[email protected]>
---
 mm/shmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/shmem.c +1 -2
index 96ccf6e941aa..2aef5b8e17c9 100644
@@ -856,8 +856,7 @@ unsigned long shmem_swap_usage(struct vm_area_struct *vma)
 		return swapped << PAGE_SHIFT;
 
 	/* Here comes the more involved part */
-	return shmem_partial_swap_usage(mapping,
-			linear_page_index(vma, vma->vm_start),
+	return shmem_partial_swap_usage(mapping, vma->vm_pgoff,
 			linear_page_index(vma, vma->vm_end));
 }
 
author
#2 lore raw
Quoted 5 lines · Vlastimil Babka
Quoted 1 line · Peter Xu

linear_page_index(vma, vma->vm_start) of a shmem vma is exactly vm_pgoff.

Could you use "vma->vm_pgoff + vma_pages(vma)" instead of the other linear_page_index() then?

Sure.

Quoted 3 lines

But now I wonder, is smaps_pte_hole() broken? it calls shmem_partial_swap_usage with addresses, not pgoffs?

Hmm, that seems true.. I guess it still gets the right number when start==0 and when the vma covers the whole file (which could be the simplest scenario), but not otherwise.

I'll add a new patch.

Thanks,

Signature · 1 line
Peter Xu