Skip to content

Commit 29efc0b

Browse files
committed
Reduce default stack size from 5Mb to 1Mb
See ChangeLog.md for rationale.
1 parent 33cbb24 commit 29efc0b

7 files changed

+39
-30
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ See docs/process.md for more on how version tagging works.
2020

2121
2.0.21
2222
------
23+
- Default shadow stack size used by emscripten reduced from 5Mb to 1Mb. Anyone
24+
running into issues can restore the old size using `-sTOTAL_STACK=5Mb`. Since
25+
windows has max stack of 1Mb and since WebAssembly stack usage should be less
26+
than on native platforms (since its only used for address taken values) it
27+
seems like 1Mb might still be on the high side here. For reference, llvm
28+
(`wasm-ld`) use 64kb as the default stack size. `DEFAULT_PTHREAD_STACK_SIZE`
29+
was also reduced from 2Mb to 1Mb to match primary stack.
2330
- The WebAssembly linker (`wasm-ld`) now performes string tail merging on any
2431
static string data in your program. This has long been part of the native
2532
ELF linker and should not be observable in well-behaved programs. This

src/settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var MEM_INIT_METHOD = 0;
113113
// assertions are on, we will assert on not exceeding this, otherwise,
114114
// it will fail silently.
115115
// [link]
116-
var TOTAL_STACK = 5*1024*1024;
116+
var TOTAL_STACK = 1*1024*1024;
117117

118118
// What malloc()/free() to use, out of
119119
// * dlmalloc - a powerful general-purpose malloc
@@ -1508,7 +1508,7 @@ var PTHREAD_POOL_DELAY_LOAD = 0;
15081508
// those that have their addresses taken, or ones that are too large to fit as
15091509
// local vars in wasm code.
15101510
// [link]
1511-
var DEFAULT_PTHREAD_STACK_SIZE = 2*1024*1024;
1511+
var DEFAULT_PTHREAD_STACK_SIZE = 1*1024*1024;
15121512

15131513
// True when building with --threadprofiler
15141514
// [link]

tests/core/test_emmalloc_memory_statistics.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ int main()
1313
void *ptr3 = malloc(64*1024*1024);
1414
void *ptr4 = malloc(16*1024);
1515
void *ptr5 = malloc(2*1024*1024);
16-
printf("%d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
16+
printf("valid allocs: %d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
1717
free(ptr2);
1818
free(ptr4);
19-
printf("%d\n", emmalloc_validate_memory_regions());
20-
printf("%zu\n", emmalloc_dynamic_heap_size());
21-
printf("%zu\n", emmalloc_free_dynamic_memory());
19+
printf("emmalloc_validate_memory_regions: %d\n", emmalloc_validate_memory_regions());
20+
printf("emmalloc_dynamic_heap_size : %zu\n", emmalloc_dynamic_heap_size());
21+
printf("emmalloc_free_dynamic_memory : %zu\n", emmalloc_free_dynamic_memory());
2222
size_t numFreeMemoryRegions = 0;
2323
size_t freeMemorySizeMap[32];
2424
numFreeMemoryRegions = emmalloc_compute_free_dynamic_memory_fragmentation_map(freeMemorySizeMap);
25-
printf("%zu\n", numFreeMemoryRegions);
25+
printf("numFreeMemoryRegions: %zu\n", numFreeMemoryRegions);
2626
for(int i = 0; i < 32; ++i)
2727
printf("%zu ", freeMemorySizeMap[i]);
2828
printf("\n");
29-
printf("%zu\n", round_to_4k(emmalloc_unclaimed_heap_memory()));
29+
printf("emmalloc_unclaimed_heap_memory : %zu\n", round_to_4k(emmalloc_unclaimed_heap_memory()));
3030
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
1
2-
0
3-
106971424
4-
4210892
5-
3
1+
valid allocs: 1
2+
emmalloc_validate_memory_regions: 0
3+
emmalloc_dynamic_heap_size : 106971424
4+
emmalloc_free_dynamic_memory : 4210892
5+
numFreeMemoryRegions: 3
66
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
7-
21999616
7+
emmalloc_unclaimed_heap_memory : 26193920

tests/core/test_emmalloc_trim.out

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
heap size: 134217728
22
dynamic heap 0: 4096
33
free dynamic memory 0: 4096
4-
unclaimed heap memory 0: 2142171136
5-
sbrk 0: 0x502000
4+
unclaimed heap memory 0: 2146365440
5+
sbrk 0: 0x102000
66
1
77
dynamic heap 1: 37752832
88
free dynamic memory 1: 4096
9-
unclaimed heap memory 1: 2104422400
10-
sbrk 1: 0x2902000
9+
unclaimed heap memory 1: 2108616704
10+
sbrk 1: 0x2502000
1111
1st trim: 1
1212
dynamic heap 1: 37752832
1313
free dynamic memory 1: 0
14-
unclaimed heap memory 1: 2104422400
15-
sbrk 1: 0x2902000
14+
unclaimed heap memory 1: 2108616704
15+
sbrk 1: 0x2502000
1616
2nd trim: 0
1717
dynamic heap 2: 37752832
1818
free dynamic memory 2: 0
19-
unclaimed heap memory 2: 2104422400
20-
sbrk 2: 0x2902000
19+
unclaimed heap memory 2: 2108616704
20+
sbrk 2: 0x2502000
2121
3rd trim: 1
2222
dynamic heap 3: 33656832
2323
free dynamic memory 3: 102400
24-
unclaimed heap memory 3: 2104422400
25-
sbrk 3: 0x2902000
24+
unclaimed heap memory 3: 2108616704
25+
sbrk 3: 0x2502000
2626
4th trim: 0
2727
dynamic heap 4: 33656832
2828
free dynamic memory 4: 102400
29-
unclaimed heap memory 4: 2104422400
30-
sbrk 4: 0x2902000
29+
unclaimed heap memory 4: 2108616704
30+
sbrk 4: 0x2502000
3131
5th trim: 1
3232
dynamic heap 5: 33558528
3333
free dynamic memory 5: 0
34-
unclaimed heap memory 5: 2104422400
35-
sbrk 5: 0x2902000
34+
unclaimed heap memory 5: 2108616704
35+
sbrk 5: 0x2502000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Heap size before allocation: 16777216
2-
Ptr: 1, value: 16843009, Heap size now: 101777408 (increase: 85000192 bytes)
2+
Ptr: 1, value: 16843009, Heap size now: 97583104 (increase: 80805888 bytes)

tests/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,8 @@ def test_embind(self):
22062206
'--pre-js', test_file('embind', 'test.pre.js'),
22072207
'--post-js', test_file('embind', 'test.post.js'),
22082208
'-s', 'WASM_ASYNC_COMPILATION=0',
2209+
# For some reason the default of 1Mb is not enough for these tests.
2210+
'-s', 'TOTAL_STACK=2Mb',
22092211
'-s', 'IN_TEST_HARNESS'] + args,
22102212
env=environ)
22112213

@@ -5208,7 +5210,7 @@ def test_massive_alloc(self, wasm):
52085210
# just care about message regarding allocating over 1GB of memory
52095211
output = self.run_js('a.out.js')
52105212
if not wasm:
5211-
self.assertContained('Warning: Enlarging memory arrays, this is not fast! 16777216,1473314816\n', output)
5213+
self.assertContained('Warning: Enlarging memory arrays, this is not fast! 16777216,1469120512\n', output)
52125214

52135215
def test_failing_alloc(self):
52145216
for pre_fail, post_fail, opts in [

0 commit comments

Comments
 (0)