Skip to content

Tier RAM budget by host size#752

Merged
DeusData merged 1 commit into
DeusData:mainfrom
Andy11-cpu:fix/ram-tier-budget
Jul 4, 2026
Merged

Tier RAM budget by host size#752
DeusData merged 1 commit into
DeusData:mainfrom
Andy11-cpu:fix/ram-tier-budget

Conversation

@Andy11-cpu

Copy link
Copy Markdown
Contributor

Summary

  • Use 25% of physical RAM on hosts with <=16GB, 35% on <=32GB, and 50% above
  • Add cbm_mem_ram_fraction_for_total() with unit tests

Motivation

Split from #625 — reduces default memory reservation on 16GB machines without changing indexing behavior.

Test plan

  • mem_ram_fraction_* tier tests in test_mem.c
  • make -f Makefile.cbm test (CI)

Signed-off-by: Andy11-cpu canada11@duck.com

Use 25% of physical RAM on hosts with 16GB or less, 35% on 32GB or less, and 50% above. Expose cbm_mem_ram_fraction_for_total() for unit tests and call it from MCP/CLI startup instead of a fixed 50% fraction.

Signed-off-by: Andy11-cpu <canada11@duck.com>
@Andy11-cpu Andy11-cpu requested a review from DeusData as a code owner July 2, 2026 01:56
@DeusData DeusData added stability/performance Server crashes, OOM, hangs, high CPU/memory priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Jul 3, 2026
@DeusData

DeusData commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Thanks for the RAM-budget split. Triage: high-priority stability/performance work from the memory-pressure track.

Review will check that the tiered default is conservative on 16GB machines, does not regress larger-host throughput unexpectedly, and composes correctly with explicit memory-budget overrides. Please keep any benchmark or before/after memory observations in the PR description as it evolves.

@DeusData

DeusData commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Quick status note: this PR is one of four open memory/RAM-policy changes (#833, #752, #586, #685) that we've reviewed individually and found genuinely complementary — so rather than merging them piecemeal, we're doing a combined design pass over the whole memory policy (explicit override, host-tiered defaults, retention bounds, post-index release, and the Windows auto-sync driver in #841) and will respond here with a concrete direction shortly. Your work is very much part of that plan — thanks for your patience!

@DeusData DeusData added the bug Something isn't working label Jul 4, 2026
@DeusData DeusData merged commit a960d3d into DeusData:main Jul 4, 2026
14 checks passed
@DeusData

DeusData commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Thank you — this is a clean, well-judged fix: tiering the RAM fraction by host size (25% ≤16GB / 35% ≤32GB / 50% above) so small and containerized hosts don't over-commit, and it correctly reads the cgroup-aware total so a memory-limited container gets the right tier. Atomic, green on all platforms, with genuine boundary tests. Merged as a960d3d. It composes cleanly with the CBM_MEM_BUDGET_MB explicit override (override still wins) and the retention layer's re-read fallback covers the smaller-budget case with no lost edges. Appreciated — and thanks for splitting this out from the earlier bundle so it could land on its own merits!

pull Bot pushed a commit to MrDolphin/codebase-memory-mcp that referenced this pull request Jul 4, 2026
…ts, blinding backpressure)

Distilled from DeusData#776's 132460f. This project sets arena_eager_commit=0 +
purge_decommits=1 + purge_delay=0 in cbm_mem_init to reduce upfront memory, so
mimalloc's committed-page counter reads low. On Linux mi_process_info() never
sets current_rss (vendored/mimalloc/src/prim/unix/prim.c only fills peak_rss),
so current_rss defaults to that low committed counter — cbm_mem_rss() returned a
few MB while true RSS was multiple GB, leaving cbm_mem_over_budget() backpressure,
the memory ceiling, and the host RAM tier blind on Linux.

Prefer os_rss() (/proc/self/statm) as the primary source on Linux; macOS and
Windows are unchanged (their mi_process_info current_rss is accurate via
task_info / GetProcessMemoryInfo). cbm_mem_peak_rss() is untouched. Complements
DeusData#752 by making the RAM tiers actually bite on Linux.

Reproduce-first: mem_rss_reflects_external_resident_memory pins mimalloc's
committed counter low with a live mi_malloc, then grows true RSS via a raw 256MB
mmap (invisible to mimalloc); unfixed Linux returns the ~few-MB committed counter
(RED), fixed Linux returns /proc RSS (GREEN). macOS/Windows pass either way, so
the RED manifests on the Linux CI leg.

Co-authored-by: petercoxphoto <info@petercox.ie>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. stability/performance Server crashes, OOM, hangs, high CPU/memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants