Ulan, Thanks for the detailed answer.
I have a question on the caveats you listed: >> "*if the heap limit is extended by small number, then the application may still crash with OOM. For example, if the application wants to allocate 10MB, but the limit is extended by 5MB*." << Question 1: In the "AddNearHeapLimitCallback", I don't know what is the memory size requested. So, how can I safely increase the heap limit to avoid OOM? Question 2: Even though, I plan to terminate the isolate execution( isolate->TerminateExecution()), I need to increase the heap limit to avoid crash. In such a case(TerminateExecution), is there a way I can avoid crash without increasing the limit(say, by returning same or lesser memory limit as return code from MyNearHeapLimitCallback)? Thanks, Prakash On Wednesday, June 6, 2018 at 2:23:26 PM UTC+5:30, Ulan Degenbaev wrote: > > Hi Prakash, > > I added the AddNearHeapLimitCallback API. The provided callback is > invoked when V8's heap is close to the heap limit specified by the > ResourceConstraints::max_old_space_size during V8 setup. > > If the callback extends the heap limit by returning a number greater then > the provided current_heap_limit, then the application will continue running > until the new heap limit is reached. At that point the callback is invoked > again. > If the callback returns the current_heap_limit (or smaller number) then > the application will crash with OOM if it continues allocating. > > The initial_heap_limit is the original limit that V8 was set up with. It > is provided for convenience, so that the callback can figure out if it has > already extended the limit without maintaining state. > > The callback is called on the same thread as the running JavaScript. So > during callback invocation JavaScript is paused. > > Overall, I think the API should work for your case. > > Caveats: > - the callback may be invoked multiple times. > - if the callback does not extend the heap limit, then the application is > not guaranteed to OOM. For example, if the application stops allocating and > never reaches the heap limit. > - if the heap limit is extended by small number, then the application may > still crash with OOM. For example, if the application wants to allocate > 10MB, but the limit is extended by 5MB. > - if V8 runs out of system memory without reaching the heap limit, then it > will crash with OOM without invoking the callback. For example, if > malloc/mmap fails there is no way to safely continue execution. > > I hope that answers your questions. Please let me know if I > missed anything. > > Cheers, > Ulan. > > On Tue, Jun 5, 2018 at 11:28 AM, Prakash Bailkeri <prakash....@gmail.com > <javascript:>> wrote: > >> Thanks for the response. >> >> Any advice on usage of "AddNearHeapLimitCallback"? [Please see my sample >> program] >> >> Thanks, Prakash >> >> >> -- >> -- >> v8-users mailing list >> v8-u...@googlegroups.com <javascript:> >> http://groups.google.com/group/v8-users >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to v8-users+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.