feat(memory): apply kernel memory tunables before memory-mode runs - #507
feat(memory): apply kernel memory tunables before memory-mode runs#507not-matthias wants to merge 3 commits into
Conversation
Merging this PR will not alter performance
|
febfce2 to
a219b76
Compare
a219b76 to
3568cec
Compare
Greptile SummaryThe PR applies and restores Linux kernel memory tunables around memory-mode benchmark runs and centralizes reusable sysctl guards for profiling. The current restoration path does not preserve swap priorities, while privileged local runs remain able to mutate host memory state.
Confidence Score: 3/5The PR is not yet safe to merge because privileged local runs mutate host memory state and swap restoration changes non-default priorities. Memory tuning is reached locally whenever root or passwordless sudo is available, including an irreversible page-cache drop, and restored swap areas lose their configured priority because only their paths are recorded. Files Needing Attention: src/executor/memory/tunables.rs and src/executor/memory/executor.rs
|
| Filename | Overview |
|---|---|
| src/executor/memory/tunables.rs | Adds host memory tuning and restoration, but swap restoration loses each area's original priority and the existing local-run admission defect remains. |
| src/executor/memory/executor.rs | Applies the tuning guard for every memory execution, including privileged local runs. |
| src/executor/helpers/linux_sysctl.rs | Centralizes sysctl mutation behind a guard that restores changed values on drop. |
| src/executor/wall_time/executor.rs | Retains profiling sysctl guards on the executor so prior values survive setup and are restored when the executor is dropped. |
Sequence Diagram
sequenceDiagram
participant E as MemoryExecutor
participant T as MemoryTunables
participant K as Linux kernel
participant B as Benchmark
E->>T: apply()
T->>K: Set THP and disable eligible swap
T->>K: Drop page cache
E->>B: Run memory benchmark
B-->>E: Exit
E->>T: Drop guard
T->>K: swapon(path)
Note over T,K: Original swap priority is not restored
T->>K: Restore THP mode
Reviews (3): Last reviewed commit: "fix(walltime): restore profiling sysctls" | Re-trigger Greptile
755df11 to
8bfb28b
Compare
The sysctl read-then-write-with-sudo primitive is not walltime-specific; memory mode needs it too.
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, 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.
77ad6fc to
87a02e9
Compare
art049
left a comment
There was a problem hiding this comment.
I know it was the case before but it hurts readability a bit
There was a problem hiding this comment.
Is it possible to gate this whole mod behind the feature flag but not every single line, because now we end up gating almost every single line with #[cfg(target_os = "linux")] 😅
dcd2e8f to
758c564
Compare
|
@greptileai review again |
Keep the original profiler sysctl values in the walltime executor and restore them when it is dropped. This prevents a local or containerized run from leaving host-global profiling access enabled.
758c564 to
fc2fe71
Compare
Benchmark repos running
codspeed --mode memorycurrently need a hand-written CI step to stabilise kernel memory behaviour before measuring: disable THP, zerovm.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
MemoryTunables::apply()returns a guard holding the previous value of every knob it changed, and restores it on drop — including on the error paths, whereteardown()never runs. Only knobs that were not already at the target are captured, and THP is restored to the exact mode it held (madvisestaysmadvise).swapoff -ais guarded: skipped on zram devices (it permanently resets theirdisksize) and whenever the swapped pages would not fit inMemAvailable. Restoring re-enables the recorded entries one by one, sinceswapon -awould miss a swap file absent from/etc/fstab.run()rather thansetup(), so the page cache is dropped before every suite and--skip-setupdoes not bypass it. The sysctl/THP writes are no-ops on later suites sinceensure_sysctlcompares before writing.Commits
refactor(executor): move linux_sysctl into executor helpers— pure move, the sysctl primitive is no longer walltime-specific.feat(memory): apply kernel memory tunables before memory-mode runsVerification
cargo clippy --all-targetsclean,cargo test --lib(pre-existing failures on this host are the sudo-requiring tests, which writekernel.kptr_restrictand are identical onmain).Not running in CI, skipping kernel memory tunables; host THP unchanged.enabled/defragbecome[never],vm.compaction_proactiveness = 0,vm.swappiness = 0, and the swap guard correctly loggedLeaving swap enabled: swapped pages do not fit in available memory.