okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
b585313
main
1/// Memory-pressure ordering depends on nondeterministic RSS in E2E. 2import albedo/daemon/reaper .{ type Candidate , Candidate , Limits } 3import gleam/list 4import gleeunit/should 5 6const limits = Limits ( idle_ms : 60_000 , budget_kb : 1000 , detached_ms : 30_000 ) 7 8fn pids ( victims : List ( Candidate )) -> List ( Int ) { 9list . map ( victims , fn ( victim : Candidate ) { victim . pid }) 10} 11 12pub fn attached_running_and_job_holding_kernels_are_never_released_test () -> Nil { 13[ 14// attached moments ago, however much it holds 15Candidate ( 1 , 0 , False , 0 , 100_000 ), 16// detached but working 17Candidate ( 2 , 600_000 , True , 0 , 100_000 ), 18// detached, idle past every limit, but a background job still runs 19Candidate ( 3 , 600_000 , False , 1 , 100_000 ), 20] 21|> reaper . victims ( limits ) 22|> should . equal ([]) 23} 24 25pub fn a_pool_over_budget_loses_the_longest_unattended_first_test () -> Nil { 26let victims = 27[ 28Candidate ( 1 , 31_000 , False , 0 , 600 ), 29Candidate ( 2 , 45_000 , False , 0 , 600 ), 30Candidate ( 3 , 35_000 , False , 0 , 600 ), 31] 32|> reaper . victims ( limits ) 33// 1800 held against a 1000 budget: the two quietest go, the freshest stays. 34victims |> pids |> should . equal ([ 2 , 3 ]) 35} 36 37pub fn memory_freed_by_the_idle_rule_counts_against_the_budget_test () -> Nil { 38let victims = 39[ Candidate ( 1 , 120_000 , False , 0 , 900 ), Candidate ( 2 , 31_000 , False , 0 , 600 )] 40|> reaper . victims ( limits ) 41// Releasing the expired kernel already brings the pool under budget. 42victims |> pids |> should . equal ([ 1 ]) 43}