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

From: Vernon Yang

Date: Fri Nov 06 2026 - 04:31:27 EST


On Fri, Nov 06, 2026 at 10:12:46AM +0800, Vernon Yang wrote:
> On Thu, Nov 05, 2026 at 08:57:24PM +0000, Lorenzo Stoakes (ARM) wrote:
> > if (!collapse_possible_orders(vma, vma->vm_flags, TVA_KHUGEPAGED)) {
> > - /* Unable to collapse, skip to the next candidate. */
> > - mm_slot->address = ALIGN(vma->vm_end, HPAGE_PMD_SIZE);
> > + const unsigned long next =
> > + ALIGN(vma->vm_end, HPAGE_PMD_SIZE);
> > +
> > cc->progress++;
> > + /* Check for overflow. */
> > + if (unlikely(next < vma->vm_end)) {
>
> I think you want it to be like that.
>
> if (unlikely(next >= vma->vm_end)) {
> ^^

Don’t read this comment please. Your code is right.

The VMA at the top of mm, after aligning the end values according to the
PMD, may overflow to 0.

It might be easier to understand if this coding is used.

if (unlikely(next == 0)) {

--
Cheers,
Vernon