Re: [PATCH] mm/migrate_device: fix folio refcount leak on folio_split_unmapped failure
From: Kiryl Shutsemau
Date: Wed Mar 04 2026 - 09:01:26 EST
On Wed, Mar 04, 2026 at 04:01:32AM -0800, Usama Arif wrote:
> From: Usama Arif <usama.arif@xxxxxxxxx>
>
> migrate_vma_split_unmapped_folio() takes an extra reference via
> folio_get() before calling folio_split_unmapped(). On success, the
> split consumes this reference: __folio_freeze_and_split_unmapped()
> expects the +1 in its folio_ref_freeze() check, and distributes it
> across the resulting sub-folios via folio_ref_unfreeze(...+1), which
> are later balanced by folio_put() calls in __migrate_device_finalize().
Without this explanation folio_get() looks very random. And I still
can't say I understand reference management for the folios here.
Who takes reference for the folio if it !THP that gets return in the
_finalize()?
Can we get reference for THP and !THP at the same spot?
I think we should avoid spacial-casing THP where possible.
--
Kiryl Shutsemau / Kirill A. Shutemov