Skip to content

Fix invalid THP kernel param in optimize_kernel (#176)#177

Draft
VijitSingh97 wants to merge 2 commits into
mainfrom
claude/priceless-cerf-0b37f6
Draft

Fix invalid THP kernel param in optimize_kernel (#176)#177
VijitSingh97 wants to merge 2 commits into
mainfrom
claude/priceless-cerf-0b37f6

Conversation

@VijitSingh97

@VijitSingh97 VijitSingh97 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

⛔ Merge order: goes after #114

Draft on purpose. This touches GRUB / kernel boot params, so it should be validated against the real-server end-to-end test harness in #114 before merging. Hold until #114 testing is done.

Fixes #176.

Problem

optimize_kernel appended transparent_hugepages=never (plural) to GRUB_CMDLINE_LINUX_DEFAULT. The real Linux kernel parameter is singulartransparent_hugepage=never. The plural form is an unrecognized param the kernel silently ignores, so disabling Transparent HugePages for RandomX never took effect even after the GRUB edit + reboot:

$ cat /sys/kernel/mm/transparent_hugepage/enabled
always [madvise] never     # distro default — NOT [never]

No error, no warning, and doctor doesn't check THP state — so it failed silently.

The explicit HugePages reservation (hugepagesz=2M hugepages=3072) was already correct and is unchanged — only the THP-disable was broken.

Fix

  • Extract the boot params into a single randomx_boot_params helper (one source of truth, unit-testable) with the corrected singular param; optimize_kernel's edit now consumes it.
  • Self-heal already-broken installs. A box that ran the buggy version has the plural token and hugepages= in GRUB, so the reservation guard (grep -q "hugepages=") would report "already configured" and skip — leaving the dead plural token in place forever. heal_grub_thp_typo rewrites it to the singular form (idempotent: a no-op once corrected) and re-runs update-grub.
  • Stop silently no-op'ing the insert. The edit only handles the standard double-quoted GRUB_CMDLINE_LINUX_DEFAULT="..." line; previously a single-quoted / commented / absent line meant nothing changed yet update-grub still ran and a reboot was flagged. append_grub_boot_params now anchors to the active (non-comment) line, returns non-zero when there's nothing to edit, and the caller prints manual instructions instead of claiming success. The ^-anchor also stops a commented-out example line from being edited.
  • Add sudo_sed (safe_sed's GNU/BSD -i split, with sudo) so the helpers are portable across the Linux target and a macOS dev box.

Confirmed on a live box: with the singular form + update-grub + reboot, /sys/kernel/mm/transparent_hugepage/enabled reads [never].

Test

bash tests/stack/run.sh125 passed, 0 failed. New assertions:

  • unit: randomx_boot_params — generated cmdline reserves HugePages and uses the singular THP param; explicitly fails on the plural typo so it can't regress.
  • unit: grub heal + boot-param insert — exercises the real heal/insert transforms via a passthrough-sudo stub against sandbox grub files: heal rewrites plural→singular and is an idempotent no-op once corrected; insert appends to the active line while preserving existing params; a commented-out line is left untouched and reported (no silent reboot).

shellcheck -S warning pithead tests/stack/run.sh → clean.

🤖 Generated with Claude Code

VijitSingh97 and others added 2 commits June 8, 2026 02:02
optimize_kernel wrote `transparent_hugepages=never` (plural) into
GRUB_CMDLINE_LINUX_DEFAULT. The real kernel parameter is singular
(`transparent_hugepage=never`); the plural form is unrecognized and
silently ignored, so disabling Transparent HugePages for RandomX never
took effect even after the GRUB edit + reboot — /sys/kernel/mm/
transparent_hugepage/enabled stayed at the distro default.

Extract the boot params into a single `randomx_boot_params` helper (one
source of truth, unit-testable) with the corrected singular param, and
add a unit test that guards against the plural typo regressing.

The explicit HugePages reservation (hugepages=3072) was already correct
and is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…UB edit (#176)

Two related robustness fixes flagged while reviewing optimize_kernel for
idempotency:

1. Self-heal already-broken installs. A box that ran the buggy version has
   the plural transparent_hugepages= AND hugepages= in GRUB, so the
   reservation guard (grep -q "hugepages=") would report "already
   configured" and skip — leaving the dead plural token in place forever.
   heal_grub_thp_typo() rewrites it to the singular form (idempotent: a
   no-op once corrected) and re-runs update-grub.

2. Stop silently no-op'ing the insert. The sed only handles the standard
   double-quoted GRUB_CMDLINE_LINUX_DEFAULT="..." line; previously a
   single-quoted/commented/absent line meant the sed changed nothing yet
   update-grub still ran and a reboot was flagged. append_grub_boot_params()
   now anchors to the active (non-comment) line, returns non-zero when
   there's nothing to edit, and the caller prints manual instructions
   instead of claiming success. The ^-anchor also stops a commented-out
   example line from being edited.

Adds sudo_sed (safe_sed's GNU/BSD -i split, with sudo) so the helpers are
portable, and unit tests that exercise the real heal/insert transforms via
a passthrough-sudo stub against sandbox grub files. 125 passed, 0 failed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

optimize_kernel writes an invalid THP kernel param (transparent_hugepages, plural) — THP-disable silently never takes effect

1 participant