From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 AF42A37A488 for ; Wed, 15 Jul 2026 07:35:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784100939; cv=none; b=NDp2rS1C8uGDa8zMLor+R16UNi379QamUP7b+20BGcV4AxLJ5S+vLS2MqD1ES7BcTDvlTc31P/NxLhunUfroY2rt/akjxkXgK4qHhTD0CODdXbUb1SfDU/EEiNGMeE8dzqVLjJjVZOdIu55bmw5uT6iEh4GKeXfION5hSIxwPek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784100939; c=relaxed/simple; bh=dAHayjTFgXiJY+xD37bZIENqU3i5ZSwI5acXnaeB/J4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=SMZ6NTLuTK2ulAWjR0013CkWPTqh/QbKfGVmM5/310cx3jCmyxyqWccsW5gEfkKEmzEbJkh4P23c81uAjRIMgACm9f5JgnP3+AUZXQdf4mx998InmHAz+UOU6tNhWqpeJIkhF4k8Tn7pUCVTAxhndfNXc3qcSFnLzHsqC46X+Ag= 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=GsfXrd2c; arc=none smtp.client-ip=115.124.30.130 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="GsfXrd2c" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1784100933; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=DN9qkIBfxQkFxgIJBMV3MbSvsMoUDj3yx8PMyVI22Rc=; b=GsfXrd2czrddNrDu7KSnbX9XHhQaWuKuzv7Jb+J6/FYbrwp1sEmu31ZPs0Inni+OxyAcTx16dnveSeBgpSIxF9FdX9Oozi/tCfh6lrTQx/ZoGyD/f9zGjDW5aSRdUoaj5/78rC7K1e1TXdCye9mNNVrYtzI2raWYHzFo1Wme5Zg= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0X78GlGU_1784100931; Received: from 30.74.144.123(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X78GlGU_1784100931 cluster:ay36) by smtp.aliyun-inc.com; Wed, 15 Jul 2026 15:35:31 +0800 Message-ID: <414075de-e039-4bc5-8316-bef297e72b42@linux.alibaba.com> Date: Wed, 15 Jul 2026 15:35:30 +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/thp: support mTHP in thp_underused() To: Nico Pache , Ye Liu Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Ye Liu , Zi Yan , "Liam R. Howlett" , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , linux-mm@kvack.org, linux-kernel@vger.kernel.org, joannelkoong@gmail.com References: <20260715062150.114757-1-ye.liu@linux.dev> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit CC Joanne. On 7/15/26 2:42 PM, Nico Pache wrote: > On Wed, Jul 15, 2026 at 12:28 AM Ye Liu wrote: >> >> From: Ye Liu >> >> When khugepaged_max_ptes_none is configured to a non-default value, >> scale it for non-PMD-mappable folios to match the logic in >> collapse_max_ptes_none(), so mTHP can be classified as underused >> instead of being silently skipped due to unscaled PMD-sized thresholds. > > IIUC we don't actually add non-PMD folios to the deferred split list > and only operate on fully mapped folios, so consequently, we never try > to shrink them with the underused shrinker. Right. Joanne sent a similar patch set[1] to split underused mTHP folios, but David said "needs more proper thought". [1] https://lore.kernel.org/all/20260707201735.4113107-1-joannelkoong@gmail.com/ >> Signed-off-by: Ye Liu >> --- >> mm/huge_memory.c | 21 +++++++++++++-------- >> 1 file changed, 13 insertions(+), 8 deletions(-) >> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index 25612af72dca..c642bec967fa 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -4489,24 +4489,29 @@ static unsigned long deferred_split_count(struct shrinker *shrink, >> static bool thp_underused(struct folio *folio) >> { >> int num_zero_pages = 0, num_filled_pages = 0; >> + unsigned int max_ptes_none = khugepaged_max_ptes_none; >> + unsigned int folio_nr = folio_nr_pages(folio); >> int i; >> >> - if (khugepaged_max_ptes_none == HPAGE_PMD_NR - 1) >> + if (!folio_test_pmd_mappable(folio)) { >> + if (max_ptes_none == HPAGE_PMD_NR - 1) >> + max_ptes_none = folio_nr - 1; >> + else if (max_ptes_none) >> + return false; >> + } >> + >> + if (max_ptes_none == folio_nr - 1) >> return false; >> >> if (folio_contain_hwpoisoned_page(folio)) >> return false; >> >> - for (i = 0; i < folio_nr_pages(folio); i++) { >> + for (i = 0; i < folio_nr; i++) { >> if (pages_identical(folio_page(folio, i), ZERO_PAGE(0))) { >> - if (++num_zero_pages > khugepaged_max_ptes_none) >> + if (++num_zero_pages > max_ptes_none) >> return true; >> } else { >> - /* >> - * Another path for early exit once the number >> - * of non-zero filled pages exceeds threshold. >> - */ >> - if (++num_filled_pages >= HPAGE_PMD_NR - khugepaged_max_ptes_none) >> + if (++num_filled_pages >= folio_nr - max_ptes_none) >> return false; >> } >> } >> -- >> 2.43.0 >>