Repository navigation
[AUTOMATED] Let the per-function watchdog stop heritage's guard placement - #1044
Merged
Merged
Conversation
…ment Heritage guards every stack range at every call, so a function that hands the addresses of thousands of stack locals to thousands of calls places ranges x calls INDIRECT ops in one pass. That placement loop had no deadline probe: --max-fn-seconds could not cut it off, and a 290 KB function of this shape ran past a 10 s budget to 8 GB. Probe the deadline before each range placement visits, return before renaming once it has passed, and report a pass panic after the deadline as the budget error. A drive that finishes before its deadline is unchanged. Part of #1034 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
mahaloz
force-pushed
the
fix/fix1034-hugefn
branch
from
October 12, 2026 16:52
b4c48f2 to
416ffc0
Compare
mahaloz
added a commit
that referenced
this pull request
Oct 12, 2026
…oup default) (#1045) A function can use up a container's memory long before `--max-fn-seconds` fires. When it does, the kernel kills the whole run, not just that function. With this change kuna stops the function and records it as that function's error. A serial run does this by default under a cgroup memory cap; any run does it with an explicit `--max-fn-memory MiB`. With `big` from #1044 (one function that passes 700 stack structs to 700 calls) under a 1 GB cap: ``` $ systemd-run --user --scope -p MemoryMax=1G -p MemorySwapMax=0 -- kuna decompile-all big --json --max-fn-seconds 0 Killed # main: exit 137, no output cb "error": null # this PR, same command reg "error": null big "error": "per-function memory limit exceeded (512 MiB)" ``` `kuna decompile big big` under the same cap now exits 1 with that error instead of being killed. This is the shape of the command in #1034. - **Trip rule.** A function stops only when the process decompiling it is over the limit and the function itself has added at least 64 MiB since it began. Memory the batch already held when the function started can stop it only if the function adds 64 MiB on top of that. A function that starts within a tenth of the limit first returns free heap pages (`malloc_trim`) and measures again. A stopped function returns its pages before the next one starts. - **Default.** A serial run and `kuna decompile` under a finite cgroup v2 `memory.max` (the smallest one on the way to the root) take the cap less max(512 MiB, 10%). A 6 GiB cap gives 5,529 MiB. A `--jobs N` pool gets no default: a fixed share per worker stopped functions the container could have held. A container-level check for pools is a possible follow-up. Outside a capped cgroup there is no default either. An explicit value, `0` included, always wins, and `--jobs` workers and `decomp_dbg` get the parent's value as a flag. - **Mechanism.** It uses the watchdog's existing cooperative probes. Memory is read when a function starts and then at most every 50 ms from `/proc/self/status`. On platforms without that file a non-zero value is refused and there is no default. - **Surfaces.** `decompile-all`, `decompile-project`, `decompile-graph` and `kuna decompile`. No new knob for huge functions: `--max-size N` already leaves functions over N bytes out of a run, and `--option maxinstruction N` truncates their flow. `docs/cli.md` points to both. On a long in-process batch the limit is still a whole-process limit. In stripped `bash -O2`, the process holds 158 to 175 MiB of live data after releasing free pages. At `--max-fn-memory 250`, 4 of 2,540 functions stop, and each of them added 64 to 85 MiB, taking the process to 260 to 273 MiB. At 200 MiB, 7 functions stop. 300 functions of `/usr/bin/gh` at 150 MiB, below the process's post-load size, all decompile. In a 6 GiB scope with the defaults, `gh` under `--jobs 8` has no memory stops. Its 30 largest functions run serially give 17 decompiled and 13 watchdog trips, and the run is not killed. Tests: - `memory_limit_stops_one_function_and_the_batch_continues`: serial, `--jobs 2` and `kuna decompile`. - `ordinary_functions_never_trip_the_memory_limit`: fauxware is byte-identical at 1 MiB, below the post-load size, and at 64 GiB; `6G` is refused. - `the_memory_limit_defaults_to_a_share_of_the_cgroup_cap`: a faked 1 GiB cap gives 512 MiB serially, `kuna decompile` included. `--jobs 2` gets no default, and an explicit value wins. - Unit tests cover the trip rule and the cgroup walk, including a namespaced container's root cap. The first three tests fail before this change, which rejects the flag and has no default. dash, bzip2, cmp and crond decompile byte-identically to main with the limit off, and dash and cmp also with the default on (a 32 GiB cgroup). Speed (decompile-all of gzip, kmod, grep and ls, 11 interleaved runs under a 32 GiB cgroup, so with the default on): +0.33% on the min-sum. Fixes #1034 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--max-fn-secondscannot stop a function that hands the addresses of many stack locals to many calls: it runs far past the budget and its memory keeps growing until it finishes or the system kills it. This 45 KB function asks for 1 second and gets 13:The same shape at 290 KB (5,000 locals) ignores a 10 s budget and reaches 8 GB in 36 s, which matches the growth in #1034.
After: 1.37 s, 389 MB for the example; 10.8 s and 775 MB for the 290 KB function with a 10 s budget.
Tests:
watchdog_stops_heritage_guard_placementruns the example (checked in astests/hang-repro/escaped_locals) with a 1 s budget and fails without the fix (15 s against a 10 s bound). Speed (decompile-all of gzip, kmod, grep and ls, 11 interleaved runs): +1.7% on the min-sum with flat medians. That is within noise: the new probe runs 26,518 times over all ofls, which is well under a millisecond.Part of #1034
🤖 Generated with Claude Code
https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz