Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] mm/thp: add CONFIG_TRANSPARENT_HUGEPAGE_NEVER option - #2029

Merged
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-30-thp
Jul 30, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] mm/thp: add CONFIG_TRANSPARENT_HUGEPAGE_NEVER option#2029
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-30-thp

Conversation

@opsiff

@opsiff opsiff commented Jul 30, 2026

Copy link
Copy Markdown
Member

mainline inclusion
from mainline-v6.8-rc1
category: performance

Currently enabling THP support (CONFIG_TRANSPARENT_HUGEPAGE) requires enabling either CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS or CONFIG_TRANSPARENT_HUGEPAGE_MADVISE, which both cause khugepaged starting by default at kernel bootup. Add the third choice CONFIG_TRANSPARENT_HUGEPAGE_NEVER, in line with the existing kernel command line setting transparent_hugepage=never, to disable THP by default (in particular, to prevent starting khugepaged by default) but still allow enabling it at runtime via sysfs.

Rationale: khugepaged has its own non-negligible memory cost even if it is not used by any applications, since it bumps up vm.min_free_kbytes to its own required minimum in set_recommended_min_free_kbytes(). For example, on a machine with 4GB RAM, with 3 mm zones and pageblock_order == MAX_ORDER, starting khugepaged causes vm.min_free_kbytes increase from 8MB to 132MB.

So if we use THP on machines with e.g. >=8GB of memory for better performance, but avoid using it on lower-memory machines to avoid its memory overhead, then for the same reason we also want to avoid even starting khugepaged on those <8GB machines. So with CONFIG_TRANSPARENT_HUGEPAGE_NEVER we can use the same kernel image on both

=8GB and <8GB machines, with THP support enabled but khugepaged not
started by default. The userspace can then decide to enable THP via sysfs if needed, based on the total amount of memory.

This could also be achieved with the existing transparent_hugepage=never setting in the kernel command line instead. But it seems cleaner to avoid tweaking the command line for such a basic setting.

P.S. I see that CONFIG_TRANSPARENT_HUGEPAGE_NEVER was already proposed in the past [1] but without an explanation of the purpose.

[1] https://lore.kernel.org/all/202211301651462590168@zte.com.cn/

Link: https://lkml.kernel.org/r/20231205170244.2746210-1-dmaluka@chromium.org
Link: https://lore.kernel.org/all/20231204163254.2636289-1-dmaluka@chromium.org/

(cherry picked from commit 683ec99)

Summary by Sourcery

Introduce a Kconfig option to support disabling transparent huge pages by default while keeping runtime enablement via sysfs.

New Features:

  • Add CONFIG_TRANSPARENT_HUGEPAGE_NEVER to allow kernels to include THP support without starting khugepaged by default on boot.

Enhancements:

  • Align THP configuration behavior with the existing transparent_hugepage=never kernel command-line option to simplify deployment across machines with differing memory sizes.

mainline inclusion
from mainline-v6.8-rc1
category: performance

Currently enabling THP support (CONFIG_TRANSPARENT_HUGEPAGE) requires
enabling either CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS or
CONFIG_TRANSPARENT_HUGEPAGE_MADVISE, which both cause khugepaged starting
by default at kernel bootup.  Add the third choice
CONFIG_TRANSPARENT_HUGEPAGE_NEVER, in line with the existing kernel
command line setting transparent_hugepage=never, to disable THP by default
(in particular, to prevent starting khugepaged by default) but still allow
enabling it at runtime via sysfs.

Rationale: khugepaged has its own non-negligible memory cost even if it is
not used by any applications, since it bumps up vm.min_free_kbytes to its
own required minimum in set_recommended_min_free_kbytes().  For example,
on a machine with 4GB RAM, with 3 mm zones and pageblock_order ==
MAX_ORDER, starting khugepaged causes vm.min_free_kbytes increase from 8MB
to 132MB.

So if we use THP on machines with e.g.  >=8GB of memory for better
performance, but avoid using it on lower-memory machines to avoid its
memory overhead, then for the same reason we also want to avoid even
starting khugepaged on those <8GB machines.  So with
CONFIG_TRANSPARENT_HUGEPAGE_NEVER we can use the same kernel image on both
>=8GB and <8GB machines, with THP support enabled but khugepaged not
started by default.  The userspace can then decide to enable THP via sysfs
if needed, based on the total amount of memory.

This could also be achieved with the existing transparent_hugepage=never
setting in the kernel command line instead.  But it seems cleaner to avoid
tweaking the command line for such a basic setting.

P.S. I see that CONFIG_TRANSPARENT_HUGEPAGE_NEVER was already proposed
in the past [1] but without an explanation of the purpose.

[1] https://lore.kernel.org/all/202211301651462590168@zte.com.cn/

Link: https://lkml.kernel.org/r/20231205170244.2746210-1-dmaluka@chromium.org
Link: https://lore.kernel.org/all/20231204163254.2636289-1-dmaluka@chromium.org/
Signed-off-by: Dmytro Maluka <dmaluka@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 683ec99)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new Kconfig option CONFIG_TRANSPARENT_HUGEPAGE_NEVER to support building THP into the kernel while keeping it disabled by default (no khugepaged at boot), with runtime enablement via sysfs aligned with the transparent_hugepage=never command-line behavior.

File-Level Changes

Change Details Files
Introduce a new Kconfig choice to allow transparent hugepage support to be built in but disabled by default, preventing khugepaged from starting automatically while still permitting runtime activation via sysfs.
  • Extend the transparent hugepage Kconfig choice to include a NEVER option alongside ALWAYS and MADVISE.
  • Wire the new NEVER option into the THP configuration logic so that enabling CONFIG_TRANSPARENT_HUGEPAGE_NEVER keeps THP off by default and avoids starting khugepaged at boot.
  • Ensure behavior of the NEVER option is consistent with the transparent_hugepage=never kernel command-line setting, including interactions with vm.min_free_kbytes adjustments.
mm/Kconfig

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dongert
dongert requested a review from Copilot July 30, 2026 13:57
@Avenger-285714

Copy link
Copy Markdown
Member

no dependency?

@opsiff
opsiff merged commit 53d1699 into deepin-community:linux-6.6.y Jul 30, 2026
13 checks passed
@opsiff

opsiff commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

no dependency?

no dependency?

same as transparent_hugepage=never, just provide a kconfig .

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a third Kconfig choice for Transparent Hugepage (THP) sysfs default behavior, allowing kernels to include THP support while defaulting to “never” (i.e., not enabling THP by default), matching the existing transparent_hugepage=never cmdline behavior but via config.

Changes:

  • Add CONFIG_TRANSPARENT_HUGEPAGE_NEVER as a new option under “Transparent Hugepage Support sysfs defaults”.
  • Extend the existing THP default selection choice from 2 options (always/madvise) to 3 options (always/madvise/never).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants