Skip to content

Commit dfad6fe

Browse files
authored
Reduce over-allocation of stack (#365)
* Disable stack guard * Stop rounding up stack size to PAGE_SIZE
1 parent fb9c922 commit dfad6fe

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

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

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

218218
#define DEFAULT_STACK_SIZE 131072
219+
#ifdef __wasilibc_unmodified_upstream
219220
#define DEFAULT_GUARD_SIZE 8192
221+
#else
222+
/* guard doesn't make much sense without mprotect. */
223+
#define DEFAULT_GUARD_SIZE 0
224+
#endif
220225

221226
#define DEFAULT_STACK_MAX (8<<20)
222227
#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
@@ -295,7 +295,17 @@ _Noreturn void wasi_thread_start(int tid, void *p)
295295
}
296296
#endif
297297

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

300310
/* pthread_key_create.c overrides this */
301311
static volatile size_t dummy = 0;

0 commit comments

Comments
 (0)