Re: [RFC PATCH 08/57] mm/collapse: scan a table for what a collapse could use
Kiryl Shutsemau <[email protected]>
| Newsgroups | org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.kernel.vger.linux-trace-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <aowPqZU0aj2gSEjW@thinkstation> |
On Mon, Aug 24, 2026 at 04:39:03PM +0800, Lance Yang wrote:
> >+ /*
> >+ * The bitmap and the selection offsets stay relative to the table:
> >+ * natural-alignment math needs the table-absolute position, not the
> >+ * position within an arbitrarily placed VMA.
> >+ */
> >+ first_offset = (start - pmd_addr) >> PAGE_SHIFT;
> >+ for (i = first_offset, addr = start; addr < end;
> >+ i++, addr += PAGE_SIZE) {
> >+ pte_t pteval = ptep_get(pte + (i - first_offset));
>
> Hmm, ptep_get() does not look right for a lockless scan ...
>
> On arm64, a contiguous PTE sends ptep_get() to contpte_ptep_get():
...
> The later freeze can reject a stale candidate, but the earlier PTE read
> is still lockless. Should the read use ptep_get_lockless() so arm64 can
> retry if it finds an inconsistent PTE in the contpte range?
Good catch, thanks -- switched to ptep_get_lockless() for v2.
I don't think it would lead to any correctness issues: both variants
take the pfn and the protection bits from one __ptep_get() of the target
entry, so all contpte_ptep_get() can get wrong here is the young and
dirty bits it gathers from the neighbours. The scan reads dirty only
for the lazyfree skip, which the freeze re-tests under the page table
lock, and young only as a hint.
But it is still the wrong accessor for a walk that holds no lock.
collapse_faultin_addr() already reads its entry with ptep_get_lockless().
--
Kiryl Shutsemau / Kirill A. Shutemov