Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,14 @@ See docs/process.md for more on how version tagging works.

2.0.21: 05/18/2021
------------------
------
- Default shadow stack size used by emscripten reduced from 5Mb to 1Mb. Anyone
running into issues can restore the old size using `-sTOTAL_STACK=5Mb`. Since
windows has max stack of 1Mb and since WebAssembly stack usage should be less
than on native platforms (since its only used for address taken values) it
seems like 1Mb might still be on the high side here. For reference, llvm
(`wasm-ld`) use 64kb as the default stack size. `DEFAULT_PTHREAD_STACK_SIZE`
was also reduced from 2Mb to 1Mb to match primary stack.
- Options such as EXPORTED_FUNCTIONS that can take a response file containing
list of symbols can now use a simple one-symbol-per-line format. This new
format is much simpler and doesn't require commas between symbols, opening
Expand Down
4 changes: 2 additions & 2 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var MEM_INIT_METHOD = false;
// assertions are on, we will assert on not exceeding this, otherwise,
// it will fail silently.
// [link]
var TOTAL_STACK = 5*1024*1024;
var TOTAL_STACK = 1*1024*1024;

// What malloc()/free() to use, out of
// * dlmalloc - a powerful general-purpose malloc
Expand Down Expand Up @@ -1582,7 +1582,7 @@ var PTHREAD_POOL_DELAY_LOAD = false;
// those that have their addresses taken, or ones that are too large to fit as
// local vars in wasm code.
// [link]
var DEFAULT_PTHREAD_STACK_SIZE = 2*1024*1024;
var DEFAULT_PTHREAD_STACK_SIZE = 1*1024*1024;

// True when building with --threadprofiler
// [link]
Expand Down
47 changes: 23 additions & 24 deletions test/core/test_emmalloc_memory_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@
#include <emscripten/emmalloc.h>

template<typename T>
T round_to_4k(T val) {
return (T)(((size_t)val + 4095) & ~4095);
T round_to_4k(T val){
return (T)(((size_t)val + 4095) & ~4095);
}

int main() {
void *ptr = malloc(32*1024*1024);
void *ptr2 = malloc(4*1024*1024);
void *ptr3 = malloc(64*1024*1024);
void *ptr4 = malloc(16*1024);
void *ptr5 = malloc(2*1024*1024);
printf("%ld\n", (long)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
free(ptr2);
free(ptr4);
printf("validate_memory_regions: %d\n", emmalloc_validate_memory_regions());
printf("dynamic_heap_size: %zu\n", emmalloc_dynamic_heap_size());
printf("free_dynamic_memory: %zu\n", emmalloc_free_dynamic_memory());
size_t numFreeMemoryRegions = 0;
size_t freeMemorySizeMap[32];
numFreeMemoryRegions = emmalloc_compute_free_dynamic_memory_fragmentation_map(freeMemorySizeMap);
printf("numFreeMemoryRegions: %zu\n", numFreeMemoryRegions);
for (int i = 0; i < 32; ++i) {
printf("%zu ", freeMemorySizeMap[i]);
}
printf("\n");
printf("unclaimed_heap_memory: %zu\n", round_to_4k(emmalloc_unclaimed_heap_memory()));
return 0;
int main()
{
void *ptr = malloc(32*1024*1024);
void *ptr2 = malloc(4*1024*1024);
void *ptr3 = malloc(64*1024*1024);
void *ptr4 = malloc(16*1024);
void *ptr5 = malloc(2*1024*1024);
printf("valid allocs: %d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
free(ptr2);
free(ptr4);
printf("emmalloc_validate_memory_regions: %d\n", emmalloc_validate_memory_regions());
printf("emmalloc_dynamic_heap_size : %zu\n", emmalloc_dynamic_heap_size());
printf("emmalloc_free_dynamic_memory : %zu\n", emmalloc_free_dynamic_memory());
size_t numFreeMemoryRegions = 0;
size_t freeMemorySizeMap[32];
numFreeMemoryRegions = emmalloc_compute_free_dynamic_memory_fragmentation_map(freeMemorySizeMap);
printf("numFreeMemoryRegions: %zu\n", numFreeMemoryRegions);
for(int i = 0; i < 32; ++i)
printf("%zu ", freeMemorySizeMap[i]);
printf("\n");
printf("emmalloc_unclaimed_heap_memory : %zu\n", round_to_4k(emmalloc_unclaimed_heap_memory()));
}
10 changes: 5 additions & 5 deletions test/core/test_emmalloc_memory_statistics.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1
validate_memory_regions: 0
dynamic_heap_size: 106971424
free_dynamic_memory: 4210892
valid allocs: 1
emmalloc_validate_memory_regions: 0
emmalloc_dynamic_heap_size : 106971424
emmalloc_free_dynamic_memory : 4210892
numFreeMemoryRegions: 3
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
unclaimed_heap_memory: 21999616
emmalloc_unclaimed_heap_memory : 26193920
28 changes: 14 additions & 14 deletions test/core/test_emmalloc_trim.out
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
heap size: 134217728
dynamic heap 0: 4096
free dynamic memory 0: 4096
unclaimed heap memory 0: 2142171136
sbrk 0: 0x502000
unclaimed heap memory 0: 2146365440
sbrk 0: 0x102000
1
dynamic heap 1: 37752832
free dynamic memory 1: 4096
unclaimed heap memory 1: 2104422400
sbrk 1: 0x2902000
unclaimed heap memory 1: 2108616704
sbrk 1: 0x2502000
1st trim: 1
dynamic heap 1: 37752832
free dynamic memory 1: 0
unclaimed heap memory 1: 2104422400
sbrk 1: 0x2902000
unclaimed heap memory 1: 2108616704
sbrk 1: 0x2502000
2nd trim: 0
dynamic heap 2: 37752832
free dynamic memory 2: 0
unclaimed heap memory 2: 2104422400
sbrk 2: 0x2902000
unclaimed heap memory 2: 2108616704
sbrk 2: 0x2502000
3rd trim: 1
dynamic heap 3: 33656832
free dynamic memory 3: 102400
unclaimed heap memory 3: 2104422400
sbrk 3: 0x2902000
unclaimed heap memory 3: 2108616704
sbrk 3: 0x2502000
4th trim: 0
dynamic heap 4: 33656832
free dynamic memory 4: 102400
unclaimed heap memory 4: 2104422400
sbrk 4: 0x2902000
unclaimed heap memory 4: 2108616704
sbrk 4: 0x2502000
5th trim: 1
dynamic heap 5: 33558528
free dynamic memory 5: 0
unclaimed heap memory 5: 2104422400
sbrk 5: 0x2902000
unclaimed heap memory 5: 2108616704
sbrk 5: 0x2502000
2 changes: 1 addition & 1 deletion test/core/test_memorygrowth_geometric_step.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Heap size before allocation: 16777216
Ptr: 1, value: 16843009, Heap size now: 101777408 (increase: 85000192 bytes)
Ptr: 1, value: 16843009, Heap size now: 97583104 (increase: 80805888 bytes)
4 changes: 3 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,8 @@ def test_embind(self, extra_args):
'--pre-js', test_file('embind/test.pre.js'),
'--post-js', test_file('embind/test.post.js'),
'-sWASM_ASYNC_COMPILATION=0',
# For some reason the default of 1Mb is not enough for these tests.
'-sTOTAL_STACK=2Mb',
'-sIN_TEST_HARNESS'] + args)

if '-sDYNAMIC_EXECUTION=0' in args:
Expand Down Expand Up @@ -5748,7 +5750,7 @@ def test_massive_alloc(self, wasm):
# just care about message regarding allocating over 1GB of memory
output = self.run_js('a.out.js')
if not wasm:
self.assertContained('Warning: Enlarging memory arrays, this is not fast! 16777216,1473314816\n', output)
self.assertContained('Warning: Enlarging memory arrays, this is not fast! 16777216,1469120512\n', output)

def test_failing_alloc(self):
for pre_fail, post_fail, opts in [
Expand Down