From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4723339396 for ; Tue, 18 Aug 2026 07:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787037068; cv=none; b=oilnteJk9Oe8XK0rK/rNS+7oBvhbzTiqGVZAJJPivuIxWxFYgzEs4cWhfr6SdfElxbPLgrWhqGozXVCgPvzfmGQgp7FP4Nc2JDeXy4bBhJxlwQMwa03jTQnGPm1brjuiuIkYoqsWLCtAlcnZRxBXkPD7e8v7WGGkVfqWQmILaYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787037068; c=relaxed/simple; bh=zBloDYhFOoK+ZsOdnAL4KD1db2hJ+wU3Ve8BAVdy+d0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jSi0SJcYclZh0rnYmP4wgnk+rXCwboxeWJPytzWuDDwLjH2yikfDVYruWxvXe0a6BOHepuxlg09c0izPoNhksjVaCIjGuql5f/aJ6NyZ9JZeo2YSI6bSNoabA1L+kTfT0+BmaQxs9EZzv3F2wvbTKtj62Vr4EXx238nP/cI9WxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oPYKmsqs; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oPYKmsqs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FA731F000E9; Tue, 18 Aug 2026 07:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787037066; bh=hcKP0GI/8MCMjQwWzxd7ikqJRzxxF2VaTggnrgcABlk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=oPYKmsqsTLaYnsgF4u2veT2txSMhhZZUUeSbMLopLJAqC1cViPnqitdh0VU4sCxJZ vklK8cfYEd5nYknsnbskjjNjSIa6ENmFxsP2t8+k0M1MnDOQgrQyzFscoufJnlpEW9 dIM/7z3OD59/ZOB9xWtYhkoWHBSrR4dsgH8v9/embqCjrftRIwyza0+3Lbb6ujyUxk RqL099o+eCBsjeevXNzG8PQVIW8LwJvaHrMgwpJZr6gxxd77FX8/lnjdCPwYiFnBMB yUIjqeXM+iybkw3rjWcPvKruuM3Gm0yVXoFNGuFSQPkhL2sTyG+f7T+D32f2i8ZDxo jyNOnApjgnwRw== Date: Tue, 18 Aug 2026 08:10:46 +0100 From: "Lorenzo Stoakes (ARM)" To: Baolin Wang Cc: akpm@linux-foundation.org, david@kernel.org, hughd@google.com, vbabka@kernel.org, annh@google.com, ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, dev.jain@arm.com, ryan.roberts@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: fix incorrect vm_flags usage when checking allowable orders for tmpfs Message-ID: References: <7d5b5eb27be798f89d563b06254c947ff53db0b2.1787020910.git.baolin.wang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7d5b5eb27be798f89d563b06254c947ff53db0b2.1787020910.git.baolin.wang@linux.alibaba.com> On Tue, Aug 18, 2026 at 10:47:26AM +0800, Baolin Wang wrote: > Lance reported that when nothing else causes the mm to be considered for > khugepaged collapse, an MADV_HUGEPAGE-advised tmpfs VMA alone does not trigger > scanning. > > After commit 6beeab870e70 ("mm: shmem: move shmem_huge_global_enabled() into > shmem_allowable_huge_orders()"), the shmem/tmpfs allowable order check reads > vma->flags directly. However, when MADV_HUGEPAGE is handled, > khugepaged_enter_vma() is called before the VMA's flags have been updated, > so the check uses stale flags and incorrectly rejects the VMA for collapse. > As a result, khugepaged does not collapse the tmpfs file into PMD order in time. > > Fix this by calling khugepaged_enter_vma() with the new VMA flags in > madvise_update_vma(). Meanwhile we can remove the khugepaged_enter_vma() > in hugepage_madvise(). > > Reported-by: Lance Yang > Closes: https://lore.kernel.org/all/20260815181632.21453-1-lance.yang@linux.dev/ > Fixes: 6beeab870e70 ("mm: shmem: move shmem_huge_global_enabled() into shmem_allowable_huge_orders()") > Cc: stable@vger.kernel.org > Suggested-by: Lorenzo Stoakes (ARM) > Signed-off-by: Baolin Wang Thanks LGTM so: Reviewed-by: Lorenzo Stoakes (ARM) > --- > Changes from v1: > v1: https://lore.kernel.org/all/ed34ca03ae7d65e89467fb87bc961f5497049c00.1786948410.git.baolin.wang@linux.alibaba.com/ > - Update the commit message (per Lorenzo). > - Call khugepaged_enter_vma() in madvise_update_vma() (per Lorenzo). > --- > mm/khugepaged.c | 6 ------ > mm/madvise.c | 8 ++++++++ > 2 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 5a06e3942e88..79effd3f3da4 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -454,12 +454,6 @@ int hugepage_madvise(struct vm_area_struct *vma, > case MADV_HUGEPAGE: > *vm_flags &= ~VM_NOHUGEPAGE; > *vm_flags |= VM_HUGEPAGE; > - /* > - * If the vma become good for khugepaged to scan, > - * register it here without waiting a page fault that > - * may not happen any time soon. > - */ > - khugepaged_enter_vma(vma, *vm_flags); > break; > case MADV_NOHUGEPAGE: > *vm_flags &= ~VM_HUGEPAGE; > diff --git a/mm/madvise.c b/mm/madvise.c > index c179938097bf..cb93cf82d8df 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -178,6 +178,14 @@ static int madvise_update_vma(vm_flags_t new_flags, > /* vm_flags is protected by the mmap_lock held in write mode. */ > vma_start_write(vma); > vma->flags = new_vma_flags; > + /* > + * If the vma become good for khugepaged to scan, > + * register it here without waiting a page fault that > + * may not happen any time soon. > + */ > + if (vma_flags_test(&new_vma_flags, VMA_HUGEPAGE_BIT)) > + khugepaged_enter_vma(vma, vma_flags_to_legacy(new_vma_flags)); > + > if (set_new_anon_name) > return replace_anon_vma_name(vma, anon_name); > > -- > 2.47.3 > -- Cheers, Lorenzo