From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C86517BA2 for ; Mon, 23 Feb 2026 04:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771821651; cv=none; b=cxY0QdbOE6B/UiZOmQZulpDq/NN4JO7iuNHW7PWrff89LebhZjASD9aKH1a0Q11oxPq3f9GsksjRakZLNtbblNmYqoTPTfLNRt+tGpY5sJWaOD4DRAAo8UJAJF0vNIEdBFNorTOEmtoIsElf0zzuPvCNOnUY4xxeXQlv6nmvXh0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771821651; c=relaxed/simple; bh=ms2X+fwZo6xlOFmDnOmeDQflmBERL8IGZ1qeqnJ89cE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DWVB4QT1p92J3bF2Yp6T4nzMUtHk+zShAY3RxGLQlGnA+HeYwhHmfeAJekvtOa2bxFA1Xr5Y+N7leesQHCyRcy+Snx9W92ZqLiXlDOLozbGxjTjgsYOWIT/enH0qfOOYdkntzlT6kMdgjPhJQMYGLIgIkgcVf5gxcrk+zHbRzCU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2A03D339; Sun, 22 Feb 2026 20:40:41 -0800 (PST) Received: from [10.164.19.28] (unknown [10.164.19.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 118753F59E; Sun, 22 Feb 2026 20:40:43 -0800 (PST) Message-ID: Date: Mon, 23 Feb 2026 10:10:41 +0530 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: Andrew Morton Cc: david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.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> <20260219143327.7693e4b1474a337821e4c637@linux-foundation.org> Content-Language: en-US From: Dev Jain In-Reply-To: <20260219143327.7693e4b1474a337821e4c637@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 20/02/26 4:03 am, Andrew Morton wrote: > On Thu, 19 Feb 2026 11:18:27 +0530 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. >> >> ... >> >> --- 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); > It's a bad sad to remove unneeded code by retaining that code and > adding even more code. > > Perhaps add a comment reminding us to remove this altogether at a later > date? But then shouldn't I remove it just now :) try_collapse_pte_mapped_thp is anways going to bail out if such a bug occurs, so nothing goes wrong. In short this check is actually useless, apart from the fact that this lets us spot a bug (which I doubt won't be figured out by other code paths already).