From bee09a093ec607c9a39120c7ddda7691b2ffbf58 Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Wed, 3 Aug 2016 09:26:24 -0700 Subject: [PATCH] lkl: decrease stack size of thread_create to PTHREAD_STACK_MIN By default, each pthread has 8MB stack. LKL creates 20+ threads at startup which consumes 160MB alone. This commit decreases it to PTHREAD_STACK_MIN (16 KB) which is enough to run linux kernel code. kernel stack on x86_64 is 2 pages (8 KB). Tested: MALLOC_ARENA_MAX=1 ./bin/lkl-hijack.sh sleep 1000 pmap virt mem: 287MB vs 115 MB Signed-off-by: Yuan Liu --- tools/lkl/lib/posix-host.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lkl/lib/posix-host.c b/tools/lkl/lib/posix-host.c index de238cbc76ea38..1abd10b3c0c15d 100644 --- a/tools/lkl/lib/posix-host.c +++ b/tools/lkl/lib/posix-host.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "iomem.h" @@ -177,7 +178,10 @@ static void mutex_free(struct lkl_mutex *_mutex) static lkl_thread_t thread_create(void (*fn)(void *), void *arg) { pthread_t thread; - if (WARN_PTHREAD(pthread_create(&thread, NULL, (void* (*)(void *))fn, arg))) + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); + if (WARN_PTHREAD(pthread_create(&thread, &attr, (void* (*)(void *))fn, arg))) return 0; else return (lkl_thread_t) thread;