From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 AB25739FCE for ; Tue, 24 Feb 2026 08:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771921305; cv=none; b=jXmRMxbU1J8IZyqam0iDH0oYjjgBhEWyPNTD6KhPDME3WlrEvsWxT90gIUCsRAe9OdLG5+ILL7GAuCJwhyPvwbAmnfyI0Qc4OIPmr5jajqYwOaHfZUs+lvZfhlGJu8tq2eoaJwVsO4NRKFVbf0adJPlNJ1Nr4DKqf5pf/KilBfA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771921305; c=relaxed/simple; bh=6a6bN6l33lpiQ5YYbbdsmzF7SsJmaRKwqgeEOtA7BmQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RDEWYqe7kniC/5xq8ZJ0KAj2AxZubdsyjAC37Q8oUefJFNBYRWqfWWtp5c3k38fuK5CLI98IN9A62Tqo6rUcJLHO1Ss1mekBHhUWWdv+QjyvKLh56lnQvt/h/qOGDHndLQ9/vXgDt0z/dt4ftW9CuNscMSJfI04eYUtzdOXW22M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=nzzcL8rN; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="nzzcL8rN" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1771921301; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=a2mypeU4nOLirbcjVG6GWg/74SRIJqs9Praf4sUkMT0=; b=nzzcL8rN1y1sdLLD4V+B85IM8f3/IUissP9QZoNApB+tnyPQFIJYhij+J3cOrc+BEEQIkkeCVsDkmRboGm+br3NGeHaJEK8d8LNtrLyqbUKOwi1HEKI81FFE97Qo31Lc9F4PKukEvmchY2HpXopvoeagLDjq2o2YTn8WCN9MKsg= Received: from 30.74.144.111(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WziwIZz_1771921299 cluster:ay36) by smtp.aliyun-inc.com; Tue, 24 Feb 2026 16:21:40 +0800 Message-ID: Date: Tue, 24 Feb 2026 16:21:39 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] khugepaged: convert redundant check to WARN_ON To: Dev Jain , akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com Cc: ziy@nvidia.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260219054827.4111334-1-dev.jain@arm.com> From: Baolin Wang In-Reply-To: <20260219054827.4111334-1-dev.jain@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/19/26 1:48 PM, Dev Jain wrote: > Claim: folio_order(folio) == HPAGE_PMD_ORDER => folio->index == start. > > Proof: Both loops in hpage_collapse_scan_file and collapse_file, which > iterate on the xarray, have the invariant that > start <= folio->index < start + HPAGE_PMD_NR ... (i) > A folio is always naturally aligned in the pagecache, therefore > folio_order == HPAGE_PMD_ORDER => IS_ALIGNED(folio->index, HPAGE_PMD_NR) == true ... (ii) > thp_vma_allowable_order -> thp_vma_suitable_order requires that the virtual > offsets in the VMA are aligned to the order, > => IS_ALIGNED(start, HPAGE_PMD_NR) == true ... (iii) > > Combining (i), (ii) and (iii), the claim is proven. > > Therefore, convert this to a VM_WARN_ON. > > Signed-off-by: Dev Jain > --- Make sense to me. Personally, I’d like to keep this VM_WARN_ON() to catch unexpected behavior. Reviewed-by: Baolin Wang > Based on mm-unstable (d9982f38eb6e). mm-selftests pass. > > mm/khugepaged.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index fa1e57fd2c469..f27cbb4d1f62c 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2000,8 +2000,9 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, > * we locked the first folio, then a THP might be there already. > * This will be discovered on the first iteration. > */ > - if (folio_order(folio) == HPAGE_PMD_ORDER && > - folio->index == start) { > + if (folio_order(folio) == HPAGE_PMD_ORDER) { > + VM_WARN_ON(folio->index != start); > + > /* Maybe PMD-mapped */ > result = SCAN_PTE_MAPPED_HUGEPAGE; > goto out_unlock; > @@ -2329,8 +2330,9 @@ static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm, unsigned > continue; > } > > - if (folio_order(folio) == HPAGE_PMD_ORDER && > - folio->index == start) { > + if (folio_order(folio) == HPAGE_PMD_ORDER) { > + VM_WARN_ON(folio->index != start); > + > /* Maybe PMD-mapped */ > result = SCAN_PTE_MAPPED_HUGEPAGE; > /*