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

From: Vernon Yang

Date: Fri Nov 06 2026 - 08:28:20 EST


On Fri, Nov 06, 2026 at 12:07:53PM +0000, 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.

Looks good to me. Is the test result of this solution the same as the
current one?

--
Cheers,
Vernon