Skip to content

Reclaim pages after segment compaction#78

Merged
tjgreen42 merged 3 commits intomainfrom
page-reclamation
Dec 17, 2025
Merged

Reclaim pages after segment compaction#78
tjgreen42 merged 3 commits intomainfrom
page-reclamation

Conversation

@tjgreen42
Copy link
Copy Markdown
Collaborator

@tjgreen42 tjgreen42 commented Dec 17, 2025

Summary

  • Add page reclamation during segment compaction to prevent index bloat
  • Pages from merged source segments are now freed to PostgreSQL's FSM
  • New allocations check FSM first, reusing freed pages when available
  • Demote spill/merge notices to DEBUG1 to reduce build noise

Results (internal benchmark, 2.1M slack messages)

Metric Before After Improvement
Index Size 831 MB 473 MB 43% smaller
Pages Reused 0 45,026

Previously, when segments were merged during compaction, the pages from
the source segments were orphaned - they remained allocated but were no
longer referenced. This caused index bloat, with roughly 43% of space
wasted on the slack-db benchmark (831 MB → 473 MB after fix).

Changes:
- Add tp_segment_collect_pages() to collect all pages (data + page index)
  from a segment before merge
- Add tp_segment_free_pages() to record freed pages in PostgreSQL's FSM
- Call IndexFreeSpaceMapVacuum() after freeing pages so the FSM tree is
  updated and GetFreeIndexPage() can find them
- Modify allocate_segment_page() to check FSM for recycled pages before
  extending the relation
- Add FSM stats tracking for debugging (visible at DEBUG1 level)
- Demote spill/merge notices to DEBUG1 to reduce noise during builds

Testing:
- slack-db benchmark: index size reduced from 831 MB to 473 MB (43%)
- Page reuse during build: 45,026 pages reused from FSM
- All regression tests pass
@tjgreen42 tjgreen42 merged commit 36502f8 into main Dec 17, 2025
11 checks passed
@tjgreen42 tjgreen42 deleted the page-reclamation branch December 17, 2025 02:09
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.

1 participant