If you are looking to track Wasm allocations, there is a counter on the 
Isolate that wasm memory allocations are registered 
<https://cs.chromium.org/chromium/src/v8/src/wasm/wasm-memory.cc?q=wasm-memory.cc&sq=package:chromium&dr&l=153>
 
with - V8.WasmAddressSpaceUsageMiB. The page allocator is the catch all for 
allocations, so that should work too. 

For GetHeapStatistics 
<https://cs.chromium.org/chromium/src/v8/src/api.cc?dr&q=GetHeapSta&sq=package:chromium&g=0&l=8365>(),
 
WasmMemory is accounted for under malloced memory, could you elaborate on 
the discrepancies that you are seeing? 

Ideally, Memory.Grow should honor the same resource constraints that a 
JSArrayBuffer allocation does, because it either adjusts the externally 
allocated memory, 
<https://cs.chromium.org/chromium/src/v8/src/wasm/wasm-objects.cc?dr&q=GrowMem&sq=package:chromium&g=0&l=911>
 
or allocates a new ArrayBuffer. The WasmMemoryTracker tracks wasm 
allocations 
<https://cs.chromium.org/chromium/src/v8/src/wasm/wasm-memory.cc?dr&q=wasm-memory.cc&sq=package:chromium&g=0&l=29>,
 
apart from the isolate counters, there is no public API for the WasmEngine 
right now. 

On Wednesday, September 12, 2018 at 4:14:17 PM UTC-7, [email protected] 
wrote:
>
> Looking at the code, it looks like --wasm_max_mem_pages limits the size of 
> a particular Memory object, but a script can always allocate multiple 
> objects / create multiple instances. I need to limit the script's total 
> memory usage...
>
> I do need to track and limit per-isolate. But maybe I can use 
> PageAllocator combined with keeping track of the current isolate using 
> thread-locals? Or might it be called in background threads?
>
> -Kenton
>
> On Tuesday, September 11, 2018 at 11:19:13 AM UTC-7, Ben Noordhuis wrote:
>>
>> On Tue, Sep 11, 2018 at 6:34 PM, 'Kenton Varda' via v8-users 
>> <[email protected]> wrote: 
>> > Hi v8-users, 
>> > 
>> > I noticed that WASM seems to ignore the ResourceConstraints I've set on 
>> my 
>> > isolate -- a WebAssembly.Memory object can grow to far beyond the heap 
>> > constraint I've set, and I don't see any constraint specific to WASM. 
>> The JS 
>> > code can, of course, specify a maximum memory limit when creating the 
>> Memory 
>> > object, but that's an API exposed to the script. As as embedder, I need 
>> to 
>> > enforce my own constraint. 
>> > 
>> > Relatedly, it appears that GetHeapStatistics() does not include WASM 
>> memory 
>> > in the counts. As an embedder I need to keep track of the memory an 
>> isolate 
>> > has allocated. 
>> > 
>> > I've searched through v8.h and haven't been able to find any alternate 
>> APIs 
>> > for these. Is there one I missed, or is this something I'll need to add 
>> > myself? 
>> > 
>> > -Kenton 
>>
>> You should be able to control it with the `--wasm_max_mem_pages=...` 
>> flag (expressed in multiples of 64k) that you can set with 
>> `v8::V8::SetFlagsFromString()`.  I don't think there is currently any 
>> other way to configure it. 
>>
>> WASM allocations should be observable when you return a custom 
>> `v8::PageAllocator*` from `v8::Platform::GetPageAllocator()`.  Maybe 
>> not ideal but hopefully workable. 
>>
>> You can probably also limit memory growth that way, by returning 
>> nullptr when it's past a threshold, although not on a per-isolate 
>> basis. 
>>
>

-- 
-- 
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to