Max heap size (wildly) exceeded?

33 views
Skip to first unread message

Tudor Bosman

unread,
Aug 15, 2022, 9:42:35 PM8/15/22
to v8-dev
Hello,

This is a noob question, but I'm trying to set a low heap size (4MiB) for an embedded application and I can't seem to succeed.

I also tried setting both a near limit callback and a GC epilogue and they don't get called.

I am initializing the Isolate with constraints set via ConfigureDefaultsFromHeapSize with both initial and max heap sizes set to 4MiB.

I'm trying to run a script that has just "a = Array(20000000).fill(2)".

Heap statistics right after Isolate initialization:

total_heap=962560 total_heap_executable=524288 total_physical=438272 total_available=4246240 total_global_handles=0 used_heap=371424 heap_limit=4194304 malloced=16460 external=0 peak_malloced=8192 native_ctx=0 detached_ctx=0 zap_garbage=0

Heap statistics right after running the script:

heap total_heap=41496576 total_heap_executable=524288 total_physical=40568044 total_available=485100 total_global_handles=8192 used_heap=40900828 heap_limit=4194304 malloced=16460 external=0 peak_malloced=49208 native_ctx=1 detached_ctx=0 zap_garbage=0

Note that the total heap size is 40 MiB, despite the limit being 4 MiB.

Am I doing something obviously wrong? This is v8 10.0.139.15.

Thanks,
-Tudor.

Claudia

unread,
Aug 22, 2022, 10:28:44 PM8/22/22
to v8-dev
20000000 bytes = just over 19 MiB BTW. And that's assuming it's all bytes.

In reality, it'd take closer to 4x at minimum, as these would be stored as 32-bit integers (or 4 bytes per element), and that would come out to about 76.3 MiB. If that's even completing, that's a bug in V8 IMHO, and a potential security bug at that.

Jakob Kummerow

unread,
Aug 23, 2022, 5:58:26 AM8/23/22
to v8-dev
potential security bug

How so?

Reply all
Reply to author
Forward
0 new messages