STW
This commit is contained in:
+21
-9
@@ -11,7 +11,7 @@ use fix_builtins::{BUILTINS, BuiltinId};
|
||||
use fix_codegen::InstructionPtr;
|
||||
use fix_common::StringId;
|
||||
use fix_error::{Error, Result, Source};
|
||||
use gc_arena::arena::CollectionPhase;
|
||||
use gc_arena::metrics::Pacing;
|
||||
use gc_arena::{Arena, Collect, Gc, Mutation, RefLock, Rootable};
|
||||
use hashbrown::HashMap;
|
||||
use num_enum::TryFromPrimitive;
|
||||
@@ -485,6 +485,20 @@ enum Action {
|
||||
LoadFile(PendingLoad),
|
||||
}
|
||||
|
||||
/// Compute initial heap size mirroring CppNix's strategy: 25% of physical RAM,
|
||||
/// clamped to [32 MiB, 384 MiB]. Used as `Pacing::min_sleep` so the collector
|
||||
/// defers the first cycle until the heap reaches this size.
|
||||
fn initial_heap_size() -> usize {
|
||||
const MIN_SIZE: usize = 32 * 1024 * 1024;
|
||||
const MAX_SIZE: usize = 384 * 1024 * 1024;
|
||||
|
||||
let mut sys = sysinfo::System::new();
|
||||
sys.refresh_memory();
|
||||
let total = sys.total_memory() as usize;
|
||||
let quarter = total / 4;
|
||||
quarter.clamp(MIN_SIZE, MAX_SIZE)
|
||||
}
|
||||
|
||||
impl Vm<'_> {
|
||||
pub fn run<C: VmContext>(
|
||||
ctx: &mut C,
|
||||
@@ -493,8 +507,10 @@ impl Vm<'_> {
|
||||
) -> Result<fix_common::Value> {
|
||||
let (code, runtime) = ctx.split();
|
||||
let mut arena: Arena<Rootable![Vm<'_>]> = Arena::new(|mc| Vm::new(force_mode, mc, runtime));
|
||||
|
||||
const COLLECTOR_GRANULARITY: f64 = 1024.0;
|
||||
arena.metrics().set_pacing(Pacing {
|
||||
min_sleep: initial_heap_size(),
|
||||
..Pacing::STOP_THE_WORLD
|
||||
});
|
||||
|
||||
let mut pc = ip.0;
|
||||
loop {
|
||||
@@ -502,12 +518,8 @@ impl Vm<'_> {
|
||||
match arena.mutate_root(|mc, root| root.dispatch_batch(bytecode, runtime, pc, mc)) {
|
||||
Action::Continue { pc: new_pc } => {
|
||||
pc = new_pc;
|
||||
if arena.metrics().allocation_debt() > COLLECTOR_GRANULARITY {
|
||||
if arena.collection_phase() == CollectionPhase::Sweeping {
|
||||
arena.collect_debt();
|
||||
} else if let Some(marked) = arena.mark_debt() {
|
||||
marked.start_sweeping();
|
||||
}
|
||||
if arena.metrics().allocation_debt() > 0.0 {
|
||||
arena.finish_cycle();
|
||||
}
|
||||
}
|
||||
Action::LoadFile(load) => {
|
||||
|
||||
Reference in New Issue
Block a user