Skip to content

feat(memory): apply kernel memory tunables before memory-mode runs - #507

Draft
not-matthias wants to merge 3 commits into
mainfrom
cod-3300-kernel-memory-tunables
Draft

feat(memory): apply kernel memory tunables before memory-mode runs#507
not-matthias wants to merge 3 commits into
mainfrom
cod-3300-kernel-memory-tunables

Conversation

@not-matthias

Copy link
Copy Markdown
Member

Benchmark repos running codspeed --mode memory currently need a hand-written CI step to stabilise kernel memory behaviour before measuring: disable THP, zero vm.compaction_proactiveness / vm.swappiness / kernel.numa_balancing, swapoff -a, and drop the page cache before each suite.

The runner now does this itself at the start of every memory-mode execution.

Behaviour

  • New flag --memory-tunables auto|on|off (env CODSPEED_MEMORY_TUNABLES), default auto = apply only when a CI run environment is detected, so developer machines are not silently mutated.
  • Best effort: a knob that cannot be applied is a warning, never fatal. Skipped entirely when privileges cannot be elevated without a password prompt.
  • Knobs are not reverted afterwards.
  • swapoff -a is guarded: skipped on zram devices (it permanently resets their disksize) and whenever the swapped pages would not fit in MemAvailable.
  • Applied in run() rather than setup(), so the page cache is dropped before every suite and --skip-setup does not bypass it. The sysctl/THP writes are no-ops on later suites since ensure_sysctl compares before writing.

Commits

  1. refactor(executor): move linux_sysctl into executor helpers — pure move, the sysctl primitive is no longer walltime-specific.
  2. feat(cli): add --memory-tunables flag
  3. feat(memory): apply kernel memory tunables before memory-mode runs

Verification

  • cargo clippy --all-targets clean, cargo test --release (pre-existing failures on this host are the sudo-requiring tests, identical on main).
  • Local non-CI run logs Not running in CI, skipping kernel memory tunables; host THP unchanged.
  • Privileged container with --memory-tunables=on: THP enabled/defrag become [never], vm.compaction_proactiveness = 0, vm.swappiness = 0, and the swap guard correctly logged Leaving swap enabled: swapped pages do not fit in available memory.

The sysctl read-then-write-with-sudo primitive is not walltime-specific;
memory mode needs it too.
Tri-state (auto|on|off, CODSPEED_MEMORY_TUNABLES) controlling whether the
runner stabilises kernel memory behaviour before memory-mode runs.
Disables transparent huge pages, sets vm.compaction_proactiveness,
vm.swappiness and kernel.numa_balancing to 0, disables swap and drops the
page cache, so benchmark repos no longer need a hand-written CI step.

Applied only in CI by default, best-effort: a knob that cannot be set is a
warning. swapoff is skipped on zram devices and whenever the swapped pages
would not fit in available memory.
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.

1 participant