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 - 05:53:01 EST
On Fri, Nov 06, 2026 at 05:29:45PM +0800, Vernon Yang wrote:
> 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)) {
I'd rather keep < as it's the general form used for overflow checks and I don't
want to bake in assumptions about the nature of the overflow or make somebody
have to reason about that :)
>
> --
> Cheers,
> Vernon
--
Cheers, Lorenzo