Fix the memory leak that filled RAM and swap; launch monitor, memory log
wasmhost leaked the arguments of every host call. wt_stub.c handed them to the MoonBit dispatcher expecting it to own them, but the compiler borrowed the parameter, so nothing released them (about 600 kB/s in a test with one busy terminal; a long session reached over 16 GB resident plus swap). MoonBit now allocates the buffer and C copies into it. Also: - Unannotated pointer FFI parameters default to #owned, and none of these C functions released theirs, including the native KMS present (a whole frame each). Annotated #borrow; the wasmhost build now fails on that warning, which --warn-list -a had hidden. - Watched launches forked the whole compositor, and each monitor kept a snapshot of its heap for the app's lifetime. It now posix_spawns a fresh copy of the binary that takes over before main. - The host logs memory, window buffers and images once a minute. - chandra-session keeps the previous log as session.log.1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hj5m35Lj6Rt9vwwLGZ
This commit is contained in:
1 parent
44688453d7
commit
ada9850b8d
11 files changed
+211
-75
No files matched your search
+9
-3
@@ -4,7 +4,11 @@
|
||||
/// component reach the one handler given to `set_handler` as (id, arguments).
|
||||
|
||||
///|
|
||||
extern "C" fn c_set_dispatch(f : FuncRef[(Int, Bytes) -> Bytes]) = "wt_set_dispatch"
|
||||
extern "C" fn c_set_dispatch(f : FuncRef[(Int, Int) -> Bytes]) = "wt_set_dispatch"
|
||||
|
||||
///|
|
||||
#borrow(out)
|
||||
extern "C" fn c_take_args(out : Bytes) = "wt_take_args"
|
||||
|
||||
///|
|
||||
extern "C" fn c_last_error() -> Bytes = "wt_last_error"
|
||||
@@ -33,7 +37,9 @@ let handler : Ref[(Int, Array[Val]) -> Array[Val]] = Ref(fn(id, _) {
|
||||
})
|
||||
|
||||
///|
|
||||
fn dispatch(id : Int, args : Bytes) -> Bytes {
|
||||
fn dispatch(id : Int, len : Int) -> Bytes {
|
||||
let args = Bytes::make(len, 0)
|
||||
c_take_args(args)
|
||||
encode((handler.val)(id, decode(args)))
|
||||
}
|
||||
|
||||
@@ -52,7 +58,7 @@ pub fn load(path : String) -> Result[Unit, String] {
|
||||
if c_init() != 0 {
|
||||
return Err(last_error())
|
||||
}
|
||||
c_set_dispatch(fn(id, args) { dispatch(id, args) })
|
||||
c_set_dispatch(fn(id, len) { dispatch(id, len) })
|
||||
if c_load(cstr(path)) != 0 {
|
||||
return Err(last_error())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user