Re: [PATCH v4 10/17] mm/huge_memory: move the racy refcount check into unmap_folio()
From: Kiryl Shutsemau
Date: Tue Sep 08 2026 - 14:10:08 EST
On Tue, Sep 08, 2026 at 02:12:14AM +0800, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> The check only exists to avoid the expensive PMD-splitting unmap of a
> folio that cannot be split anyway. Move it from __folio_split() into
> unmap_folio(), right before the PMD split, so both the anon and file
> split helpers get the early check without repeating it.
>
> unmap_folio() now returns -EAGAIN if the check fails and the split
> helpers propagate the error. folio_split_unmapped() drops its own
> copy of the check: it works on already unmapped folios and the
> definitive folio_ref_freeze() in __folio_freeze_split_anon() still
> catches unexpected references.
>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
--
Kiryl Shutsemau / Kirill A. Shutemov