All of lore.kernel.org
 help / color / mirror / Atom feed
From: Usama Arif <usama.arif@linux.dev>
To: Joanne Koong <joannelkoong@gmail.com>,
	akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org
Cc: baohua@kernel.org, hannes@cmpxchg.org, kas@kernel.org,
	alex@ghiti.fr, ziy@nvidia.com, baolin.wang@linux.alibaba.com,
	liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com,
	dev.jain@arm.com, lance.yang@linux.dev, vbabka@kernel.org,
	rppt@kernel.org, surenb@google.com, mhocko@suse.com,
	willy@infradead.org, linux-mm@kvack.org
Subject: Re: [PATCH v4 3/4] mm/huge_memory: add a per-order counter for underused splits
Date: Tue, 3 Nov 2026 22:20:43 +0000	[thread overview]
Message-ID: <a16f1f8e-d3b6-4145-890b-51ce3c0a7f03@linux.dev> (raw)
In-Reply-To: <20261103212004.1356327-4-joannelkoong@gmail.com>



On 03/11/2026 21:20, Joanne Koong wrote:
> thp_underused_split_page counts every folio that the deferred split
> shrinker splits for being underused. Today that is only ever a
> PMD-sized folio, but a later patch queues anonymous mTHP folios for
> underused splitting too, at which point this counter would start
> counting mTHP splits as well.
> 
> thp_underused_split_page could then end up larger than thp_split_page,
> and there would be no per-order count of underused splits. That doesn't
> match how the other THP split stats work. In /proc/vmstat,
> thp_split_page and thp_deferred_split_page only count PMD-sized folios.
> Splits of every size, PMD included, are counted per order in the split
> and split_deferred stats under hugepages-<size>/stats/.
> 
> Do the same for underused splits. Only count PMD-sized folios in
> thp_underused_split_page, and add a per-order split_underused stat that
> counts underused splits of every size. The folio's order has to be read
> before splitting it, since the folio is no longer large once the split
> succeeds.
> 
> There is no functional change to thp_underused_split_page yet, as only
> PMD-sized folios are split for being underused today.
> 
> Suggested-by: Kiryl Shutsemau <kas@kernel.org>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>  Documentation/admin-guide/mm/transhuge.rst |  6 ++++++
>  include/linux/huge_mm.h                    |  1 +
>  mm/huge_memory.c                           | 10 ++++++++--
>  3 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
> index b187d618452f..6f2d92a2a556 100644
> --- a/Documentation/admin-guide/mm/transhuge.rst
> +++ b/Documentation/admin-guide/mm/transhuge.rst
> @@ -719,6 +719,12 @@ split_deferred
>          it would free up some memory. Pages on split queue are going to
>          be split under memory pressure, if splitting is possible.
>  

In this same commit, would you mind also doing s/THP/PMD mapped THP/ in
thp_underused_split_page section in /proc/vmstat section?

Apart from that, LGTM

Acked-by: Usama Arif <usama.arif@linux.dev>

> +split_underused
> +	is incremented when a huge page on the split queue was split
> +	because it was underused. This happens when the number of zero-filled
> +	pages in the huge page is above a certain threshold scaled from
> +	/sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none.
> +
>  nr_anon
>         the number of anonymous THP we have in the whole system. These THPs
>         might be currently entirely mapped or have partially unmapped/unused
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index c745f7ad2298..421217aca4ed 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -142,6 +142,7 @@ enum mthp_stat_item {
>  	MTHP_STAT_SPLIT,
>  	MTHP_STAT_SPLIT_FAILED,
>  	MTHP_STAT_SPLIT_DEFERRED,
> +	MTHP_STAT_SPLIT_UNDERUSED,
>  	MTHP_STAT_NR_ANON,
>  	MTHP_STAT_NR_ANON_PARTIALLY_MAPPED,
>  	MTHP_STAT_COLLAPSE_EXCEED_SWAP,
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 903bbe972011..8f90fb609e57 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -822,6 +822,7 @@ DEFINE_MTHP_STAT_ATTR(shmem_fallback_charge, MTHP_STAT_SHMEM_FALLBACK_CHARGE);
>  DEFINE_MTHP_STAT_ATTR(split, MTHP_STAT_SPLIT);
>  DEFINE_MTHP_STAT_ATTR(split_failed, MTHP_STAT_SPLIT_FAILED);
>  DEFINE_MTHP_STAT_ATTR(split_deferred, MTHP_STAT_SPLIT_DEFERRED);
> +DEFINE_MTHP_STAT_ATTR(split_underused, MTHP_STAT_SPLIT_UNDERUSED);
>  DEFINE_MTHP_STAT_ATTR(nr_anon, MTHP_STAT_NR_ANON);
>  DEFINE_MTHP_STAT_ATTR(nr_anon_partially_mapped, MTHP_STAT_NR_ANON_PARTIALLY_MAPPED);
>  DEFINE_MTHP_STAT_ATTR(collapse_exceed_swap_pte, MTHP_STAT_COLLAPSE_EXCEED_SWAP);
> @@ -842,6 +843,7 @@ static struct attribute *anon_stats_attrs[] = {
>  	&swpout_fallback_attr.attr,
>  #endif
>  	&split_deferred_attr.attr,
> +	&split_underused_attr.attr,
>  	&nr_anon_attr.attr,
>  	&nr_anon_partially_mapped_attr.attr,
>  	&collapse_exceed_swap_pte_attr.attr,
> @@ -4703,6 +4705,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,
>  					    deferred_split_isolate, &dispose);
>  
>  	list_for_each_entry_safe(folio, next, &dispose, _deferred_list) {
> +		const unsigned int order = folio_order(folio);
>  		bool did_split = false;
>  		bool underused = false;
>  
> @@ -4724,8 +4727,11 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,
>  			goto requeue;
>  		if (!split_folio(folio)) {
>  			did_split = true;
> -			if (underused)
> -				count_vm_event(THP_UNDERUSED_SPLIT_PAGE);
> +			if (underused) {
> +				if (is_pmd_order(order))
> +					count_vm_event(THP_UNDERUSED_SPLIT_PAGE);
> +				count_mthp_stat(order, MTHP_STAT_SPLIT_UNDERUSED);
> +			}
>  			split++;
>  		}
>  		folio_unlock(folio);



  reply	other threads:[~2026-11-03 22:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 21:20 [PATCH v4 0/4] mm: split underused anonymous mTHP folios Joanne Koong
2026-11-03 21:20 ` [PATCH v4 1/4] mm/huge_memory: scale thp_underused() to the folio size Joanne Koong
2026-11-05 12:20   ` Kiryl Shutsemau
2026-11-10  3:54   ` Zi Yan
2026-11-12 23:50     ` Joanne Koong
2026-11-10  8:00   ` Baolin Wang
2026-11-03 21:20 ` [PATCH v4 2/4] mm/huge_memory: don't queue folios when underused splitting is inactive Joanne Koong
2026-11-03 22:15   ` Usama Arif
2026-11-05 12:23   ` Kiryl Shutsemau
2026-11-10  8:13   ` Baolin Wang
2026-11-03 21:20 ` [PATCH v4 3/4] mm/huge_memory: add a per-order counter for underused splits Joanne Koong
2026-11-03 22:20   ` Usama Arif [this message]
2026-11-05 12:26     ` Kiryl Shutsemau
2026-11-06  0:06       ` Joanne Koong
2026-11-10  8:10   ` Baolin Wang
2026-11-03 21:20 ` [PATCH v4 4/4] mm: add anonymous mTHP folios to the deferred split list Joanne Koong
2026-11-03 22:20   ` Barry Song
2026-11-04 21:21   ` sashiko-bot
2026-11-04 23:50     ` Joanne Koong
2026-11-05 12:37       ` Kiryl Shutsemau
2026-11-06  0:05         ` Joanne Koong
2026-11-09 22:29           ` Joanne Koong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a16f1f8e-d3b6-4145-890b-51ce3c0a7f03@linux.dev \
    --to=usama.arif@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=joannelkoong@gmail.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=npache@redhat.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.