Commit c4e66e3b authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm] Add multiple retries to reserve wasm memory

The current memory reservation approach for wasm memory tries to reserve
upto the maximum, and only reserves initial if the maximum reservation  fails.
Add multiple retries with a smaller upper limit so that calls to grow
have a higher probability of succeeding.

Bug: v8:10519
Change-Id: Ice5b4c826ff993c9da7292e1b24a42a72306c098
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2259720
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68499}
parent 2cd26485
......@@ -428,10 +428,20 @@ std::unique_ptr<BackingStore> BackingStore::AllocateWasmMemory(
auto backing_store =
TryAllocateWasmMemory(isolate, initial_pages, maximum_pages, shared);
if (!backing_store && maximum_pages > initial_pages) {
// If reserving {maximum_pages} failed, try with maximum = initial.
if (maximum_pages == initial_pages) {
// If initial pages, and maximum are equal, nothing more to do return early.
return backing_store;
}
// Retry with smaller maximum pages at each retry.
const int kAllocationTries = 3;
auto delta = (maximum_pages - initial_pages) / (kAllocationTries + 1);
size_t sizes[] = {maximum_pages - delta, maximum_pages - 2 * delta,
maximum_pages - 3 * delta, initial_pages};
for (size_t i = 0; i < arraysize(sizes) && !backing_store; i++) {
backing_store =
TryAllocateWasmMemory(isolate, initial_pages, initial_pages, shared);
TryAllocateWasmMemory(isolate, initial_pages, sizes[i], shared);
}
return backing_store;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment