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 D5008343897 for ; Tue, 9 Jun 2026 14:32:09 +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=1781015530; cv=none; b=jNKlQJHcWCPqBUapOgUynwPjf2Z7sPcC9fyAXRKrowcyCPr1xgdFudAyNquBl1plu6GHZv4fOJlSwSstAe44BI0ln8J6BeeLGNovJ/p3vfIzFJH3yOcopaX2EiNvdHSLonHLrixR34W1OPI7EO3xtwN7qXa6iJ/lZqrzb/nKo0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781015530; c=relaxed/simple; bh=nLr+AxUIrrDDxmQHrIQpTcf0os4Fq9cCWK5eGAmJ4Fw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a9TJdZsrU2fsVa0iosFwrqG5mx3Jd+gPGj/RHFS8hIc/PJDpRspSPTF0WEc8eg78e3cqTMWovt0ztj+BuG3zWd45qTmHgKir/LHO48m8kdxrZqoqY47yz6j6m74hwWrvfcqhhBdq+4y264dJxKINRFgbRhYBOD/rHSE76vKtqF8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EOHoCpei; 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="EOHoCpei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E7F21F00893; Tue, 9 Jun 2026 14:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781015529; bh=BwCzMG/64t2lk7Go02waAN9KLOkdK/seZ1MO0narm8E=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=EOHoCpeiUhQq0R0L7pD+9KNJm6OcPM4fWRzUbcr02Sf4ZdWNgvnBcyzu+DiXzMXU+ 50NQCdcqLnlosNgdp8elQ3NAWYasuaLRS+oFVDppv3LEnkPkNbio4NLHluFP91lGiG tJ2H6CmOG5+m5K8irI9thKs/hNvU6U0/sVBqUpsSxeoq0tP154aCqBu8+aZjgywod1 Oz1S+ZhHe0+dh3UoaJnUjLMuQTb9wVFK7r+SAzKq50JB6NozRrMD8bfJJeK0FqGd4X gRKskGa2g+Fe4Vu5Ug2ysWJ0IYqZNuS6zCod9IqLecaSxr3jk3EVeN7b52f+TIx2Na KpzbxQ6L4CneQ== Date: Tue, 9 Jun 2026 15:32:03 +0100 From: Lorenzo Stoakes To: Lance Yang Cc: akpm@linux-foundation.org, david@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH mm-unstable 1/1] mm/khugepaged: fix PMD collapse swap PTE accounting Message-ID: References: <20260609120443.71864-1-lance.yang@linux.dev> 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: <20260609120443.71864-1-lance.yang@linux.dev> On Tue, Jun 09, 2026 at 08:04:43PM +0800, Lance Yang wrote: > From: Lance Yang > > mthp_collapse() uses mthp_present_ptes to decide whether a range has > enough occupied PTEs to try collapse. Swap PTEs accepted by > collapse_scan_pmd() are counted in unmapped, but are not represented in > mthp_present_ptes. > > When lower orders are enabled, collapse_scan_pmd() relaxes max_ptes_none > so the scan can cover the whole PMD and build the bitmap. mthp_collapse() > then checks the PMD-order candidate using the bitmap. > > With max_ptes_none set to 0, a range with 511 present PTEs and one swap > PTE no longer reaches collapse_huge_page(), even though PMD collapse can > handle swap PTEs up to max_ptes_swap. > > Account unmapped PTEs only for PMD order. PMD collapse supports swap PTEs > through max_ptes_swap, while lower-order mTHP collapse does not currently > support non-present PTEs. Keep non-present PTEs out of the lower-order > eligibility check. > > Signed-off-by: Lance Yang LGTM, so: Reviewed-by: Lorenzo Stoakes > --- > Sent separately, as discussed in [1], to spell out the PMD-order swap PTE > case. Patch [2] is still only in mm-unstable, so no Fixes: tag. > > [1] https://lore.kernel.org/linux-mm/CAA1CXcD7WAiA1b9GTLAuNZ+kHaFx0SzZwpBkqAZ=s+RHsTUaow@mail.gmail.com/ > [2] https://lore.kernel.org/linux-mm/20260605161422.213817-12-npache@redhat.com/ > > mm/khugepaged.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index b12187709f6d..617bca76db49 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -1508,6 +1508,14 @@ static enum scan_result mthp_collapse(struct mm_struct *mm, > nr_occupied_ptes = bitmap_weight_from(cc->mthp_present_ptes, offset, > offset + nr_ptes); > > + /* > + * Swap PTEs accepted during the scan are counted in @unmapped, > + * not in the present-PTE bitmap. Account them for the PMD-order > + * candidate. > + */ > + if (is_pmd_order(order)) > + nr_occupied_ptes += unmapped; > + > if (nr_occupied_ptes >= nr_ptes - max_ptes_none) { > enum scan_result ret; > > -- > 2.49.0 > Thanks, Lorenzo