[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250519070801.2588-1-21cnbao@gmail.com>
Date: Mon, 19 May 2025 19:08:01 +1200
From: Barry Song <21cnbao@...il.com>
To: ryncsn@...il.com
Cc: akpm@...ux-foundation.org,
baohua@...nel.org,
baolin.wang@...ux.alibaba.com,
bhe@...hat.com,
chrisl@...nel.org,
david@...hat.com,
hannes@...xchg.org,
hughd@...gle.com,
kaleshsingh@...gle.com,
kasong@...cent.com,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
nphamcs@...il.com,
ryan.roberts@....com,
shikemeng@...weicloud.com,
tim.c.chen@...ux.intel.com,
willy@...radead.org,
ying.huang@...ux.alibaba.com,
yosryahmed@...gle.com
Subject: Re: [PATCH 11/28] mm, swap: clean up and consolidate helper for mTHP swapin check
> From: Kairui Song <kasong@...cent.com>
> -static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)
> +static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep,
> + unsigned long addr, unsigned int nr_pages)
> + if (unlikely(addr < max(addr & PMD_MASK, vmf->vma->vm_start) ||
> + addr_end > pmd_addr_end(addr, vmf->vma->vm_end)))
> @@ -4731,27 +4732,18 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> page_idx = 0;
> address = vmf->address;
> ptep = vmf->pte;
> +
> if (folio_test_large(folio) && folio_test_swapcache(folio)) {
> - int nr = folio_nr_pages(folio);
> + unsigned long nr = folio_nr_pages(folio);
> unsigned long idx = folio_page_idx(folio, page);
> - unsigned long folio_start = address - idx * PAGE_SIZE;
> - unsigned long folio_end = folio_start + nr * PAGE_SIZE;
> - pte_t *folio_ptep;
> - pte_t folio_pte;
> + unsigned long folio_address = address - idx * PAGE_SIZE;
> + pte_t *folio_ptep = vmf->pte - idx;
>
> - if (unlikely(folio_start < max(address & PMD_MASK, vma->vm_start)))
> - goto check_folio;
We are handling a corner case a large folio is remapped to an unaligned address.
For example,
A 64KiB mTHP at address: XGB + 2MB +4KB,
Its start address will be XGB + 2MB - 60KB which is another PMD.
The previous code will return false; now your can_swapin_thp() will return true
as you are using XGB + 2MB - 60KB as the argument "addr" in can_swapin_thp().
> - if (unlikely(folio_end > pmd_addr_end(address, vma->vm_end)))
> - goto check_folio;
> -
> - folio_ptep = vmf->pte - idx;
> - folio_pte = ptep_get(folio_ptep);
> - if (!pte_same(folio_pte, pte_move_swp_offset(vmf->orig_pte, -idx)) ||
> - swap_pte_batch(folio_ptep, nr, folio_pte) != nr)
> + if (!can_swapin_thp(vmf, folio_ptep, folio_address, nr))
Thanks
Barry
Powered by blists - more mailing lists