diff mbox series

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

Message ID 20210916215839.95177-1-peterx@redhat.com (mailing list archive)
State New
Headers show
Series mm/smaps: Use vma->vm_pgoff directly when counting partial swap | expand

Commit Message

Peter Xu Sept. 16, 2021, 9:58 p.m. UTC
linear_page_index(vma, vma->vm_start) of a shmem vma is exactly vm_pgoff.

Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 mm/shmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vlastimil Babka Sept. 16, 2021, 10:17 p.m. UTC | #1
On 9/16/21 11:58 PM, Peter Xu wrote:
> 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?

> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Hugh Dickins <hughd@google.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  mm/shmem.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 96ccf6e941aa..2aef5b8e17c9 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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));
>  }
>  
>
Peter Xu Sept. 17, 2021, 12:29 a.m. UTC | #2
On Fri, Sep 17, 2021 at 12:17:32AM +0200, Vlastimil Babka wrote:
> On 9/16/21 11:58 PM, Peter Xu wrote:
> > 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.

> 
> 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,
diff mbox series

Patch

diff --git a/mm/shmem.c b/mm/shmem.c
index 96ccf6e941aa..2aef5b8e17c9 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -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));
 }