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

From: Lorenzo Stoakes (ARM)

Date: Fri Nov 06 2026 - 07:12:30 EST


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.

--
Cheers, Lorenzo