Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Usama Arif <usama.arif@linux.dev>
To: Zi Yan <ziy@nvidia.com>
Cc: Usama Arif <usama.arif@linux.dev>,
	xu.xin16@zte.com.cn, npache@redhat.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	usamaarif642@gmail.com, yuzhao@google.com, aarcange@redhat.com,
	akpm@linux-foundation.org, david@kernel.org,
	chengming.zhou@linux.dev, ljs@kernel.org,
	baolin.wang@linux.alibaba.com, liam@infradead.org,
	ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org,
	lance.yang@linux.dev, matthew.brost@intel.com,
	joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com,
	gourry@gourry.net, ying.huang@linux.alibaba.com,
	apopple@nvidia.com
Subject: Re: [PATCH mm-unstable v1 2/3] mm/migrate.c: Prevent folio splitting from interacting with KSM
Date: Tue,  9 Jun 2026 10:27:15 -0700	[thread overview]
Message-ID: <20260609172719.803537-1-usama.arif@linux.dev> (raw)
In-Reply-To: <18102ABA-0D8E-4DA0-AC30-544E34E445D5@nvidia.com>

On Tue, 09 Jun 2026 10:07:20 -0400 Zi Yan <ziy@nvidia.com> wrote:

> On 9 Jun 2026, at 9:47, xu.xin16@zte.com.cn wrote:
> 
> >>>> Since commit b1f202060afe ("mm: remap unused subpages to shared zeropage
> >>>> when splitting isolated thp"), splitting an anonymous THP remaps all
> >>>> zero-filled subpages to the shared zeropage via TTU_USE_SHARED_ZEROPAGE.
> >>>> This flag is set unconditionally for every anonymous folio split,
> >>>> including splits triggered by KSM.
> >>>>
> >>>> When KSM is enabled with THP=always, this causes two regressions:
> >>>>
> >>>> 1. use_zero_pages=1: KSM calls try_to_merge_one_page() which triggers
> >>>>   split_huge_page(). The split remaps all 512 zero-filled subpages to
> >>>>   the shared zeropage at once, freeing the entire 2MB THP when KSM only
> >>>>   intended to process a single 4KB page. This bypasses KSM's
> >>>>   pages_to_scan rate limiting, causing ~1GB to be freed almost
> >>>>   instantly.
> >>>>
> >>>
> >>> Why do you see it as regressions?
> >>
> >> Since the zero-page remapping was introduced our test has shown the
> >> following behavior changes:
> >>
> >> With use_zero_pages=0, the merge rate drops from 60MB/s to ~6 MB/s
> >> even after raising pages_to_scan. The KSM merging is now much slower
> >> and CPU utilization has increased.
> >>
> >> With use_zero_pages=1, ~1 GB is freed almost instantly, and it no
> >> longer respects the pages_to_scan behavior.
> >>
> >> Even with just this patch (1 & 2) or the RFC linked in the cover
> >> letter, the issue no longer occurs.
> >
> > Understood. You're saying that the additional processing action in split_huge_page
> > (remap unused subpages to shared zeropage) increases the scanning cost of ksmd.
> >
> > However, I still wouldn't simply classify this as a performance regression,
> > because commit b1f202060afe increases memory savings through this action — so
> > it saves memory at the cost of additional CPU overhead.
> >
> > If you want to address the increased overhead on ksmd, I think we could add a
> > check for the shared zeropage in cmp_and_merge_page, and skip merging when a
> > shared zeropage is detected.
> >
> >>>
> >>> AFAIU, KSM and THP do often conflict with each other. THP tries hard to collapse
> >>> a huge page (which may contain many zero pages). If KSM is enabled and part of
> >>> that huge page is mergeable, it can easily be split by KSM, rendering THP's
> >>> efforts futile.
> >>>
> >>> Therefore, in our actual production environment, we typically avoid making the
> >>> same region both KSM mergeable and THP always.
> >>
> >> THP=always is a global setting used in many production environments,
> >> so these features now interact very poorly together.
> >>
> >
> > Actually, I have long thought about submitting a patch: add a new interface
> > 'skip_huge_page' under KSM's sysfs, allowing users to choose not to split huge pages.
> 
> Just think out loud. Or just skip huge pages all the time unless memory pressure
> is present. Basically treat KSM as a way of reducing memory pressure by merging
> pages.

I do agree with this. I questioned about if it even makes sense to split THP
with KSM in RFC (https://lore.kernel.org/all/20260510114001.600681-1-usama.arif@linux.dev/)


> 
> Best Regards,
> Yan, Zi
> 


  reply	other threads:[~2026-06-09 17:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 11:46 [PATCH mm-unstable v1 0/3] MM: Tighten control over zero-page remapping Nico Pache
2026-06-09 11:46 ` [PATCH mm-unstable v1 1/3] mm/ksm: export ksm_is_running() to check KSM merge state Nico Pache
2026-06-09 14:13   ` Lorenzo Stoakes
2026-06-09 11:46 ` [PATCH mm-unstable v1 2/3] mm/migrate.c: Prevent folio splitting from interacting with KSM Nico Pache
2026-06-09 12:12   ` xu.xin16
2026-06-09 12:57     ` Nico Pache
2026-06-09 12:59       ` David Hildenbrand (Arm)
2026-06-09 13:47       ` xu.xin16
2026-06-09 14:07         ` Zi Yan
2026-06-09 17:27           ` Usama Arif [this message]
2026-06-09 13:06     ` Lance Yang
2026-06-09 13:42       ` Nico Pache
2026-06-09 13:49         ` xu.xin16
2026-06-09 14:14           ` Lorenzo Stoakes
2026-06-09 14:26   ` Lorenzo Stoakes
2026-06-09 11:46 ` [PATCH mm-unstable v1 3/3] mm/huge_memory.c: Skip zero-page remapping when underused THP shrinker is disabled Nico Pache

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=20260609172719.803537-1-usama.arif@linux.dev \
    --to=usama.arif@linux.dev \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=byungchul@sk.com \
    --cc=chengming.zhou@linux.dev \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=gourry@gourry.net \
    --cc=joshua.hahnjy@gmail.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=npache@redhat.com \
    --cc=rakie.kim@sk.com \
    --cc=ryan.roberts@arm.com \
    --cc=usamaarif642@gmail.com \
    --cc=xu.xin16@zte.com.cn \
    --cc=ying.huang@linux.alibaba.com \
    --cc=yuzhao@google.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox