Re: [PATCH v2] khugepaged: remove redundant index check for pmd-folios
From: Baolin Wang
Date: Mon Mar 02 2026 - 21:18:54 EST
On 2/27/26 10:35 PM, Dev Jain wrote:
Claim: folio_order(folio) == HPAGE_PMD_ORDER => folio->index == start.
Proof: Both loops in hpage_collapse_scan_file and collapse_file, which
iterate on the xarray, have the invariant that
start <= folio->index < start + HPAGE_PMD_NR ... (i)
A folio is always naturally aligned in the pagecache, therefore
folio_order == HPAGE_PMD_ORDER => IS_ALIGNED(folio->index, HPAGE_PMD_NR) == true ... (ii)
thp_vma_allowable_order -> thp_vma_suitable_order requires that the virtual
offsets in the VMA are aligned to the order,
=> IS_ALIGNED(start, HPAGE_PMD_NR) == true ... (iii)
Combining (i), (ii) and (iii), the claim is proven.
Therefore, remove this check.
While at it, simplify the comments.
Signed-off-by: Dev Jain <dev.jain@xxxxxxx>
---
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>