Skip to content

[kconfig]: Set THP default to madvise instead of always#573

Merged
saiarcot895 merged 1 commit into
sonic-net:masterfrom
prabhataravind:paravind/disable_thp
May 13, 2026
Merged

[kconfig]: Set THP default to madvise instead of always#573
saiarcot895 merged 1 commit into
sonic-net:masterfrom
prabhataravind:paravind/disable_thp

Conversation

@prabhataravind
Copy link
Copy Markdown
Contributor

@prabhataravind prabhataravind commented May 11, 2026

What I did

Set the kernel compile-time default for Transparent Huge Pages (THP) from always to madvise by adding CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y in config.local/featureset-sonic/config

Why I did it

With CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y, khugepaged continuously promotes 4KB pages to 2MB huge pages in the background. On memory-constrained network switches this has several negative effects:

  • Memory fragmentation: Once promoted, huge pages cannot be partially reclaimed. Even when applications free most of their memory, scattered live objects pin entire 2MB pages, preventing the kernel from reclaiming unused memory.
  • Allocator inefficiency: Userspace allocators (e.g., jemalloc) use MADV_DONTNEED to return memory to the kernel, but this is ineffective on sub-ranges of huge pages, causing a persistent gap between application-level and kernel-level memory accounting.
  • Process exit latency: Tearing down large THP-backed address spaces under memory pressure can cause threads to block in do_exit(), triggering hung task watchdog timeouts.

Setting the default to madvise ensures THP is only used when applications explicitly opt in via madvise(MADV_HUGEPAGE). This is the recommended setting for latency-sensitive and embedded networking workloads (consistent with guidance by other linux distributions for similar environments).

How I verified it

  • Built the kernel with updated kconfig and booted on a SONiC switch
  • Confirmed: cat /sys/kernel/mm/transparent_hugepage/enabled is set as follows:
    always [madvise] never

Details if related

@prabhataravind
Copy link
Copy Markdown
Contributor Author

/azp run Azure.sonic-linux-kernel

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Prabhat Aravind <paravind@microsoft.com>
@prabhataravind prabhataravind force-pushed the paravind/disable_thp branch from 7fb8a2c to 2fe657b Compare May 12, 2026 21:15
@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@prabhataravind prabhataravind marked this pull request as ready for review May 12, 2026 23:01
@prabhataravind prabhataravind requested a review from a team as a code owner May 12, 2026 23:01
Copilot AI review requested due to automatic review settings May 12, 2026 23:01
@saiarcot895
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates SONiC’s kernel config fragment to change the compile-time default mode for Transparent Huge Pages (THP) from always to madvise, so THP is only used when applications explicitly opt in via madvise(MADV_HUGEPAGE).

Changes:

  • Add CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y to the SONiC featureset config fragment.
  • Document the intent inline with a short comment.

@prabhataravind
Copy link
Copy Markdown
Contributor Author

@prsunny for viz

Copy link
Copy Markdown

@prsunny prsunny left a comment

Choose a reason for hiding this comment

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

lgtm, @saiarcot895 , review/signoff

@saiarcot895 saiarcot895 merged commit a7f3afe into sonic-net:master May 13, 2026
12 checks passed
@prabhataravind prabhataravind deleted the paravind/disable_thp branch May 13, 2026 22:01
@paulmenzel
Copy link
Copy Markdown
Contributor

This is the recommended setting for latency-sensitive and embedded networking workloads (consistent with guidance by other linux distributions for similar environments).

Could you please elaborate, and add references?

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.

6 participants