linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@intel.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: linux-mm@kvack.org,  Kairui Song <kasong@tencent.com>,
	linux-kernel@vger.kernel.org,
	 Andrew Morton <akpm@linux-foundation.org>,
	Miaohe Lin <linmiaohe@huawei.com>,
	 David Hildenbrand <david@redhat.com>,
	Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH 3/5] swap: fold swap_ra_clamp_pfn into swap_ra_info
Date: Fri, 09 Dec 2022 11:23:39 +0800	[thread overview]
Message-ID: <87r0x9qmys.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <20221208180209.50845-4-ryncsn@gmail.com> (Kairui Song's message of "Fri, 9 Dec 2022 02:02:07 +0800")

Kairui Song <ryncsn@gmail.com> writes:

> From: Kairui Song <kasong@tencent.com>
>
> This make the code cleaner. This helper is made of only two line of
> self explanational code and not reused anywhere else.
>
> And this actually make the compiled object smaller by a bit:
>
>           text    data     bss     dec     hex filename
> Before:   9502     976      12   10490    28fa mm/swap_state.o
> After:    9470     976      12   10458    28da mm/swap_state.o
>
> Signed-off-by: Kairui Song <kasong@tencent.com>
> ---
>  mm/swap_state.c | 44 +++++++++++++++++++-------------------------
>  1 file changed, 19 insertions(+), 25 deletions(-)

LGTM, Thanks!

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

> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index 60136bda78e3..19089417abd1 100644
> --- a/mm/swap_state.c
> +++ b/mm/swap_state.c
> @@ -696,28 +696,15 @@ void exit_swap_address_space(unsigned int type)
>  	swapper_spaces[type] = NULL;
>  }
>  
> -static inline void swap_ra_clamp_pfn(struct vm_area_struct *vma,
> -				     unsigned long faddr,
> -				     unsigned long lpfn,
> -				     unsigned long rpfn,
> -				     unsigned long *start,
> -				     unsigned long *end)
> -{
> -	*start = max3(lpfn, PFN_DOWN(vma->vm_start),
> -		      PFN_DOWN(faddr & PMD_MASK));
> -	*end = min3(rpfn, PFN_DOWN(vma->vm_end),
> -		    PFN_DOWN((faddr & PMD_MASK) + PMD_SIZE));
> -}
> -
>  static void swap_ra_info(struct vm_fault *vmf,
> -			struct vma_swap_readahead *ra_info)
> +			 struct vma_swap_readahead *ra_info)
>  {
>  	struct vm_area_struct *vma = vmf->vma;
>  	unsigned long ra_val;
> -	unsigned long faddr, pfn, fpfn;
> +	unsigned long faddr, pfn, fpfn, lpfn, rpfn;
>  	unsigned long start, end;
>  	pte_t *pte, *orig_pte;
> -	unsigned int max_win, hits, prev_win, win, left;
> +	unsigned int max_win, hits, prev_win, win;
>  #ifndef CONFIG_64BIT
>  	pte_t *tpte;
>  #endif
> @@ -745,16 +732,23 @@ static void swap_ra_info(struct vm_fault *vmf,
>  
>  	/* 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)
> -		swap_ra_clamp_pfn(vma, faddr, fpfn - win + 1, fpfn + 1,
> -				  &start, &end);
> -	else {
> -		left = (win - 1) / 2;
> -		swap_ra_clamp_pfn(vma, faddr, fpfn - left, fpfn + win - left,
> -				  &start, &end);
> +	if (fpfn == pfn + 1) {
> +		lpfn = fpfn;
> +		rpfn = fpfn + win;
> +	} else if (pfn == fpfn + 1) {
> +		lpfn = fpfn - win + 1;
> +		rpfn = fpfn + 1;
> +	} else {
> +		unsigned int left = (win - 1) / 2;
> +
> +		lpfn = fpfn - left;
> +		rpfn = fpfn + win - left;
>  	}
> +	start = max3(lpfn, PFN_DOWN(vma->vm_start),
> +		     PFN_DOWN(faddr & PMD_MASK));
> +	end = min3(rpfn, PFN_DOWN(vma->vm_end),
> +		   PFN_DOWN((faddr & PMD_MASK) + PMD_SIZE));
> +
>  	ra_info->nr_pte = end - start;
>  	ra_info->offset = fpfn - start;
>  	pte -= ra_info->offset;


  parent reply	other threads:[~2022-12-09  3:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 18:02 [PATCH 0/5] Clean up and fixes for swap Kairui Song
2022-12-08 18:02 ` [PATCH 1/5] swapfile: get rid of volatile and avoid redundant read Kairui Song
2022-12-09  2:48   ` Huang, Ying
2022-12-08 18:02 ` [PATCH 2/5] swap: avoid a redundant pte map if ra window is 1 Kairui Song
2022-12-09  3:15   ` Huang, Ying
2022-12-08 18:02 ` [PATCH 3/5] swap: fold swap_ra_clamp_pfn into swap_ra_info Kairui Song
2022-12-08 19:08   ` Matthew Wilcox
2022-12-09  2:00     ` Kairui Song
2022-12-09  3:23   ` Huang, Ying [this message]
2022-12-08 18:02 ` [PATCH 4/5] swap: remove the swap lock in swap_cache_get_folio Kairui Song
2022-12-11 11:39   ` Huang, Ying
2022-12-11 11:47     ` Kairui Song
2022-12-08 18:02 ` [PATCH 5/5] swap: avoid ra statistic lost when swapin races Kairui Song
2022-12-08 19:14   ` Matthew Wilcox
2022-12-09  1:54     ` Kairui Song
2022-12-11 12:02       ` Huang, Ying
2022-12-11 12:15         ` Kairui Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r0x9qmys.fsf@yhuang6-desk2.ccr.corp.intel.com \
    --to=ying.huang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=kasong@tencent.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryncsn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox