From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6068428469B for ; Thu, 19 Feb 2026 22:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771540409; cv=none; b=uDWJH5WesjxF5wVs9DECAfbgaNKlklrIF1J9yzl2Eb8cchHgIy1OUVz68whdinPKF8wl0O9X+ddB0/jgqFDR4y8YmtbG4L8glV+512gH3a9NgnxWXSASIOZtuZo1pgTU7AnLO5oAfFhS13MhDdorgOpJNVwxvZyxVer0LrWAZ1E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771540409; c=relaxed/simple; bh=W9HLRQM9kqFpJqXVvPFl/ReXTVVBlA9Iv4Py9xp2Vgk=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=UBG/ZFO4V2qXz2B4v9diKzRQirgMhAsABkzOUp8pmrSL6Gk3gjN2NmGia/UUJnKfPDNFxElBM7M4qkptYij8DLIYhCqmgOA8b2pOMZM5vmGJ9tdoYScfO1NeGJLmKeXiY3Pg6GcnBef9H+AsW9AwHWyZxtZey5HvxS2fDHytORE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=NBFnaQyi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="NBFnaQyi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E872C4CEF7; Thu, 19 Feb 2026 22:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1771540408; bh=W9HLRQM9kqFpJqXVvPFl/ReXTVVBlA9Iv4Py9xp2Vgk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NBFnaQyioKKw1bIV5AcFUa9w94kDnQ2v7fOfXUvRvawLkMTHvWO9edHXl7gFEvbsf OZMlvWsTY7IKgqoKwAMv+VszsCdHhpQ/VsNVKf2IesBtXt7hHTKBSV62mkuQU57wpt smtqjGhkuSuYv+2zbDWUv1GfNLqSZ5CjArIdGI5Q= Date: Thu, 19 Feb 2026 14:33:27 -0800 From: Andrew Morton To: Dev Jain 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 Subject: Re: [PATCH] khugepaged: convert redundant check to WARN_ON Message-Id: <20260219143327.7693e4b1474a337821e4c637@linux-foundation.org> In-Reply-To: <20260219054827.4111334-1-dev.jain@arm.com> References: <20260219054827.4111334-1-dev.jain@arm.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit 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?