Skip to content

progcache: trim allocations#10115

Draft
riptl wants to merge 2 commits into
firedancer-io:mainfrom
riptl:ripatel/progcache-comp-2
Draft

progcache: trim allocations#10115
riptl wants to merge 2 commits into
firedancer-io:mainfrom
riptl:ripatel/progcache-comp-2

Conversation

@riptl

@riptl riptl commented Jun 6, 2026

Copy link
Copy Markdown
Contributor
  • wksp: add trim method
  • progcache: trim allocations

riptl added 2 commits June 6, 2026 08:54
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.
@ripatel-fd ripatel-fd changed the title ripatel/progcache comp 2 progcache: trim allocations Jun 6, 2026
@ripatel-fd ripatel-fd marked this pull request as ready for review June 6, 2026 08:59
Copilot AI review requested due to automatic review settings June 6, 2026 08:59
@ripatel-fd ripatel-fd marked this pull request as draft June 6, 2026 09:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_alloc allocations, 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 thread src/flamenco/progcache/fd_progcache_rec.c
Comment thread src/util/wksp/fd_wksp.h
Comment on lines +517 to +520
int
fd_wksp_trim( fd_wksp_t * wksp,
ulong gaddr,
ulong sz );
Comment thread src/util/alloc/fd_alloc.h
Comment on lines +360 to +363
int
fd_alloc_trim( fd_alloc_t * join,
void * laddr,
ulong sz );
#include "../vm/fd_vm.h" /* fd_vm_syscall_register_slot, fd_vm_validate */
#include "../../util/alloc/fd_alloc.h"

#include <stdatomic.h>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unnecessary include

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