linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Nico Pache <npache@redhat.com>
Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	 rientjes@google.com, hannes@cmpxchg.org,
	lorenzo.stoakes@oracle.com,  rdunlap@infradead.org,
	mhocko@suse.com, Liam.Howlett@oracle.com,  zokeefe@google.com,
	surenb@google.com, jglisse@google.com, cl@gentwo.org,
	 jack@suse.cz, dave.hansen@linux.intel.com, will@kernel.org,
	tiwai@suse.de,  catalin.marinas@arm.com,
	anshuman.khandual@arm.com, dev.jain@arm.com,  raquini@redhat.com,
	aarcange@redhat.com, kirill.shutemov@linux.intel.com,
	 yang@os.amperecomputing.com, thomas.hellstrom@linux.intel.com,
	 vishal.moola@gmail.com, sunnanyong@huawei.com,
	usamaarif642@gmail.com,  wangkefeng.wang@huawei.com,
	ziy@nvidia.com, shuah@kernel.org,  peterx@redhat.com,
	willy@infradead.org, ryan.roberts@arm.com,
	 baolin.wang@linux.alibaba.com, baohua@kernel.org,
	david@redhat.com,  mathieu.desnoyers@efficios.com,
	mhiramat@kernel.org, rostedt@goodmis.org,  corbet@lwn.net,
	akpm@linux-foundation.org
Subject: Re: [PATCH v6 0/4] mm: introduce THP deferred setting
Date: Wed, 21 May 2025 19:35:35 +0800	[thread overview]
Message-ID: <CALOAHbATH4+y71TfVOaGU9NV5coy9XnLfDD1pDBfniv=T-cyqw@mail.gmail.com> (raw)
In-Reply-To: <CAA1CXcA0WX+qGKvL4VcTM_bazFxRyDmp5DK60ycoS4OCDUnH-Q@mail.gmail.com>

On Wed, May 21, 2025 at 6:19 PM Nico Pache <npache@redhat.com> wrote:
>
> On Tue, May 20, 2025 at 3:25 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > On Thu, May 15, 2025 at 11:41 AM Nico Pache <npache@redhat.com> wrote:
> > >
> > > This series is a follow-up to [1], which adds mTHP support to khugepaged.
> > > mTHP khugepaged support is a "loose" dependency for the sysfs/sysctl
> > > configs to make sense. Without it global="defer" and  mTHP="inherit" case
> > > is "undefined" behavior.
> > >
> > > We've seen cases were customers switching from RHEL7 to RHEL8 see a
> > > significant increase in the memory footprint for the same workloads.
> > >
> > > Through our investigations we found that a large contributing factor to
> > > the increase in RSS was an increase in THP usage.
> > >
> > > For workloads like MySQL, or when using allocators like jemalloc, it is
> > > often recommended to set /transparent_hugepages/enabled=never. This is
> > > in part due to performance degradations and increased memory waste.
> > >
> > > This series introduces enabled=defer, this setting acts as a middle
> > > ground between always and madvise. If the mapping is MADV_HUGEPAGE, the
> > > page fault handler will act normally, making a hugepage if possible. If
> > > the allocation is not MADV_HUGEPAGE, then the page fault handler will
> > > default to the base size allocation. The caveat is that khugepaged can
> > > still operate on pages that are not MADV_HUGEPAGE.
> > >
> > > This allows for three things... one, applications specifically designed to
> > > use hugepages will get them, and two, applications that don't use
> > > hugepages can still benefit from them without aggressively inserting
> > > THPs at every possible chance. This curbs the memory waste, and defers
> > > the use of hugepages to khugepaged. Khugepaged can then scan the memory
> > > for eligible collapsing. Lastly there is the added benefit for those who
> > > want THPs but experience higher latency PFs. Now you can get base page
> > > performance at the PF handler and Hugepage performance for those mappings
> > > after they collapse.
> > >
> > > Admins may want to lower max_ptes_none, if not, khugepaged may
> > > aggressively collapse single allocations into hugepages.
> > >
> > > TESTING:
> > > - Built for x86_64, aarch64, ppc64le, and s390x
> > > - selftests mm
> > > - In [1] I provided a script [2] that has multiple access patterns
> > > - lots of general use.
> > > - redis testing. This test was my original case for the defer mode. What I
> > >    was able to prove was that THP=always leads to increased max_latency
> > >    cases; hence why it is recommended to disable THPs for redis servers.
> > >    However with 'defer' we dont have the max_latency spikes and can still
> > >    get the system to utilize THPs. I further tested this with the mTHP
> > >    defer setting and found that redis (and probably other jmalloc users)
> > >    can utilize THPs via defer (+mTHP defer) without a large latency
> > >    penalty and some potential gains. I uploaded some mmtest results
> > >    here[3] which compares:
> > >        stock+thp=never
> > >        stock+(m)thp=always
> > >        khugepaged-mthp + defer (max_ptes_none=64)
> > >
> > >   The results show that (m)THPs can cause some throughput regression in
> > >   some cases, but also has gains in other cases. The mTHP+defer results
> > >   have more gains and less losses over the (m)THP=always case.
> > >
> > > V6 Changes:
> > > - nits
> > > - rebased dependent series and added review tags
> > >
> > > V5 Changes:
> > > - rebased dependent series
> > > - added reviewed-by tag on 2/4
> > >
> > > V4 Changes:
> > > - Minor Documentation fixes
> > > - rebased the dependent series [1] onto mm-unstable
> > >     commit 0e68b850b1d3 ("vmalloc: use atomic_long_add_return_relaxed()")
> > >
> > > V3 Changes:
> > > - Combined the documentation commits into one, and moved a section to the
> > >   khugepaged mthp patchset
> > >
> > > V2 Changes:
> > > - base changes on mTHP khugepaged support
> > > - Fix selftests parsing issue
> > > - add mTHP defer option
> > > - add mTHP defer Documentation
> > >
> > > [1] - https://lore.kernel.org/all/20250515032226.128900-1-npache@redhat.com/
> > > [2] - https://gitlab.com/npache/khugepaged_mthp_test
> > > [3] - https://people.redhat.com/npache/mthp_khugepaged_defer/testoutput2/output.html
> > >
> > > Nico Pache (4):
> > >   mm: defer THP insertion to khugepaged
> > >   mm: document (m)THP defer usage
> > >   khugepaged: add defer option to mTHP options
> > >   selftests: mm: add defer to thp setting parser
> > >
> > >  Documentation/admin-guide/mm/transhuge.rst | 31 +++++++---
> > >  include/linux/huge_mm.h                    | 18 +++++-
> > >  mm/huge_memory.c                           | 69 +++++++++++++++++++---
> > >  mm/khugepaged.c                            |  8 +--
> > >  tools/testing/selftests/mm/thp_settings.c  |  1 +
> > >  tools/testing/selftests/mm/thp_settings.h  |  1 +
> > >  6 files changed, 106 insertions(+), 22 deletions(-)
> > >
> > > --
> > > 2.49.0
> > >
> > >
> >
> > Hello Nico,
> >
> > Upon reviewing the series, it occurred to me that BPF could solve this
> > more cleanly. Adding a 'tva_flags' parameter to the BPF hook would
> > handle this case and future scenarios without requiring new modes. The
> > BPF mode could then serve as a unified solution.
> Hi Yafang,
>
> I dont see how this is the case? This would require users to
> modify/add functionality rather than configuring the system in this
> manner. What if BPF is not configured or being used? Having to use an
> additional technology that requires precise configuration doesn't seem
> cleaner.

The core challenge remains: while certain tasks benefit from this new
mode, others see no improvement—or may even regress.
For that reason, implementing it globally seems unwise—per-task
control would be far more effective.

-- 
Regards
Yafang

  reply	other threads:[~2025-05-21 11:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15  3:38 [PATCH v6 0/4] mm: introduce THP deferred setting Nico Pache
2025-05-15  3:38 ` [PATCH v6 1/4] mm: defer THP insertion to khugepaged Nico Pache
2025-05-20  7:43   ` Yafang Shao
2025-06-14 11:25   ` Klara Modin
2025-06-17 17:52     ` Nico Pache
2025-05-15  3:38 ` [PATCH v6 2/4] mm: document (m)THP defer usage Nico Pache
2025-05-15  3:38 ` [PATCH v6 3/4] khugepaged: add defer option to mTHP options Nico Pache
2025-05-15  3:38 ` [PATCH v6 4/4] selftests: mm: add defer to thp setting parser Nico Pache
2025-05-20  9:24 ` [PATCH v6 0/4] mm: introduce THP deferred setting Yafang Shao
2025-05-21 10:19   ` Nico Pache
2025-05-21 11:35     ` Yafang Shao [this message]
2025-05-20  9:42 ` Lorenzo Stoakes
2025-05-21 10:41   ` Nico Pache
2025-05-21 11:24     ` Lorenzo Stoakes
2025-05-21 11:46       ` David Hildenbrand
2025-05-21 12:00         ` Lorenzo Stoakes
2025-05-21 12:24           ` David Hildenbrand
2025-05-21 12:33             ` Lorenzo Stoakes
2025-05-21 12:40               ` David Hildenbrand
2025-05-29  4:26       ` 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='CALOAHbATH4+y71TfVOaGU9NV5coy9XnLfDD1pDBfniv=T-cyqw@mail.gmail.com' \
    --to=laoar.shao@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@gentwo.org \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=jack@suse.cz \
    --cc=jglisse@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@suse.com \
    --cc=npache@redhat.com \
    --cc=peterx@redhat.com \
    --cc=raquini@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=ryan.roberts@arm.com \
    --cc=shuah@kernel.org \
    --cc=sunnanyong@huawei.com \
    --cc=surenb@google.com \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tiwai@suse.de \
    --cc=usamaarif642@gmail.com \
    --cc=vishal.moola@gmail.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    --cc=yang@os.amperecomputing.com \
    --cc=ziy@nvidia.com \
    --cc=zokeefe@google.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;
as well as URLs for NNTP newsgroup(s).