Why UnregisterMemory in PreFreeMemory instead of PerformFreeMemory ?

36 views
Skip to first unread message

Jianxiao Lu

unread,
Dec 22, 2021, 2:17:20 AM12/22/21
to v8-dev
In MemoryAllocator, there is a member variable size_ to record current committed memory size..
The size_ increase after allocate or commit a VirtualMemory.
From the perspective of symmetry, the size_ should decrease after free or uncommit a VirtualMemory .
But in fact it's in PreFreeMemory.
When free pages with mode kPooledAndQueue, the size_ will decrease during UnregisterMemory during PreFreeMemory, but the MemoryChunk is not really freed or uncommitted.

I think the decrease of size_ should be in PerformFreeMemory.
I wonder what is the purpose of the current design?

dinf...@chromium.org

unread,
Jan 11, 2022, 9:22:59 AM1/11/22
to v8-dev
Hi,

this is indeed surprising. I suppose the main reason for this behavior is that we record memory size before and after the GC (see https://source.chromium.org/chromium/chromium/src/+/main:v8/src/heap/gc-tracer.cc;l=330). If we would decrement size_ some time after that point, we wouldn't see that memory size decreases after a GC.

Regards,
Dominik

Jianxiao Lu

unread,
Jan 13, 2022, 7:49:42 PM1/13/22
to v8-dev
Thanks for the explanation, it make sense to me, and I find that the MemoryAllocator is refactored, it's readability is better now.

Regards,
Jianxiao

Reply all
Reply to author
Forward
0 new messages