feat(mem): pure resolver + strict parse + clamp for CBM_MEM_BUDGET_MB#954
Open
yangsec888 wants to merge 2 commits into
Open
feat(mem): pure resolver + strict parse + clamp for CBM_MEM_BUDGET_MB#954yangsec888 wants to merge 2 commits into
yangsec888 wants to merge 2 commits into
Conversation
…_BUDGET_MB Fold the inline CBM_MEM_BUDGET_MB override logic in cbm_mem_init into a pure, testable cbm_mem_resolve_budget() that returns a result struct (budget/source/clamped/invalid), so the parse + clamp lives in exactly one place and cbm_mem_init only surfaces the outcome as log lines. Parsing now matches the strict src/foundation/limits.c convention (errno/ERANGE, reject trailing garbage, positive-only): a fat-fingered value like "8GB" or a 20-digit typo becomes a warning + safe ram_fraction fallback instead of a silently wrong budget. A valid-but-huge value clamps to detected total RAM (logged mem.budget.clamped) rather than overflowing the MiB->bytes multiply and wrapping to a near-zero budget (which would pin cbm_mem_over_budget() true and stall indexing). mem.init now logs source= on both the override and fraction paths, and the README gains the CBM_MEM_BUDGET_MB row it lacked. Hardening of the existing DeusData#363 knob. Signed-off-by: Sam Li <yangsec888@gmail.com>
…mped CBM_MEM_BUDGET_MB The DeusData#363 memory axis (CBM_MEM_BUDGET_MB) has shipped, so this reproduce-first case is now a permanent GREEN guard, not an open bug. Its header claimed the override "does not exist" and asserted the budget is honoured "regardless of host RAM" — both stale: the resolver now clamps the override to effective (cgroup/host) RAM. On a <4 GiB host the old 4096 MiB assertion would clamp and falsely flip the bug board RED. Rewrite the header to describe the shipped + clamped behaviour and drop the override to 128 MiB, which is at/below any realistic host's RAM so it is honoured exactly and stays stable on every runner. The clamp path itself is unit-tested in tests/test_mem.c (resolve_budget_override_clamped_to_total). Signed-off-by: Sam Li <yangsec888@gmail.com>
Owner
|
Thanks for hardening the memory-budget knob. Triage: stability/performance improvement, normal priority. Review focus is strict parsing, sane clamping, deterministic defaults, and making sure bad env values fail local and predictable rather than surprising users. |
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.
Summary
Hardens the existing
CBM_MEM_BUDGET_MBknob per the direction in #586 — extracts the inline budget logic into a pure, testable resolver, adds clamp-to-total-RAM andsource=logging, and adds the README row it lacked. No new env var.cbm_mem_resolve_budget(total_ram, ram_fraction, budget_mb)returns a small result struct{ budget, source, clamped, invalid }. The parse + clamp now live in exactly one place;cbm_mem_initonly surfaces the outcome as log lines (no second parse).src/foundation/limits.cconvention (errno/ERANGE, reject trailing garbage, positive-only). A fat-fingered8GB/512MB/ 20-digit typo becomes amem.budget.env.invalidwarning + saferam_fractionfallback instead of a silently wrong budget.mem.budget.clamped) instead of overflowing the MiB→bytes multiply and wrapping to a near-zero budget — which would pincbm_mem_over_budget()permanently true and stall indexing. When RAM detection fails (total_ram == 0), an astronomical value caps atSIZE_MAXrather than wrapping.mem.initnow logssource=on both the override and fraction paths.CBM_MEM_BUDGET_MBrow.Behavior
CBM_MEM_BUDGET_MBram_fraction × total_ram(source=ram_fraction)source=CBM_MEM_BUDGET_MB)mem.budget.clamped)SIZE_MAXfor astronomical values)mem.budget.env.invalid)Testing
tests/test_mem.c(fraction default, invalid fraction, override wins, clamp-to-total, total-unknown, strict-reject batch incl.8GB/512MB/0x400/ERANGE, plus the two integer-overflow abuse guards), asserting.budget/.source/.clamped/.invalid.test-runnermemsuite: 49/49 pass.clang-format --dry-run --Werrorclean.Follow-ups (out of scope — for the broader memory-policy pass)
These are cross-cutting and intentionally left for the combined memory-policy design pass mentioned in #586:
CBM_WORKERS,CBM_MEM_BUDGET_MB,limits.*) so every override shares identical errno/trailing/range/warn semantics. TodayCBM_WORKERS(system_info.c) andlimits.cuse two different parsing styles.mem.ctracks RSS + enforces a number; a policy module (no globals) owns tiers + override + clamp, resolved once inmain.cand injected — removing the init-once global and the test-onlycbm_mem_set_budget_for_testshook.docs/CONFIGURATION.md's env table is a stale subset of README's; the tiers/clamp/retention/subprocess-isolation story lives only in code comments.Signed-off-by: Sam Li yangsec888@gmail.com