-
Hi, I am trying to profile the memory usage of a Unity application. To do this I hook When I run our application though, the heap size grows well (100's of Mb) in advance of the tracked allocations. (To be clear, Unity uses managed code which I believe is transcoded to C++ from CLR bytecode, and then given to Emscripten) My question is, is there any mechanism to grow or allocate from the heap outside of the exported (e.g. a non-obvious internal function, or maybe some way for the CLR GC to manage the heap alongside |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
All memory allocations need to go through the single allocator since there is only one single contiguous heap region. How are you measuring this memory growth? Are you building with Are you talking about the actually wasm memory growing? i.e. are building with ALLOW_MEMORY_GROWTH and seeing the actual Wasm memory object growing? Or are you talking about memory usage withing the heap managed by the allocator (i.e. dlmalloc?) |
Beta Was this translation helpful? Give feedback.
-
Note that there is a trace API that can help with this: https://emscripten.org/docs/api_reference/trace.h.html Otherwise, you can manually hook |
Beta Was this translation helpful? Give feedback.
-
Thanks for the replies.
So far I have been hooking For example, here is the
The aim is to accurately track memory consumption to optimise our application that currently runs out of memory unpredictably. (Though I wasn't able to find
Thank you! I have made this work in our Unity application by using the This is an example capture, From what I understand, The Allocation Summary figures seem very low compared to the Memory Usage figures. The Allocation figures match the hooks I place in the WASM. Fragmentation is about 82%. There is a discrepancy of about 600 Mb. In these tests Looking at the WAT, the only places
Here is that function,
I need to continue to look into it but it looks like the GC might be interacting with the chunk linked list, bypassing the (I would guess interacting with the list, rather than just allocating and doing its own thing, since the first call just gets the current location, and surely trying to grab blocks of memory inside the heap throughout the program lifetime would break |
Beta Was this translation helpful? Give feedback.
-
Some questions:
In emscripten, there is only a single sbrk pointer and only one allocator should ever use it. If you are building a GC that uses sbkr() I don't think you can use Here are some useful APIs:
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I've found the implementation of
It looks to me as if it is trying to get more memory from process via It is not just at start-up either, but seems to be called while
From what I can tell, That seems to solve the confusion then: there is another allocator, just not known to Emscripten because Unity put it there. (I can imagine this is a nightmare for fragmentation however!) Thank you for all the pointers! |
Beta Was this translation helpful? Give feedback.
Hi,
I've found the implementation of
GC_unix_sbrk_get_mem
. (Unity seems to be using BoehmGC)