Re: [PATCH v2 3/3] mm/khugepaged: release contended mmap read lock after scanning enough VMAs

From: David Hildenbrand (Arm)

Date: Mon Nov 09 2026 - 09:12:35 EST


On 11/6/26 13:07, Lorenzo Stoakes (ARM) wrote:
> On reflection, I think this would be better implemented as something like:
>
> static void collapse_scan_mm_slot(unsigned int progress_max, ...)
> {
> unsigned int long lock_start = jiffies;
> ...
> for_each_vma(vmi, vma) {
> ...
> if (time_after(jiffies, lock_start) && mmap_lock_is_contended(mm)) {
> mmap_read_unlock(mm);
> cond_resched();
> mmap_read_lock(mm);
> lock_start = jiffies;
> vma_iter_set(&vmi, mm_slot->address);
> continue;
> }
> }
> }
>
> Which avoids magic numbers, and means if we hold the lock for 1-10ms (depending
> on HZ), which is a long time in the kernel to hold a lock, AND the lock is
> contended, we drop/reacquire.

That approach indeed sounds better to me regarding lock contention.

--
Cheers,

David