Re: [PATCH 1/1] mm/ksm: trylock the mmap lock in the unstable tree walk

From: David Hildenbrand (Arm)

Date: Wed Sep 09 2026 - 14:08:55 EST



>> index 49d48d1e0998..3cfb09a926ff 100644
>> --- a/mm/ksm.c
>> +++ b/mm/ksm.c
>> @@ -820,7 +820,14 @@ static struct page *get_mergeable_page(struct ksm_rmap_item *rmap_item)
>> struct folio_walk fw;
>> struct folio *folio;
>>
>> - mmap_read_lock(mm);
>> + /*
>> + * We trylock because we don't want ksmd to wait for an mm that is
>> + * busy changing its memory layout: we prefer to skip this page and
>> + * let the next full scan retry it, like the folio trylock in
>> + * try_to_merge_one_page().
>> + */
>> + if (!mmap_read_trylock(mm))
>> + return NULL;
>> vma = find_mergeable_vma(mm, addr);
>> if (!vma)
>> goto out;
>> --
>> 2.43.0
> Sorry, NACK

Agreed. Likely the answer is to switch to per-vma locks here. All we do is a
folio_walk_start() to look up a page, that's not too crazy :)

--
Cheers,

David