Re: [PATCH 30/32] mm/migrate: fix KSM oddity by checking expected refcount without mappings
From: David Hildenbrand (Arm)
Date: Wed Dec 02 2026 - 13:42:47 EST
On 12/2/26 18:00, Zi Yan wrote:
> On Sun Nov 29, 2026 at 5:07 AM EST, David Hildenbrand (Arm) wrote:
>> KSM can add page table mappings to an unmapped folio while it is locked
>> and getting migrated. While that is completely inconsistent with
>
> The first sentence is confusing, since I read it as if KSM adds mappings
> while holding the folio lock.
>
> How about ?
>
> KSM can add page table mappings to a folio that the migration code has
> locked and unmapped.
Yes, much better.
[...]
>> +++ b/mm/migrate.c
>> @@ -914,7 +914,7 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst,
>> struct folio *src, void *src_private,
>> enum migrate_mode mode)
>> {
>> - int rc, expected_count = folio_expected_ref_count(src) + 1;
>> + int rc, expected_count = folio_expected_unmapped_ref_count(src) + 1;
>>
>> /* Check whether src does not have extra refs before we do more work */
>> if (folio_ref_count(src) != expected_count)
>
> Sigh, another special case to clean up later. Anyway,
Yeah, KSM should just take proper locks. I played with that but it turned too
ugly for a quick fix.
Thanks!
--
Cheers,
David