Mostly still reviewing and planning... (see description)

Anything considered static can be aggregated into a single VArena. We don't have to worry about ever releasing its memory or it growing "too large".  All memory here must be fixed sized.
Conservative persistent memory can grow on demand but we would perfer if it could be trimmed or released when no longer dealing with heavy scenarios. Persistent memory should use a slab allocator that is backed by a virtual address space pool allocator instead of pools allocating from a single varena. Chained Arenas can source thier chunks of vmem from the slab which can be utilized for scratch memory. Fonts should be loaded from VSlab. The string cache should use a dedicated varena with 16-byte alignment. All conservative memory should be trimmable by a wipe command which should free all unused blocks. Each block should be a single OS aware reserve of vmem.

The Frame can possilby stay as a single varena with scratch allocation utilized on demand. Although it may be more viable for chained varenas to be derived from the main varena via a slab or pool interface. Frame memory should be trimmable on command which should release its committed vmem to its initial value. A dedicated transient varena should not exist. It should be removed when possible. File mappings for now can use a dedicated varena made on demand with a capped reserve size of 4 meg. Any file exceeding this needs the host to support virtual memory mapped I/O for files. The codebase db will use sqlite for the file I/O abstraction.

Host might only need to track the first persistent block of vmem, and the rest can be handled by the client (including wrapping that vmem up in a varena). Hot-reload only needs persistent vmem's ref restored on the client module's side. All other references can be resolved from there.
This commit is contained in:
2025-07-07 02:00:57 -04:00
parent 87d5cda2c0
commit 6d780482c7
8 changed files with 265 additions and 203 deletions

View File

@ -10,8 +10,11 @@ Str_App_State := "App State"
//region Memory
// Data segment Memory for sectr module.
Memory_App : Memory
// General memory configuration
Memory_Base_Address_Persistent :: Terabyte * 1
Memory_Base_Address_Frame :: Memory_Base_Address_Persistent + Memory_Reserve_Persistent * 2
Memory_Base_Address_Transient :: Memory_Base_Address_Frame + Memory_Reserve_Frame * 2
@ -29,13 +32,6 @@ Memory_Commit_Initial_Frame :: 4 * Kilobyte
Memory_Commit_Initial_Transient :: 4 * Kilobyte
Memory_Commit_Initial_Filebuffer :: 4 * Kilobyte
MemorySnapshot :: struct {
persistent : []u8,
frame : []u8,
transient : []u8,
// files_buffer cannot be restored from snapshot
}
Memory :: struct {
persistent : ^VArena,
frame : ^VArena,
@ -44,15 +40,12 @@ Memory :: struct {
state : ^State,
// Should only be used for small memory allocation iterations
// Not for large memory env states
snapshot : MemorySnapshot,
replay : ReplayState,
logger : Logger,
profiler : ^SpallProfiler
}
persistent_allocator :: proc() -> Allocator {
result := varena_allocator( Memory_App.persistent )
return result
@ -97,37 +90,6 @@ transient_slab_allocator :: proc() -> Allocator {
return result
}
// TODO(Ed) : Implment host memory mapping api
save_snapshot :: proc( snapshot : ^MemorySnapshot )
{
// Make sure the snapshot size is able to hold the current size of the arenas
// Grow the files & mapping otherwise
{
// TODO(Ed) : Implement eventually
}
persistent := Memory_App.persistent
mem.copy_non_overlapping( & snapshot.persistent[0], persistent.reserve_start, int(persistent.commit_used) )
frame := Memory_App.frame
mem.copy_non_overlapping( & snapshot.frame[0], frame.reserve_start, int(frame.commit_used) )
transient := Memory_App.transient
mem.copy_non_overlapping( & snapshot.transient[0], transient.reserve_start, int(transient.commit_used) )
}
// TODO(Ed) : Implment host memory mapping api
load_snapshot :: proc( snapshot : ^MemorySnapshot ) {
persistent := Memory_App.persistent
mem.copy_non_overlapping( persistent.reserve_start, & snapshot.persistent[0], int(persistent.commit_used) )
frame := Memory_App.frame
mem.copy_non_overlapping( frame.reserve_start, & snapshot.frame[0], int(frame.commit_used) )
transient := Memory_App.transient
mem.copy_non_overlapping( transient.reserve_start, & snapshot.transient[0], int(transient.commit_used) )
}
// TODO(Ed) : Implement usage of this
MemoryConfig :: struct {
reserve_persistent : uint,
@ -220,6 +182,8 @@ State :: struct {
transient_clear_time : f32, // Time in seconds for the usual period to clear transient
transient_clear_elapsed : f32, // Time since last clear
job_system : JobSystemContext,
string_cache : StringCache,
input_data : [2]InputState,