Alexey Zolotarev
11/18/2024, 1:51 PMSvyatoslav Kuzmich [JB]
11/18/2024, 2:11 PMinitial = variable_static_data_size + 1
max = unlimited
Why would you want to change this?Svyatoslav Kuzmich [JB]
11/18/2024, 2:14 PMAlexey Zolotarev
11/18/2024, 2:20 PMAlexey Zolotarev
11/18/2024, 2:27 PMWasmtime
as a host runtime and Kotlin-compiled wasm-module. Currently after just a handful of small 16-bytes allocations on the Kotlin side, I encounter an GC heap out of memory
error and it is not clear if it is a Kotlin issue, a runtime issue or it is some sort bug in my code. So I wanted to check if increasing the initial memory might help - memory doesn't grow during the test I run, it stays at 1 page.
For the reference here is the smallest guest function that reproduces the issue mentioned after about 10 calls:
@OptIn(UnsafeWasmMemoryApi::class)
@WasmExport("test")
fun memSimple4IntsVoid(callId: ULong, dataSize: Int) {
withScopedMemoryAllocator { allocator ->
val ptr = allocator.allocate(dataSize)
val result = requestHostToStoreArguments(callId, ptr.address)
// ... error handling
val x = ptr.loadInt()
println("Received $x")
}
}
Svyatoslav Kuzmich [JB]
11/18/2024, 2:46 PMGC heap out of memory
looks a lot like hitting a runtime-defined limit.
Kotlin uses linear memory only for storing some constant data, and for temporary allocations to exchange data with outside world. I was guessing that setting custom linear memory limits would not be as important as for non-WasmGC languages. I’m curious to see if programs could be improved by changing them.Alexey Zolotarev
11/18/2024, 2:54 PMI've run the same benchmark with a guest compiled withlooks a lot like hitting a runtime-defined limit.GC heap out of memory
AssemblyScript
and I'm not hitting memory errors even when the memory grows to 2 GB. Of course, AssemblyScript
doesn't use Wasm GC proposal, all allocations are made with the built-in _malloc
function. But at least it shows that the runtime doesn't limit the memory size. With Kotlin I don't see the memory growing from the 1 initial page and encounter this error after just a few allocations.Alexey Zolotarev
11/18/2024, 2:57 PMwithScopedMemoryAllocator
lambda.Svyatoslav Kuzmich [JB]
11/18/2024, 3:23 PMWith Kotlin I don’t see the memory growing from the 1 initial page and encounter this error after just a few allocations.
GC heap
error is not related to linear memory. It is normal that you can overflow Wasmtime’s GcHeap
without growing linear memory at all.Alexey Zolotarev
11/18/2024, 3:35 PMSvyatoslav Kuzmich [JB]
11/18/2024, 3:45 PMGcHeap
is tied to wasmtime::Store
Alexey Zolotarev
11/18/2024, 3:55 PMmemory.grow
in that proposal so I guess the runtime should manage its size automatically? Do you by any chance know if other runtimes that support Wasm GC (V8
?) allow configuring this? Can't find anything relevant in docs.Svyatoslav Kuzmich [JB]
11/18/2024, 4:01 PMDaniel
11/19/2024, 12:18 PMAlexey Zolotarev
11/19/2024, 12:21 PMAlexey Zolotarev
11/19/2024, 12:35 PMDaniel
11/20/2024, 12:49 AMAlexey Zolotarev
11/20/2024, 12:56 PM