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 59A983955EB for ; Wed, 10 Jun 2026 08:02:46 +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=1781078570; cv=none; b=IGh0Dx9Q1xAZMsNLNutmvKNwd/KKx8aTBn2lylXQWNfxtI2fGJ2plzOocQVonfK6+NMobz+KPMscNl66JX/Xy1xxcJgfsnxxasB3Pf3DPqNladLKYUGmX28MD17kHfELLkXKiUrT9JD4pN3OpuMMPUcAJ+si5gZ6vmKyyYNZROo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781078570; c=relaxed/simple; bh=pXF0AkVanSeOGVbRSP3tJgaCSKnp6QdVUi2wtm9ERiM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kW/iENDbvbAXgiNENgk2cIY+S75TIXvURwWP1OzreSNHDsfbWQfKgDwZKygEkC9TU0TUbGlpTjwRYEhhrIELn6KM4OSJMUBQz+io2i+GQsW14bQnmd9bpa6PnKnZ1uDWnlIlkck6uNVYaJzz2mq8YXrv7r2Aq11Ymk1X58C1mLk= 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=wuS7AjEJ; 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="wuS7AjEJ" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781078559; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=8gtYxj6a7fAD7Z6IKLgRqzmm5d2LG5rVj+H+R61HoGo=; b=wuS7AjEJTjumAlJDymxGpb2UolHfCkl0oNX7D5peGJvy3zDEVcpDLR9FK4dDEOa/+eeXJi8CqkCL2tn3fdiHcCelVZVUPoaUbtTvNUTMP1H4Ou5ZLscaQsn16ohUjFNx+1gB+GwdBmYr+2ARTuqUIh2ykR9srXuVs9iOXmzQa4c= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R521e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0X4Zwsje_1781078557; Received: from 30.74.144.110(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X4Zwsje_1781078557 cluster:ay36) by smtp.aliyun-inc.com; Wed, 10 Jun 2026 16:02:38 +0800 Message-ID: <92ed35ad-4f8c-43d2-b72d-b46f07533a3a@linux.alibaba.com> Date: Wed, 10 Jun 2026 16:02:37 +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 mm-unstable 1/1] mm/khugepaged: fix PMD collapse swap PTE accounting To: Lance Yang , akpm@linux-foundation.org Cc: david@kernel.org, ljs@kernel.org, ziy@nvidia.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 References: <20260609120443.71864-1-lance.yang@linux.dev> From: Baolin Wang In-Reply-To: <20260609120443.71864-1-lance.yang@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/9/26 8:04 PM, 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. Feel free to add: Reviewed-by: Baolin Wang > 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; >