progcache: trim allocations#10115
Draft
riptl wants to merge 2 commits into
Draft
Conversation
riptl
commented
Jun 6, 2026
Contributor
- wksp: add trim method
- progcache: trim allocations
Allow shrinking existing wksp allocations
Trim program cache record allocation to save space when loading over-allocated program data accounts. In theory, we could just allocate less space in the first place, to avoid the need for trimming. This patch for simplicity, not touching existing code.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an in-place “trim” capability for workspace-backed allocations and uses it to reduce post-load memory usage in the program cache (where deployers often over-allocate program accounts).
Changes:
- Add
fd_wksp_trim()to shrink an existing wksp allocation and add wksp tests/fuzz-op coverage for trimming. - Add
fd_alloc_trim()to expose trimming for large (wksp-direct)fd_allocallocations, plus allocator tests. - Add
fd_progcache_rec_compact()and call it after program load to trim away unused tail space.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util/wksp/test_wksp_user.c | Adds explicit and randomized tests for fd_wksp_trim() |
| src/util/wksp/fd_wksp.h | Exposes new fd_wksp_trim() API |
| src/util/wksp/fd_wksp_user.c | Implements fd_wksp_trim() logic (split/merge free partitions, ASan poison) |
| src/util/alloc/test_alloc.c | Adds tests for fd_alloc_trim() behavior |
| src/util/alloc/fd_alloc.h | Exposes new fd_alloc_trim() API |
| src/util/alloc/fd_alloc.c | Implements fd_alloc_trim() for large allocations |
| src/flamenco/progcache/fd_progcache_user.c | Calls record compaction after successful load attempt |
| src/flamenco/progcache/fd_progcache_rec.h | Declares fd_progcache_rec_compact() and documents intent |
| src/flamenco/progcache/fd_progcache_rec.c | Implements fd_progcache_rec_compact() using trimming |
| up less space. Solana program deployers typically over-allocate the | ||
| program data account (by about 2x) to support future growth. During | ||
| ELF loading, the entire size of the program might be used for scratch | ||
| calculations (due to awful ELF relocation semenatics). But after |
Comment on lines
+517
to
+520
| int | ||
| fd_wksp_trim( fd_wksp_t * wksp, | ||
| ulong gaddr, | ||
| ulong sz ); |
Comment on lines
+360
to
+363
| int | ||
| fd_alloc_trim( fd_alloc_t * join, | ||
| void * laddr, | ||
| ulong sz ); |
riptl
commented
Jun 6, 2026
| #include "../vm/fd_vm.h" /* fd_vm_syscall_register_slot, fd_vm_validate */ | ||
| #include "../../util/alloc/fd_alloc.h" | ||
|
|
||
| #include <stdatomic.h> |
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.