Skip to content

Fix rb_gc_adjust_memory_usage double-counting#613

Open
omohokcoj wants to merge 1 commit into
bytecodealliance:mainfrom
omohokcoj:gc-stat
Open

Fix rb_gc_adjust_memory_usage double-counting#613
omohokcoj wants to merge 1 commit into
bytecodealliance:mainfrom
omohokcoj:gc-stat

Conversation

@omohokcoj

Copy link
Copy Markdown
Contributor

Memory wrapper tracked wasm memory via its own ManuallyTracked, but that memory lives in the Store and is already reported to Ruby by the store's TrackingResourceLimiter causing double-counting:

require "wasmtime"

pages = 200
bytes = pages * 65_536
store = Wasmtime::Store.new(Wasmtime::Engine.new)

before = GC.stat(:malloc_increase_bytes)
Wasmtime::Memory.new(store, min_size: pages)
delta = GC.stat(:malloc_increase_bytes) - before

puts "linear memory: %d bytes | reported to GC: %d bytes | %.1fx\n" % [bytes, delta, delta.to_f / bytes]

# output:  linear memory: 13107200 bytes | reported to GC: 26216600 bytes | 2.0x - double-counting

This PR removes redundant GC stats tracking from Memory that double-counted wasm memory in Ruby (since the store's resource limiter already reports it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant