Skip to content

Commit e0f3446

Browse files
yamtjohn-sharratt
authored andcommitted
Reduce over-allocation of stack (WebAssembly#365)
* Disable stack guard * Stop rounding up stack size to PAGE_SIZE
1 parent 4b2bb1c commit e0f3446

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

libc-top-half/musl/src/internal/pthread_impl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ extern hidden unsigned __default_stacksize;
222222
extern hidden unsigned __default_guardsize;
223223

224224
#define DEFAULT_STACK_SIZE 131072
225+
#ifdef __wasilibc_unmodified_upstream
225226
#define DEFAULT_GUARD_SIZE 8192
227+
#else
228+
/* guard doesn't make much sense without mprotect. */
229+
#define DEFAULT_GUARD_SIZE 0
230+
#endif
226231

227232
#define DEFAULT_STACK_MAX (8<<20)
228233
#define DEFAULT_GUARD_MAX (1<<20)

libc-top-half/musl/src/thread/pthread_create.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,17 @@ _Noreturn void wasi_thread_start(int tid, void *p)
297297
}
298298
#endif
299299

300+
#ifdef __wasilibc_unmodified_upstream
300301
#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
302+
#else
303+
/*
304+
* As we allocate stack with malloc() instead of mmap/mprotect,
305+
* there is no point to round it up to PAGE_SIZE.
306+
* Instead, round up to a sane alignment.
307+
* Note: PAGE_SIZE is rather big on WASM. (65536)
308+
*/
309+
#define ROUND(x) (((x)+16-1)&-16)
310+
#endif
301311

302312
/* pthread_key_create.c overrides this */
303313
static volatile size_t dummy = 0;

0 commit comments

Comments
 (0)