From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 412AB3CC32D for ; Wed, 15 Jul 2026 08:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784103767; cv=none; b=uy3a6+WN3Kne7aNAIRhYVwrbfo+uDdBipozuv1LElR93U/Uf/RIvbPx03y0DNrrhaO656hM5MIS+/X7Cqy/7hgKEMePS08TqjwwDwmtrpsvHvQ817HKvQg865T2MRYfVfwCXBCIBDnT6hGExB9IBjAg2CCj3fLc0VnlN9XJ6KcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784103767; c=relaxed/simple; bh=Pp8X5e64eoIp3Quy7N6fcGdQQM8OIlXiZ3Thkq99u54=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=u8fgZSiUCOecKUO/AKbic0P/yzLvlfJHKOxPQ/8vh34aHLnD2iWqiN2qN8OJwMZb0TTOm/q2nD7ybBWyrkiFXu3/mGGuKlLu1lLUVaFONX3Pj5vf217pBupdYaVvdnJscBgkEVmdq3oaQquhzmvkaonibOgViNVxiJ2ChKijjG0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=SHhoEy2A; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="SHhoEy2A" Message-ID: <4a4934c2-eb3c-4ca3-8bfa-526ef347b4b1@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784103763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pCe0v0Nf9LtwVUu7mtTa5Kp4tDUAQbhNLGkNcoZOsCc=; b=SHhoEy2AKlMPo9UfUEL2v/x3eYpd/hoZyEntKUd9UtsUvRExBLPMkhiiw+sNiSarojVEHX lmMq1Rbu8t25xNmiaLBnFy5O8E0tzeSMtCRZdu/6noLwq3TLsYTlCvxgCcad+sTtzoFs+y y+1lJFrTkANBJ/46wDWuKuWxFKNI1RQ= Date: Wed, 15 Jul 2026 16:22:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/thp: support mTHP in thp_underused() To: Baolin Wang , Nico Pache 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> <414075de-e039-4bc5-8316-bef297e72b42@linux.alibaba.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ye Liu In-Reply-To: <414075de-e039-4bc5-8316-bef297e72b42@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2026/7/15 15:35, Baolin Wang 写道: > 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". > Hi Nico,Baolin Thanks for the review and to Baolin for providing the relevant information. You're right – non‑PMD folios aren't on the deferred split list, so this patch alone is pointless. I'll drop it and continue to follow the discussions surrounding the Joanne patch series instead. Sorry for the noise. > [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 >>> > -- Thanks, Ye Liu