valuelog: bound sealed mmap growth and export residency stats#827
valuelog: bound sealed mmap growth and export residency stats#827snissn wants to merge 20 commits intopr/rss-pressure-pool-governorfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces retained heap/RSS pressure in TreeDB’s cached write path by compacting pathologically underfilled batch copy-arena tail chunks before those chunks are leased to memtables, and adds instrumentation + tests to validate behavior.
Changes:
- Add batch arena tail-compaction logic that clones only entry slices aliasing an underfilled tail chunk, then releases the tail chunk before lease retention.
- Add new TreeDB stats counters for tail compaction (runs, copied bytes, saved bytes).
- Surface the new counters in
unified-benchcache stat output and add focused unit tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
TreeDB/caching/db.go |
Implements tail-compaction logic, adds DB counters, and exposes new stats keys. |
TreeDB/caching/batch_arena_budget_test.go |
Adds unit tests for alias-preserving cloning and no-op behavior for near-full tails. |
cmd/unified_bench/main.go |
Prints the new tail-compaction stats in the compact cache stats output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Validation update for commit aaacae8 (pressure-aware retention/clamp hardening).\n\nLocal checks:\n- GOWORK=off go test ./TreeDB/... ✅\n- GOWORK=off go vet ./TreeDB/... ✅\n- Unified bench profile dir: /home/mikers/tmp/perf-1773478400\n\nSame-window run_celestia A/B (serial), patched vs prepatch control (37b0483):\n\nfast\n- patched home: /home/mikers/.celestia-app-mainnet-treedb-20260313225408\n- prepatch home: /home/mikers/.celestia-app-mainnet-treedb-20260313231047\n- duration_seconds: 260 vs 292 (patched -32s)\n- max_rss_kb: 26305104 vs 28065736 (patched -1760632 kB)\n- end_app_bytes: 5734421000 vs 5625820250 (patched +108600750 B)\n\nwal_on_fast\n- patched home: /home/mikers/.celestia-app-mainnet-treedb-20260313225850\n- prepatch home: /home/mikers/.celestia-app-mainnet-treedb-20260313231603\n- duration_seconds: 338 vs 349 (patched -11s)\n- max_rss_kb: 26477336 vs 26364472 (patched +112864 kB)\n- end_app_bytes: 4999204828 vs 5441349237 (patched -442144409 B)\n\nHeap-capture artifacts are present under each run's sync/diagnostics directory (pprof-heap-max-rss-*).\n\nInterpretation: this step is a net improvement on wall time in both profiles, improves RSS materially in fast and is near-neutral in wal_on_fast, with mixed end_app_bytes impact across profiles.\n |
There was a problem hiding this comment.
Pull request overview
This PR reduces heap/RSS pressure in the caching DB by compacting pathologically underfilled batch copy-arena tail chunks before those chunks are leased/retained by memtables, while adding new memory-pressure-aware retention/sizing behavior and surfacing new stats + tests.
Changes:
- Add batch arena tail compaction that clones only entry slices aliasing the underfilled tail, then drops the tail chunk before lease handoff; track new tail-compaction counters in DB stats.
- Make several pools/arenas pressure-aware (batch copy arena max chunk sizing, append-only direct arena retention limits, and skipping batch aux pool retention under pressure).
- Add targeted tests for tail compaction correctness (slice aliasing + pointer metadata stability), pressure-aware sizing/retention, and vlog maintenance cancellation still running forced GC.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
cmd/unified_bench/main.go |
Prints newly added batch-arena tail compaction stats in unified-bench cache stat output. |
TreeDB/caching/db.go |
Implements tail compaction + new stats; adds pressure-aware chunk sizing, append-only retention limits, and pressure-based dropping of batch aux pool entries; tweaks vlog generation maintenance cancellation behavior. |
TreeDB/caching/vlog_generation_scheduler_test.go |
Adds coverage ensuring forced GC still runs when rewrite planning is canceled by resumed foreground activity. |
TreeDB/caching/pool_pressure_test.go |
Adds test asserting batch aux pools skip retention under critical heap pressure and increment new counters. |
TreeDB/caching/batch_arena_sizing_test.go |
Adds tests verifying batch copy-arena init/growth clamps under critical pressure while still allowing large single writes. |
TreeDB/caching/batch_arena_budget_test.go |
Updates budget cap expectation and adds focused tail-compaction tests (alias-preserving clone + tail drop, and near-full no-op). |
TreeDB/caching/append_only_direct_writer_pool_test.go |
Adds test for append-only direct arena pressure-aware retention limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Validation update for commit 8ebeeb1 (batch-arena retained hard cap + borrow gating). What changed:
Local checks:
Unified bench (same command as thread):
Decisive A/B: serial run_celestia same-window control (new code vs aaacae8) Candidate (8ebeeb1):
Control (aaacae8):
Deltas (candidate - control):
Interpretation:
|
|
Follow-up validation for commit 4b465cb (preflight borrow admission). What changed:
Checks:
Same-window serial run_celestia A/B (candidate 4b465cb vs control aaacae8): Candidate:
Control (aaacae8):
Deltas (candidate - control):
Interpretation:
|
There was a problem hiding this comment.
Pull request overview
This PR reduces memory retention pressure in TreeDB’s caching layer by compacting pathologically underfilled batch arena tail chunks before handing ownership/leases to memtables, while adding pressure-aware retention limits and new observability counters.
Changes:
- Add batch-arena tail compaction plus global retained-hard-cap / borrow gating and pressure-aware chunk sizing/aux-pool retention controls.
- Surface new batch-arena tail-compaction counters in TreeDB stats and unified-bench cache stat output.
- Add targeted tests covering tail compaction semantics, hard-cap gating, pool-pressure behavior, and generational vlog maintenance cancellation behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
cmd/unified_bench/main.go |
Prints new batch-arena tail-compaction counters in cache stats output. |
TreeDB/caching/db.go |
Implements tail compaction, global retained hard-cap estimation + borrow gating, pressure-aware sizing/retention, and new stats counters; adjusts vlog maintenance cancellation handling to still run GC. |
TreeDB/caching/vlog_generation_scheduler_test.go |
Adds a regression test ensuring forced GC still runs after rewrite-plan cancellation. |
TreeDB/caching/pool_pressure_test.go |
Adds coverage that batch auxiliary pools skip retention under critical pressure. |
TreeDB/caching/batch_arena_sizing_test.go |
Tests critical-pressure clamping and “large write still allowed” behavior for batch arena chunk sizing. |
TreeDB/caching/batch_arena_ownership_test.go |
Adds tests for retained-hard-cap behavior across sustained writes and preflight blocking. |
TreeDB/caching/batch_arena_budget_test.go |
Updates pool-budget saturation expectation; adds tests for hard-cap override, preflight borrow blocking, hard-cap pool drop, and tail compaction mechanics. |
TreeDB/caching/append_only_direct_writer_pool_test.go |
Adds pressure-aware retention limit test for append-only direct value arena retention. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b465cbf0c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR primarily targets reducing retained heap/RSS from batch copy-arena tail chunks by compacting pathologically underfilled tails before memtable lease handoff, and adds related instrumentation surfaced via unified-bench. It also expands memory-pressure handling (pool retention/drop behavior, hard caps) and adds debugging/behavioral tweaks around memtable rotation and generational maintenance.
Changes:
- Add batch arena tail compaction (clone only slices aliasing the underfilled tail, then drop the oversized tail chunk) plus new stats counters and unified-bench output.
- Introduce pressure-aware retention/sizing policies (batch arena retained hard cap, pressure-clamped copy chunk sizing, append-only direct arena retention limits, dropping aux pool entries under pressure).
- Add tests and additional operational/debug behavior (iterator-triggered rotation flush triggering, debug memtable rotation logging, adaptive memtable decision telemetry, and ensuring forced GC still runs after rewrite-plan cancellation).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/unified_bench/main.go | Surface new batch-arena tail-compaction counters in unified-bench cache stats output. |
| TreeDB/caching/db.go | Implement tail compaction + pressure-aware batch arena retention/hard-cap gating; add new stats and tweak rotation/maintenance behaviors. |
| TreeDB/caching/debug_memtable_rotate.go | Add env-gated debug logging for memtable rotation events. |
| TreeDB/caching/debug_memtable_rotate_test.go | Validate mode-label mapping and nil handling for debug rotation logging. |
| TreeDB/caching/iterator_rotation_flush_test.go | Add coverage for iterator-triggered rotations requesting background flush when queue already has work. |
| TreeDB/caching/vlog_generation_scheduler_test.go | Ensure rewrite-plan cancellation still proceeds to forced GC and scheduler returns to idle. |
| TreeDB/caching/stats_test.go | Add test for adaptive BTree min-iterator-samples override behavior. |
| TreeDB/caching/pool_pressure_test.go | Add test ensuring aux batch pools skip retention under critical pressure. |
| TreeDB/caching/batch_arena_sizing_test.go | Add tests for pressure-clamped arena sizing and allowing large single writes. |
| TreeDB/caching/batch_arena_ownership_test.go | Add tests for hard-cap behavior bounding leases and for preflight blocking. |
| TreeDB/caching/batch_arena_budget_test.go | Add tests for hard-cap override, preflight logic, hard-cap drops in pool, and tail compaction. |
| TreeDB/caching/append_only_direct_writer_pool_test.go | Add tests for pressure-aware append-only direct arena retention limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Follow-up pushed: What changed in this step:
Validation:
Celestia runs:
Key diagnostic delta from debug runs:
So this step is acting in the intended direction for the specific tiny-rotation queue-churn pathology. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c350fb3ec3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Pushed follow-up Change:
Validation:
Same-window branch-vs-main A/B (using Fast profile:
wal_on_fast profile:
Interpretation: this step clearly improves RSS and queue-churn behavior; fast wall is improved in this window, wal_on_fast wall is slightly slower in this single pair and needs another sample before treating as a real regression. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b2118aca9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Follow-up on iterator-rotation flush aggressiveness experiments.
So current conclusion stands: keep guarded iterator-flush policy; do not merge the always-kick variant. |
|
Iteration update: commit What changed
Validation
Unified-bench (baseline
run_celestia serial (with
Note on runtime comparability
|
There was a problem hiding this comment.
Pull request overview
This PR reduces memory/RSS pressure from cached batch copy-arena chunks by compacting pathologically underfilled tail chunks before batch-arena leasing/retention, and adds related telemetry and tests across caching/memtable/zipper.
Changes:
- Add batch arena tail-compaction (clone only entry slices that alias an underfilled tail, then release the oversized tail chunk) plus new stats surfaced in unified-bench output.
- Introduce/extend memory-retention controls and telemetry (batch-arena retained hard cap, pool-pressure-aware limits, deferred bytes tracking) with additional targeted tests.
- Update zipper merge paths to reuse apply-lifetime scratch for split keys and optionally reuse outer-leaf build pages.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/unified_bench/main.go | Surface new batch-arena tail-compaction counters in unified-bench cache stat output. |
| TreeDB/zipper/zipper.go | Add apply scratch reuse for split-key cloning; add outer-leaf build page pooling; thread scratch through merge recursion. |
| TreeDB/zipper/zipper_test.go | Update mergeLeaf callsites; add tests for apply-scratch reuse/reset and arena trimming. |
| TreeDB/internal/memtable/append_only.go | Add hard-reset policy support (drop retained chunks/maps when requested). |
| TreeDB/internal/memtable/append_only_reset_hard_test.go | New test ensuring hard reset clamps post-spike capacity and drops retained arena chunks. |
| TreeDB/caching/db.go | Core changes: tail compaction, batch-arena hard-cap gating, pressure-aware pool retention, deferred-bytes telemetry, retained-arena trimming, iterator rotation flush trigger, adaptive memtable decision telemetry/env knob, and related stats wiring. |
| TreeDB/caching/vlog_generation_scheduler_test.go | Add test ensuring rewrite-plan cancellation still proceeds to forced GC path. |
| TreeDB/caching/stats_test.go | Add test for adaptive memtable BTree min-iterator-samples override behavior + reason tracking. |
| TreeDB/caching/retained_arena_trim_test.go | New test for post-checkpoint retained-arena trimming behavior. |
| TreeDB/caching/pool_pressure_test.go | Add test covering dropping batch aux pools under critical pressure. |
| TreeDB/caching/memtable_view_telemetry_test.go | Extend tests to cover deferred-bytes tracking in view telemetry. |
| TreeDB/caching/iterator_rotation_flush_test.go | New tests ensuring iterator-triggered rotations don’t let queue depth grow unbounded and only enqueue non-empty shards. |
| TreeDB/caching/iterator_lease_test.go | Extend iterator lease tests to assert deferred-bytes stats behavior. |
| TreeDB/caching/debug_memtable_rotate.go | Add optional env-gated debug logging for memtable rotation events. |
| TreeDB/caching/debug_memtable_rotate_test.go | New tests for debug memtable mode labeling (incl. nil). |
| TreeDB/caching/batch_arena_sizing_test.go | Add tests for pressure-aware batch arena chunk sizing/clamping behavior. |
| TreeDB/caching/batch_arena_ownership_test.go | Add tests for retained hard-cap behavior and preflight blocking. |
| TreeDB/caching/batch_arena_budget_test.go | Add tests for new pool-drain and hard-cap/lease/global-bytes helpers and tail-compaction behavior. |
| TreeDB/caching/backpressure_component_test.go | Update test expectations around skipping empty rotate units and flushing non-empty units. |
| TreeDB/caching/append_only_direct_writer_pool_test.go | Add tests for oversize chunk drop, trimRetained caps, and pressure-aware retention limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Follow-up push: What changed
Validation
run_celestia fixed-height A/B (serial)
Key deltas (patched vs pre-change control)
|
There was a problem hiding this comment.
Pull request overview
This PR reduces memory/RSS pressure in TreeDB’s caching path by compacting pathologically underfilled batch arena tail chunks before memtable lease/borrow retention, and expands observability + pressure-aware retention/trim behaviors across several cache components.
Changes:
- Add batch arena tail-compaction (clone only aliased entry slices, drop oversized tail chunk) plus new cache stats surfaced in unified-bench.
- Introduce pressure-aware retention limits/hard caps and post-flush/checkpoint trimming for batch arenas, entry-slice leases/pools, and append-only direct arenas/memtable leases.
- Expand observability: deferred-bytes telemetry for memtable views, value-log mmap residency (active/dead bytes), adaptive memtable decision stats + env knob, and debug logging/tests for memtable rotation.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/unified_bench/main.go | Adds printing of new batch-arena tail-compaction counters in cache stat output. |
| TreeDB/zipper/zipper.go | Introduces apply-lifetime scratch reuse for split-key cloning and outer-leaf build-page buffers. |
| TreeDB/zipper/zipper_test.go | Adds focused tests for apply scratch reuse/trimming and outer-leaf build-page reuse behavior. |
| TreeDB/internal/valuelog/reader_mmap.go | Tracks dead-mapped bytes when remapping grows the mmap. |
| TreeDB/internal/valuelog/manager.go | Adds deadMappedBytes counter + MmapResidencyStats; avoids eager mmap/remap on open. |
| TreeDB/internal/valuelog/manager_test.go | Adds tests for mmap residency aggregation and non-eager mapping on open. |
| TreeDB/internal/memtable/append_only.go | Adds hard reset policy to drop retained buffers after spikes; plumbing for hard reset behavior. |
| TreeDB/internal/memtable/append_only_reset_hard_test.go | Tests that hard reset drops observed spike capacity and retained value-arena chunks. |
| TreeDB/db/api.go | Exposes value-log mmap residency stats via DB Stats() in backend/read-only path. |
| TreeDB/caching/db.go | Implements tail compaction + new retention hard caps, pressure-aware pool behavior, deferred-bytes telemetry, post-flush trims, adaptive memtable decision stats, iterator-rotation flush trigger, and debug rotate logging. |
| TreeDB/caching/batch_arena_sizing_test.go | Tests copy-arena chunk sizing clamps under critical pressure and large-write override behavior. |
| TreeDB/caching/batch_arena_budget_test.go | Adds tests for pool draining, hard-cap behavior, tail-compaction behavior, and hard-cap preflight gating. |
| TreeDB/caching/batch_arena_ownership_test.go | Adds hard-cap lease-growth tests across sustained writes and large-first-batch preflight blocking. |
| TreeDB/caching/pool_pressure_test.go | Tests that auxiliary batch pools skip retention under critical pressure. |
| TreeDB/caching/append_only_direct_writer_pool_test.go | Adds tests for oversize-chunk drop, trimming behavior, and pressure-aware retention limits. |
| TreeDB/caching/retained_arena_trim_test.go | Tests checkpoint-path trimming for append-only caches and retained direct arenas. |
| TreeDB/caching/vlog_generation_scheduler_test.go | Ensures forced GC still runs even when rewrite planning cancels due to resumed foreground reads. |
| TreeDB/caching/memtable_view_telemetry_test.go | Updates tests for deferred-bytes tracking in memtable view telemetry. |
| TreeDB/caching/iterator_lease_test.go | Extends iterator lease tests to validate deferred-bytes stats. |
| TreeDB/caching/iterator_rotation_flush_test.go | Adds tests ensuring iterator-triggered rotation can kick background flush and only enqueues non-empty shards. |
| TreeDB/caching/debug_memtable_rotate.go | Adds env-gated debug logging for memtable rotation events. |
| TreeDB/caching/debug_memtable_rotate_test.go | Tests debugMemtableModeLabel mapping for known memtable implementations. |
| TreeDB/caching/stats_test.go | Adds coverage for adaptive BTree min-iterator-sample override behavior. |
| TreeDB/caching/backpressure_component_test.go | Renames/extends test to validate queue behavior across empty vs non-empty rotates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7f3bac819
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR reduces file-backed RSS and improves memory observability/controls by changing value-log mmap behavior (lazy mapping + bounded sealed-segment residency), adding new mmap residency stats, and tightening several in-memory retention/rotation behaviors in caching/memtable layers.
Changes:
- Value-log: switch to lazy mmap on open, mark only current-writable segments as persistently remappable, cap sealed-segment mmap residency, and export mmap residency counters.
- Caching/memory: add batch-arena hard-cap + tail-compaction, pressure-aware pool retention, post-flush/checkpoint trimming, and iterator-rotation flush behavior.
- Telemetry/tests: add/extend stats for mmap residency, deferred memtable bytes, adaptive memtable decisions, and add focused tests across packages.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cmd/unified_bench/main.go | Adds batch-arena tail-compaction metrics to printed stat list. |
| TreeDB/zipper/zipper.go | Introduces apply-lifetime merge scratch + pooled outer-leaf page buffers; updates merge APIs to use scratch-cloned split keys. |
| TreeDB/zipper/zipper_test.go | Updates existing merge test for new signature and adds scratch reuse/trim tests. |
| TreeDB/internal/valuelog/reader_mmap.go | Adds sealed-segment mmap budget controls and persistent-vs-sealed mmap gating; tracks dead mapped bytes. |
| TreeDB/internal/valuelog/manager.go | Removes eager mmap on open; adds current-writable promotion, residency aggregation, and sealed mmap admission logic. |
| TreeDB/internal/valuelog/manager_test.go | Adds tests for lazy-open behavior, current-writable promotion, residency aggregation, and sealed-budget ReadAt fallback. |
| TreeDB/db/api.go | Exposes value-log mmap residency stats via DB.Stats(). |
| TreeDB/internal/memtable/append_only.go | Adds hard-reset path to drop retained buffers after spikes; used by caching recycle paths. |
| TreeDB/internal/memtable/append_only_reset_hard_test.go | New test validating hard reset drops spike retention. |
| TreeDB/caching/db.go | Adds pool-pressure controls, batch-arena hard caps + tail compaction, deferred-bytes telemetry, trimming after flush/checkpoint, adaptive decision telemetry, iterator rotation flush triggering, and value-log segment promotion on register. |
| TreeDB/caching/debug_memtable_rotate.go | Adds optional debug logging for memtable rotations. |
| TreeDB/caching/debug_memtable_rotate_test.go | Tests debug memtable mode labeling. |
| TreeDB/caching/pool_pressure_test.go | Tests aux pool retention skipping under critical pressure. |
| TreeDB/caching/batch_arena_sizing_test.go | Tests batch arena sizing clamping under critical pressure. |
| TreeDB/caching/batch_arena_ownership_test.go | Tests retained hard-cap gating behavior across sustained writes and preflight blocking. |
| TreeDB/caching/batch_arena_budget_test.go | Adds hard-cap, draining, tail-compaction, and global-lease tracking tests; updates max budget expectation. |
| TreeDB/caching/append_only_direct_writer_pool_test.go | Adds oversize-drop + trimming + pressure-aware retention tests for append-only direct arena. |
| TreeDB/caching/retained_arena_trim_test.go | New test covering trimming behavior after checkpoint flush path. |
| TreeDB/caching/iterator_rotation_flush_test.go | New tests ensuring iterator-triggered rotations don’t let queue backlog grow unbounded. |
| TreeDB/caching/iterator_lease_test.go | Extends iterator lease telemetry assertions to include deferred bytes. |
| TreeDB/caching/memtable_view_telemetry_test.go | Updates tests for new deferred-bytes telemetry fields. |
| TreeDB/caching/backpressure_component_test.go | Renames/extends test to cover empty-rotate vs non-empty rotate behavior. |
| TreeDB/caching/stats_test.go | Adds test for adaptive BTree min-iterator-samples override behavior. |
| TreeDB/caching/vlog_generation_scheduler_test.go | Adds test ensuring forced GC still runs when rewrite planning is canceled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR bounds TreeDB’s file-backed RSS growth by making value-log mmaps lazy and budgeted, adds mmap residency telemetry, and tightens several cache/memtable retention behaviors to reduce post-spike memory.
Changes:
- Value-log: lazy mmap on open, persistent mmap only for current-writable segments, sealed-segment lazy-mmap budget with
ReadAtfallback, and exported residency stats. - Caching/memtable: hard-reset path for append-only reuse, pressure-aware pool retention, iterator-rotation flush behavior, and additional telemetry/stats.
- Zipper/batch: new apply-lifetime scratch reuse (split keys + outer-leaf build pages) and batch-arena tail compaction + hard-cap gating.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/unified_bench/main.go | Adds new batch-arena tail compaction stat keys to unified bench output. |
| TreeDB/zipper/zipper.go | Adds apply scratch reuse for merge split keys + outer-leaf page build buffers. |
| TreeDB/zipper/zipper_test.go | Updates mergeLeaf signature usage and adds scratch reuse/trim tests. |
| TreeDB/internal/valuelog/reader_mmap.go | Adds sealed lazy-mmap budget + persistent-mmap gating and env knob. |
| TreeDB/internal/valuelog/manager.go | Tracks current-writable segment per lane, mmap residency stats, and lazy-mmap allowance logic. |
| TreeDB/internal/valuelog/manager_test.go | Adds tests for lazy open, writable promotion, residency aggregation, and sealed budget fallback. |
| TreeDB/internal/memtable/append_only.go | Adds “hard” reset policy to drop retained buffers after spikes. |
| TreeDB/internal/memtable/append_only_reset_hard_test.go | Tests hard-reset behavior for append-only memtable. |
| TreeDB/db/api.go | Exposes new value-log mmap budget and residency stats via DB stats. |
| TreeDB/caching/vlog_generation_scheduler_test.go | Ensures forced GC can still run when rewrite planning is canceled. |
| TreeDB/caching/stats_test.go | Adds test for adaptive BTree min-iterator-samples override behavior. |
| TreeDB/caching/retained_arena_trim_test.go | Tests post-checkpoint trimming of append-only caches/arenas. |
| TreeDB/caching/pool_pressure_test.go | Tests aux pool retention drops under critical pressure. |
| TreeDB/caching/memtable_view_telemetry_test.go | Updates tests for deferred bytes telemetry tracking. |
| TreeDB/caching/iterator_rotation_flush_test.go | Adds tests for iterator-triggered rotation + flush and shard enqueue filtering. |
| TreeDB/caching/iterator_lease_test.go | Extends iterator lease tests to include deferred-bytes telemetry. |
| TreeDB/caching/debug_memtable_rotate_test.go | Adds tests for memtable mode label helper used in debug logging. |
| TreeDB/caching/debug_memtable_rotate.go | Adds optional stderr debug logging for memtable rotations. |
| TreeDB/caching/db.go | Implements multiple retention/pressure controls, new stats, and iterator rotation flush behavior. |
| TreeDB/caching/batch_arena_sizing_test.go | Tests batch arena chunk sizing clamp under critical pressure. |
| TreeDB/caching/batch_arena_ownership_test.go | Tests batch-arena retained hard-cap behavior across sustained writes. |
| TreeDB/caching/batch_arena_budget_test.go | Adds tests for draining, hard-cap gating, and tail compaction behavior. |
| TreeDB/caching/backpressure_component_test.go | Updates test to reflect skipping empty units during flush/rotate. |
| TreeDB/caching/append_only_direct_writer_pool_test.go | Adds tests for oversize chunk drops and pressure-aware retention limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0ff55a3125
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45871cadef
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR reduces file-backed RSS by making value-log mmapping lazy and bounded (especially across sealed segments), while adding richer residency stats and several cache/memtable memory-retention controls and diagnostics.
Changes:
- Value-log: lazily mmap segments, promote only the current writable segment per lane for persistent remaps, and enforce a capped sealed-segment lazy-mmap budget with
ReadAtfallback. - Caching/memtable: add retained-buffer trimming (post-flush/checkpoint), batch-arena hard caps + tail-compaction, and adaptive memtable decision telemetry/tuning.
- Add targeted tests covering mmap behavior, scratch/buffer reuse, trim policies, and new stats/telemetry.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/unified_bench/main.go | Exposes new batch-arena tail-compaction stats in unified bench output. |
| TreeDB/zipper/zipper.go | Introduces apply-lifetime scratch + pooled outer-leaf build pages to reduce per-apply allocs. |
| TreeDB/zipper/zipper_test.go | Adds tests for apply-scratch reuse and trimming behavior. |
| TreeDB/internal/valuelog/reader_mmap.go | Adds sealed lazy-mmap budget + “persistent mmap” gating logic. |
| TreeDB/internal/valuelog/manager.go | Tracks current writable per lane, exports mmap residency stats, and enforces sealed mapping budget. |
| TreeDB/internal/valuelog/manager_test.go | Adds tests for residency aggregation, writable promotion, and sealed-budget fallback. |
| TreeDB/db/api.go | Exposes new value-log mmap configuration/residency stats via DB stats. |
| TreeDB/internal/memtable/append_only.go | Adds “hard reset” option to drop retained buffers and avoid spike retention. |
| TreeDB/internal/memtable/append_only_reset_hard_test.go | Tests hard reset clamping and retained-chunk drop behavior. |
| TreeDB/caching/db.go | Implements pool-pressure-aware retention policies, batch-arena hard caps, tail compaction, flush/checkpoint trimming, adaptive decision stats, and iterator-rotation flushing behavior. |
| TreeDB/caching/stats_test.go | Tests adaptive BTREE min-iterator sample gate behavior and decision accounting. |
| TreeDB/caching/snapshot_test.go | Updates tests to use atomic memtable-mode storage accessor. |
| TreeDB/caching/reverse_iterator_parity_test.go | Updates tests to use atomic memtable-mode storage accessor. |
| TreeDB/caching/vlog_generation_scheduler_test.go | Ensures canceling rewrite planning still runs forced GC and returns to idle state. |
| TreeDB/caching/retained_arena_trim_test.go | Tests post-checkpoint trimming behavior for retained arenas and append-only leases. |
| TreeDB/caching/pool_pressure_test.go | Tests that aux batch pools drop retention under critical pressure. |
| TreeDB/caching/memtable_view_telemetry_test.go | Extends deferred view telemetry tests to include deferred bytes tracking. |
| TreeDB/caching/iterator_rotation_flush_test.go | Adds tests verifying iterator-driven rotations trigger background flushing and avoid enqueuing empty shards. |
| TreeDB/caching/iterator_lease_test.go | Extends iterator lease tests to validate deferred-bytes telemetry. |
| TreeDB/caching/debug_memtable_rotate.go | Adds optional env-gated debug logging for memtable rotations. |
| TreeDB/caching/debug_memtable_rotate_test.go | Tests memtable mode label helper used by debug logs. |
| TreeDB/caching/batch_arena_sizing_test.go | Tests copy-arena chunk sizing clamps under critical pressure (while allowing large writes). |
| TreeDB/caching/batch_arena_ownership_test.go | Tests batch-arena hard-cap behavior across sustained writes and preflight blocking. |
| TreeDB/caching/batch_arena_budget_test.go | Adds tests for new draining, hard-cap, global leased tracking, and tail compaction. |
| TreeDB/caching/backpressure_component_test.go | Updates flush test to reflect new “skip empty shards” semantics. |
| TreeDB/caching/append_only_direct_writer_pool_test.go | Adds tests for oversize direct-arena chunk dropping and pressure-aware retention limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Summary
ReadAtfor cold sealed reads once the sealed-map budget is fullWhy
Validation
go test ./TreeDB/internal/valuelog -run 'PromoteCurrentWritable|SealedLazyMmapBudget|OpenFile_DoesNotEagerlyMap|Mmap'go test ./TreeDB/db ./TreeDB/cachinggo vet ./TreeDB/internal/valuelog ./TreeDB/db ./TreeDB/cachingCelestia Evidence
Using
/home/mikers/run_celestia.shwithLOCAL_GOMAP_DIR=/home/mikers/dev/snissn/gomap-geminion March 14, 2026:fast/home/mikers/.celestia-app-mainnet-treedb-20260314220733duration_seconds=351max_rss_kb=12720776end_app_bytes=5936149499smaps_rollup:Pss_File=761415 kB,Anonymous=11664956 kBwal_on_fast/home/mikers/.celestia-app-mainnet-treedb-20260314221413duration_seconds=446max_rss_kb=13300632end_app_bytes=5940826699smaps_rollup:Pss_File=547278 kB,Anonymous=12101152 kBInterpretation
Pss_Filecaptures