Skip to content

Fix rb_gc_adjust_memory_usage double-counting - #613

Merged
saulecabrera merged 1 commit into
bytecodealliance:mainfrom
omohokcoj:gc-stat
Jun 30, 2026
Merged

Fix rb_gc_adjust_memory_usage double-counting#613
saulecabrera merged 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).

@saulecabrera saulecabrera left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@saulecabrera
saulecabrera merged commit a1acd5c into bytecodealliance:main Jun 30, 2026
11 checks passed
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.

2 participants