[2/5] swap: avoid a redundant pte map if ra window is 1

Message ID 20221208180209.50845-3-ryncsn@gmail.com
State New
Headers
Series Clean up and fixes for swap |

Commit Message

Kairui Song Dec. 8, 2022, 6:02 p.m. UTC
  From: Kairui Song <kasong@tencent.com>

Avoid a redundant pte map/unmap when swap readahead window is 1.

Signed-off-by: Kairui Song <kasong@tencent.com>
---
 mm/swap_state.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
  

Comments

Huang, Ying Dec. 9, 2022, 3:15 a.m. UTC | #1
Kairui Song <ryncsn@gmail.com> writes:

> From: Kairui Song <kasong@tencent.com>
>
> Avoid a redundant pte map/unmap when swap readahead window is 1.
>
> Signed-off-by: Kairui Song <kasong@tencent.com>
> ---
>  mm/swap_state.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Good to reduce the line of code.  Thanks!

Reviewed-by: "Huang, Ying" <ying.huang@intel.com>

> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index 438d0676c5be..60136bda78e3 100644
> --- a/mm/swap_state.c
> +++ b/mm/swap_state.c
> @@ -730,8 +730,6 @@ static void swap_ra_info(struct vm_fault *vmf,
>  	}
>  
>  	faddr = vmf->address;
> -	orig_pte = pte = pte_offset_map(vmf->pmd, faddr);
> -
>  	fpfn = PFN_DOWN(faddr);
>  	ra_val = GET_SWAP_RA_VAL(vma);
>  	pfn = PFN_DOWN(SWAP_RA_ADDR(ra_val));
> @@ -742,12 +740,11 @@ static void swap_ra_info(struct vm_fault *vmf,
>  	atomic_long_set(&vma->swap_readahead_info,
>  			SWAP_RA_VAL(faddr, win, 0));
>  
> -	if (win == 1) {
> -		pte_unmap(orig_pte);
> +	if (win == 1)
>  		return;
> -	}
>  
>  	/* Copy the PTEs because the page table may be unmapped */
> +	orig_pte = pte = pte_offset_map(vmf->pmd, faddr);
>  	if (fpfn == pfn + 1)
>  		swap_ra_clamp_pfn(vma, faddr, fpfn, fpfn + win, &start, &end);
>  	else if (pfn == fpfn + 1)
  

Patch

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 438d0676c5be..60136bda78e3 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -730,8 +730,6 @@  static void swap_ra_info(struct vm_fault *vmf,
 	}
 
 	faddr = vmf->address;
-	orig_pte = pte = pte_offset_map(vmf->pmd, faddr);
-
 	fpfn = PFN_DOWN(faddr);
 	ra_val = GET_SWAP_RA_VAL(vma);
 	pfn = PFN_DOWN(SWAP_RA_ADDR(ra_val));
@@ -742,12 +740,11 @@  static void swap_ra_info(struct vm_fault *vmf,
 	atomic_long_set(&vma->swap_readahead_info,
 			SWAP_RA_VAL(faddr, win, 0));
 
-	if (win == 1) {
-		pte_unmap(orig_pte);
+	if (win == 1)
 		return;
-	}
 
 	/* Copy the PTEs because the page table may be unmapped */
+	orig_pte = pte = pte_offset_map(vmf->pmd, faddr);
 	if (fpfn == pfn + 1)
 		swap_ra_clamp_pfn(vma, faddr, fpfn, fpfn + win, &start, &end);
 	else if (pfn == fpfn + 1)