Skip to content

valuelog: add sealed mmap byte budget and deny-reason stats#829

Open
snissn wants to merge 6 commits intopr/vlog-mmap-telemetry-splitfrom
pr/vlog-mmap-sealed-byte-budget
Open

valuelog: add sealed mmap byte budget and deny-reason stats#829
snissn wants to merge 6 commits intopr/vlog-mmap-telemetry-splitfrom
pr/vlog-mmap-sealed-byte-budget

Conversation

@snissn
Copy link
Copy Markdown
Owner

@snissn snissn commented Mar 15, 2026

Summary

  • add a sealed lazy-mmap bytes budget (TREEDB_VLOG_MAX_MAPPED_SEALED_BYTES, default 64MiB) alongside the existing sealed-segment-count budget
  • deny sealed lazy mmap when either count cap or bytes cap would be exceeded, while keeping current-writable behavior unchanged
  • split sealed-map deny telemetry into count_cap vs bytes_cap and export both in TreeDB stats

Why

The telemetry split in #828 showed we can now distinguish current-vs-sealed mmap residency. This step uses that signal to bound sealed residency by bytes, not only segment count, so a few large sealed segments cannot inflate file-backed RSS.

Validation

  • go test ./TreeDB/internal/valuelog
  • go test ./TreeDB/internal/valuelog -run 'SealedLazyMmap|MmapResidencyStatsAggregatesCounters'
  • go test ./TreeDB/db -run TestDoesNotExist -count=1
  • go test ./TreeDB/caching -run TestDoesNotExist -count=1
  • go vet ./TreeDB/internal/valuelog ./TreeDB/db ./TreeDB/caching

Copilot AI review requested due to automatic review settings March 15, 2026 08:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a sealed mmap byte budget (default 64 MiB) alongside the existing sealed-segment-count cap, and splits sealed-map-denied telemetry into count-cap vs bytes-cap reasons.

Changes:

  • New MaxMappedSealedBytes config (env TREEDB_VLOG_MAX_MAPPED_SEALED_BYTES, default 64 MiB) that denies sealed lazy mmap when cumulative sealed mapped bytes would exceed the budget
  • Deny-reason enum (sealedLazyMmapDenyCountCap / sealedLazyMmapDenyBytesCap) with per-reason atomic counters and aggregated stats
  • Stats export of sealed_map_denied.count_cap and sealed_map_denied.bytes_cap in both db and caching layers

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
TreeDB/internal/valuelog/reader_mmap.go Add bytes budget constant/env var, stat the file before lock, split deny counters
TreeDB/internal/valuelog/manager.go Deny-reason enum, bytes accounting in allowSealedLazyMmapLocked, new SealedMapDeniedByReasonStats
TreeDB/internal/valuelog/manager_test.go Tests for byte-budget fallback and per-reason deny stats
TreeDB/db/api.go Export per-reason denied stats in Stats()
TreeDB/caching/db.go Same stats export + whitespace alignment

💡 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.

@snissn
Copy link
Copy Markdown
Owner Author

snissn commented Mar 15, 2026

Follow-up validation on pr/vlog-mmap-sealed-byte-budget (8dc4f4e4) using LOCAL_GOMAP_DIR=/home/mikers/dev/snissn/gomap-gemini.

Runs

fast

  • run home: /home/mikers/.celestia-app-mainnet-treedb-20260314230241
  • duration_seconds: 315
  • max_rss_kb: 8489412
  • end_app_bytes: 4773184050
  • du -sb application.db: 4773184050
  • nearest max-rss smaps capture: /home/mikers/.celestia-app-mainnet-treedb-20260314230241/sync/diagnostics/pprof-heap-max-rss-7533140k-20260314230647.smaps_rollup.txt
    • Pss_File=265631 kB
    • Anonymous=7265532 kB

wal_on_fast

  • run home: /home/mikers/.celestia-app-mainnet-treedb-20260314230842
  • duration_seconds: 337
  • max_rss_kb: 10268292
  • end_app_bytes: 4697750989
  • du -sb application.db: 4697750989
  • nearest max-rss smaps capture: /home/mikers/.celestia-app-mainnet-treedb-20260314230842/sync/diagnostics/pprof-heap-max-rss-9307220k-20260314231408.smaps_rollup.txt
    • Pss_File=410755 kB
    • Anonymous=8895108 kB

Comparison vs earlier #827 evidence (same day)

Reference runs:

  • fast /home/mikers/.celestia-app-mainnet-treedb-20260314220733: duration=351s, max_rss_kb=12720776, end_app_bytes=5936149499
  • wal_on_fast /home/mikers/.celestia-app-mainnet-treedb-20260314221413: duration=446s, max_rss_kb=13300632, end_app_bytes=5940826699

Observed deltas on this branch:

  • fast: -36s, -4231364 kB RSS, -1162965449 bytes end_app
  • wal_on_fast: -109s, -3032340 kB RSS, -1243075710 bytes end_app

Telemetry note

The new TreeDB mmap counters are exported through TreeDB stats surfaces, but celestia’s current forensics pipeline does not emit those counters into sync-time.log/node.log yet. I attempted live /debug/vars polling during these runs; only default expvar keys (cmdline, memstats) were exposed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a sealed value-log lazy-mmap byte budget (in addition to the existing sealed segment-count budget) and refines telemetry so operators can distinguish whether sealed lazy-mmap was denied due to segment-count vs byte-cap pressure.

Changes:

  • Introduces TREEDB_VLOG_MAX_MAPPED_SEALED_BYTES (default 64MiB) and enforces it for sealed (non-current-writable) lazy mmaps.
  • Splits sealed mmap deny counters into count_cap vs bytes_cap, and exports both via Stats() (db + caching).
  • Extends valuelog tests to cover byte-budget fallback and per-reason deny aggregation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
TreeDB/internal/valuelog/reader_mmap.go Adds the new env-configured sealed-mmap byte budget and increments per-reason deny counters when mapping is refused.
TreeDB/internal/valuelog/manager.go Adds deny-reason plumbing, aggregates per-reason deny counters, and enforces the sealed mapped-bytes budget.
TreeDB/internal/valuelog/manager_test.go Adds helper + tests validating byte-budget fallback and deny-reason aggregation.
TreeDB/db/api.go Exports new max-bytes config stat and split deny-reason stats for non-caching DB stats.
TreeDB/caching/db.go Exports new max-bytes config stat and split deny-reason stats for caching DB stats.
Comments suppressed due to low confidence (1)

TreeDB/internal/valuelog/reader_mmap.go:170

  • The sealed mmap budgets can be exceeded under concurrent reads: the manager lock is released before remapToFileSize(), so multiple goroutines can all pass allowSealedLazyMmapLocked (seeing the target and other files as still-unmapped) and then mmap in parallel, overshooting both the segment-count and byte budgets. If the intent is to strictly cap sealed residency, consider reserving segments/bytes under m.mu (and releasing the reservation on mmap failure) or otherwise re-checking/enforcing the budget once the mapping is installed.
	m.mu.Lock()
	allow, denyReason := m.allowSealedLazyMmapLocked(f, targetSize)
	m.mu.Unlock()
	if !allow {
		switch denyReason {
		case sealedLazyMmapDenyCountCap:
			f.sealedMapDeniedByCount.Add(1)
		case sealedLazyMmapDenyBytesCap:
			f.sealedMapDeniedByBytes.Add(1)
		default:
			f.sealedMapDeniedByCount.Add(1)
		}
		return false
	}
	f.remapToFileSize()
	data, _ := f.mmapData.Load().([]byte)

💡 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.

Copilot AI review requested due to automatic review settings March 18, 2026 00:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a bytes-based budget for sealed lazy-mmap in the value log and exposes split deny telemetry (count cap vs bytes cap) via TreeDB stats.

Changes:

  • Introduce TREEDB_VLOG_MAX_MAPPED_SEALED_BYTES and enforce it alongside the existing sealed-segment-count cap.
  • Split sealed mmap deny counters into count_cap vs bytes_cap and aggregate/export them in stats.
  • Add tests covering the new byte-budget behavior and new deny-reason aggregation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
TreeDB/internal/valuelog/reader_mmap.go Adds env-configurable sealed-mmap byte budget and records deny reason counters.
TreeDB/internal/valuelog/manager.go Enforces byte budget in allowSealedLazyMmapLocked and exposes per-reason deny stats.
TreeDB/internal/valuelog/manager_test.go Adds helpers and tests for byte budget + deny-reason aggregation.
TreeDB/db/api.go Exports new sealed-mmap byte budget and per-reason deny stats in DB stats.
TreeDB/caching/db.go Exports new sealed-mmap byte budget and per-reason deny stats in caching DB stats.

💡 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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8c1cbca67

ℹ️ 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".

Copilot AI review requested due to automatic review settings March 18, 2026 20:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends TreeDB’s value-log sealed lazy-mmap policy to include a byte-based budget (in addition to the existing sealed-segment-count budget) and exposes deny-reason telemetry split by count-cap vs bytes-cap via Stats.

Changes:

  • Add TREEDB_VLOG_MAX_MAPPED_SEALED_BYTES / MaxMappedSealedBytes (default 64MiB) and enforce it when deciding whether to lazily mmap sealed segments.
  • Split sealed lazy-mmap deny counters into count_cap vs bytes_cap, and provide an aggregated total for backward compatibility.
  • Add/extend internal valuelog tests to cover byte-budget fallback behavior and deny-reason aggregation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
TreeDB/internal/valuelog/reader_mmap.go Adds sealed mapped-bytes budget config parsing and increments deny counters by reason during sealed lazy-mmap enable attempts.
TreeDB/internal/valuelog/manager.go Implements deny-reason enum, byte-budget enforcement, and deny-reason aggregation APIs.
TreeDB/internal/valuelog/manager_test.go Adds helpers and tests for byte-budget fallback and new deny-reason stats aggregation.
TreeDB/db/api.go Exports new byte-budget setting and split deny-reason stats in DB Stats output.
TreeDB/caching/db.go Exports new byte-budget setting and split deny-reason stats in caching DB 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants