Skip to content

Commit

Permalink
lkl: decrease stack size of thread_create to PTHREAD_STACK_MIN
Browse files Browse the repository at this point in the history
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 <liuyuan@google.com>
  • Loading branch information
liuyuan10 committed Aug 3, 2016
1 parent bafaea1 commit bee09a0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <sys/socket.h>
#include <sys/syscall.h>
#include <poll.h>
#include <limits.h>
#include <lkl_host.h>
#include "iomem.h"

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bee09a0

Please sign in to comment.