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 E8B6F261B6D for ; Wed, 4 Mar 2026 08:44:43 +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=1772613886; cv=none; b=RuNLs6FEeaRbEa+17zS641QB1iJlVbsicnHR09Td2ygm8NT/TLc8IZTOtcCF6Mc69lpUsVGrEvsECi5tCRMinJo38XXL6bMTpDl5SEKFdcSTMqZvqXkd1oU/Dc0PfF04BT0PDWPVwvuNu5VuBopMm7t4H3XMKtHW56VDmVzm+0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772613886; c=relaxed/simple; bh=4coBzyg+VNC9NrPrjj68oHPVf7mVBp8k7q8Sn+VFx2E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CBM1Hnx8K4gK3MtJWPjKSvHX6EkY41RIbD5VMAe0KWWVwlfAHW19RZqbHE+bRLeHAu545w1KxVY2PgV48oprzauQpzbmtu8xwkydiLIpmuLIbakpux0wHz83VXfM3oC7MPqwI9ZzZx3bCnhVtD8MX9r2kvnVIcuwo5+v/hggYNU= 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 CAD97339; Wed, 4 Mar 2026 00:44:30 -0800 (PST) Received: from [10.164.19.52] (unknown [10.164.19.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 01A283F7BD; Wed, 4 Mar 2026 00:44:32 -0800 (PST) Message-ID: <68178718-7177-4e5c-a12a-4bfd35459b54@arm.com> Date: Wed, 4 Mar 2026 14:14:29 +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 v2] khugepaged: remove redundant index check for pmd-folios To: Wei Yang Cc: akpm@linux-foundation.org, 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: <20260227143501.1488110-1-dev.jain@arm.com> <20260304082735.j4brgesse3vp34rz@master> Content-Language: en-US From: Dev Jain In-Reply-To: <20260304082735.j4brgesse3vp34rz@master> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 04/03/26 1:57 pm, Wei Yang wrote: > On Fri, Feb 27, 2026 at 08:05:01PM +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) > > This is because __filemap_add_folio() align the index to folio_order(), right? No, see code around instances of mapping_align_index(). We retrieve the max order from the index, not the other way around. We already are given the index to put the folio at, by the caller, so have to construct the order from that. > >> >> 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, remove this check. >> While at it, simplify the comments. >> >> Signed-off-by: Dev Jain >