Hi,
Are there any limitations on memory allocation within a WASM extension using V8 runtime? I am not able to allocate more than 10MB when storing in an array. I am able to allocate additional memory outside of an array though.
My code:
bool FilterRootContext::onStart(size_t) {
LOG_WARN("onStart");
size_t max_size_mb=1000;
size_t testedMemCapacityMB = -1;
size_t testedMemCapacityMB1 = -1;
if (max_size_mb == 0) { return 0;}
void *memblocks[max_size_mb];
void *memblocks1[max_size_mb];
int testedMemCapacity = 0;
int testedMemCapacity1 = 0;
do {
memblocks[testedMemCapacity] = malloc(2097152); // 2MB
} while (memblocks[testedMemCapacity] != nullptr && ++testedMemCapacity < max_size_mb);
testedMemCapacityMB = testedMemCapacity;
do {
memblocks1[testedMemCapacity1] = malloc(2097152); // 2MB
} while (memblocks1[testedMemCapacity1] != nullptr && ++testedMemCapacity1 < max_size_mb);
testedMemCapacityMB1 = testedMemCapacity1;
char* ptr =NULL;
if ((ptr =(char*)malloc(209715200)) == NULL) {
LOG_WARN(std::string("Additional Allocation failed ") );
} else {
LOG_WARN(std::string("Additional Allocation is successful ") );
}
for (int j = 0; j < testedMemCapacityMB; j++) {
free(memblocks[j]);
}
for (int j = 0; j < testedMemCapacityMB1; j++) {
free(memblocks1[j]);
}
LOG_WARN(std::string("Allocated: ") + std::to_string(testedMemCapacityMB));
LOG_WARN(std::string("Allocated1: ") + std::to_string(testedMemCapacityMB1));
return true;
}
Here is the log generated:
2021-09-07T15:59:09.700580Z warning envoy wasm wasm log my_root_id shipping-vm-id: [extensions/service-mesh/example-filter/filter.cc:29]::onStart() onStart
2021-09-07T15:59:09.700627Z warning envoy wasm wasm log my_root_id shipping-vm-id: [extensions/service-mesh/example-filter/filter.cc:52]::onStart() Additional Allocation is successful
2021-09-07T15:59:09.700631Z warning envoy wasm wasm log my_root_id shipping-vm-id: [extensions/service-mesh/example-filter/filter.cc:61]::onStart() Allocated: 5
2021-09-07T15:59:09.700636Z warning envoy wasm wasm log my_root_id shipping-vm-id: [extensions/service-mesh/example-filter/filter.cc:62]::onStart() Allocated1: 0
Can somebody please explain this behaviour?