Limit memory usage by all isolates

102 views
Skip to first unread message

Meir Shpilraien

unread,
May 9, 2023, 9:05:29 AM5/9/23
to v8-dev
Hi

I know I can limit the memory used by a single isolate. But assuming my application creates more than one isolate. Is there a way to put a global limit such that the memory used by all isolates combined will not bypass this limit?

Thanks.

Ben Noordhuis

unread,
May 10, 2023, 8:37:40 PM5/10/23
to v8-...@googlegroups.com
On Tue, May 9, 2023 at 3:05 PM Meir Shpilraien <me...@redis.com> wrote:
>
> I know I can limit the memory used by a single isolate. But assuming my application creates more than one isolate. Is there a way to put a global limit such that the memory used by all isolates combined will not bypass this limit?

V8 has no such mechanism built in.

Users of V8 have cobbled together various solutions but they
ultimately all involve tracking isolates and forcing garbage
collection (isolate->LowMemoryNotification()) or terminating them when
they exceed a threshold.

If crashing is okay for your use case, implementing your own
PageAllocator could work; see include/v8-platform.h.

Meir Shpilraien

unread,
Aug 8, 2023, 8:34:52 AM8/8/23
to v8-dev
Thanks,

I was looking at the page allocator but it does not seems like the memory for isolate is allocated from it. Is it true or did I miss something?
In general I do not want to fail the allocation but only to know how much was allocated so I can take actions when the memory usage become to much (for example, I can try stop the JS code using terminate TerminateExecution). Currently I investigate 3 options:

1. Start each isolate with small memory limit and increase it in small junks  when I get the near OOM callback. It works pretty nice, the only issue I saw is when the required memory is larger than the chunk that I use to increase the limit, V8 will still abort the processes, its not always the case but I did see it happened in certain cases. My question: does it make sense to provide the amount of memory required by the isolate to the near OOM callback, so I will know how much I need to increase the limit so that the V8 will not abort?

2. Avoid setting memory limit and just periodically check the usage and take actions if the usage is to high, but this can be very inaccurate.

3. I saw there is an API for third_party_heap that I can maybe implement and track the total memory usage, maybe this is a good direction to investigate.

Personaly I would prefer option 1, I already saw that it works nicely and I just need to know how much the limit should be increased to avoid V8 abort. Wonder what you think, maybe there are other options I did not considered?

Thanks a lot for the help and sorry it took time to reply.

Meir.

Reply all
Reply to author
Forward
0 new messages