Re: [PATCH] mm/migrate_device: pin large folios before splitting

From: David Hildenbrand (Arm)

Date: Thu Jul 02 2026 - 04:04:31 EST


On 7/2/26 02:33, Alistair Popple wrote:
> On 2026-07-02 at 06:16 +1000, Zi Yan <ziy@xxxxxxxxxx> wrote...
>> On 1 Jul 2026, at 16:06, David Hildenbrand (Arm) wrote:
>>
>>>
>>> I mean, it's one of the basic rules: if you lookup a page in the page table, the
>>> moment you drop the lock that might be invalid.
>>>
>>> If we were to document that everywhere... this is not really the secret sauce we
>>> want to document everywhere.
>>
>> In this particular case, split_folio() is used in migrate_vma_split_folio()
>> and split_folio() wraps __split_huge_page_to_list_to_order(), which documents
>> the requirement of elevated folio reference. One who wants to get familiar
>> with kernel code can be expected to chase down to
>> __split_huge_page_to_list_to_order() and find the requirement.
>>
>> With LLMs, it is probably as easy as asking “why is folio_get() needed here?”.
>
> The interesting part of the comment isn't why the folio_get() is needed, it's
> where the corresponding reference is dropped/returned. I've spent far too many
> hours in this code trying to figure out why a page didn't migrate because of
> a spurious refcount and it's not easy figuring out where the matching get/puts
> occur.
>
> So the comment could probably be condensed but I think it's valuable.

"migrate_vma_split_folio() consumes this reference" would be better indeed.

--
Cheers,

David