Reduce default stack size from 5Mb to 1Mb See ChangeLog.md for rationale.
diff --git a/ChangeLog.md b/ChangeLog.md index 098dd9d..2c9fae8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md
@@ -23,6 +23,13 @@ 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
diff --git a/src/settings.js b/src/settings.js index 6b56225..bc9c905 100644 --- a/src/settings.js +++ b/src/settings.js
@@ -113,7 +113,7 @@ // 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 @@ -1506,7 +1506,7 @@ // 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]
diff --git a/tests/core/test_emmalloc_memory_statistics.cpp b/tests/core/test_emmalloc_memory_statistics.cpp index 4de5a5d..42750a3 100644 --- a/tests/core/test_emmalloc_memory_statistics.cpp +++ b/tests/core/test_emmalloc_memory_statistics.cpp
@@ -13,18 +13,18 @@ void *ptr3 = malloc(64*1024*1024); void *ptr4 = malloc(16*1024); void *ptr5 = malloc(2*1024*1024); - printf("%d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5)); + printf("valid allocs: %d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5)); free(ptr2); free(ptr4); - printf("%d\n", emmalloc_validate_memory_regions()); - printf("%zu\n", emmalloc_dynamic_heap_size()); - printf("%zu\n", emmalloc_free_dynamic_memory()); + 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("%zu\n", numFreeMemoryRegions); + printf("numFreeMemoryRegions: %zu\n", numFreeMemoryRegions); for(int i = 0; i < 32; ++i) printf("%zu ", freeMemorySizeMap[i]); printf("\n"); - printf("%zu\n", round_to_4k(emmalloc_unclaimed_heap_memory())); + printf("emmalloc_unclaimed_heap_memory : %zu\n", round_to_4k(emmalloc_unclaimed_heap_memory())); }
diff --git a/tests/core/test_emmalloc_memory_statistics.out b/tests/core/test_emmalloc_memory_statistics.out index 0daf8d7..23722c0 100644 --- a/tests/core/test_emmalloc_memory_statistics.out +++ b/tests/core/test_emmalloc_memory_statistics.out
@@ -1,7 +1,7 @@ -1 -0 -106971424 -4210892 -3 +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 -21999616 +emmalloc_unclaimed_heap_memory : 26193920
diff --git a/tests/core/test_emmalloc_trim.out b/tests/core/test_emmalloc_trim.out index daa3c04..5bdeb75 100644 --- a/tests/core/test_emmalloc_trim.out +++ b/tests/core/test_emmalloc_trim.out
@@ -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 \ No newline at end of file +unclaimed heap memory 5: 2108616704 +sbrk 5: 0x2502000
diff --git a/tests/core/test_memorygrowth_geometric_step.out b/tests/core/test_memorygrowth_geometric_step.out index 4cb463c..589e07e 100644 --- a/tests/core/test_memorygrowth_geometric_step.out +++ b/tests/core/test_memorygrowth_geometric_step.out
@@ -1,2 +1,2 @@ Heap size before allocation: 16777216 -Ptr: 1, value: 16843009, Heap size now: 101777408 (increase: 85000192 bytes) \ No newline at end of file +Ptr: 1, value: 16843009, Heap size now: 97583104 (increase: 80805888 bytes)
diff --git a/tests/test_other.py b/tests/test_other.py index 01cb3a9..f76c951 100644 --- a/tests/test_other.py +++ b/tests/test_other.py
@@ -2203,6 +2203,8 @@ '--pre-js', test_file('embind/test.pre.js'), '--post-js', test_file('embind/test.post.js'), '-s', 'WASM_ASYNC_COMPILATION=0', + # For some reason the default of 1Mb is not enough for these tests. + '-s', 'TOTAL_STACK=2Mb', '-s', 'IN_TEST_HARNESS'] + args, env=environ) @@ -5217,7 +5219,7 @@ # 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 [