Mail archive

Re: [alpine-aports] [PATCH] testing/mongodb: fix bug #5117 where mongo fails at start

From: Timo Teras <>
Date: Tue, 23 Feb 2016 17:04:46 +0200

On Tue, 23 Feb 2016 15:41:23 +0100
Marc Vertes <> wrote:

> It doesn't work. And on my side, I tried a similar modification
> (using getrlimit) in
> src/third_party/mozjs-38/extract/js/src/jsnativestack.cpp without
> success.
> But I found a separate patch which works:
> --- src/mongo/scripting/mozjs/implscope.cpp.orig
> +++ src/mongo/scripting/mozjs/implscope.cpp
> _at_@ -258,6 +258,7 @@
> //
> // TODO: What if we are running on a platform with very
> // large pages, like 4MB?
> + //JS_SetNativeStackQuota(_runtime, available.get() - (64
> * 1024)); JS_SetNativeStackQuota(_runtime, available.get() - (32 *
> 1024)); }
> So I believe that it should be a matter of increasing allocated stack
> at thread creation. I'm still not able to do that, despite my various
> attempts.

The main thread's stack is allocated by kernel. In practice, kernel
maps the stack on virtual address space so that it's size is the
stack rlimit, but it only allocates the first pages of it. When the
stack is needed more, the kernel automatically commits/allocates more
of the stack.

Musl returns you the actual size of the stack in use. Glibc returns you
the maximum stack size (but kernel might fail to allocate it).

Another attempt would be to patch that function to have in the
beginning a call to function that has large stack array and that writes
to it.

Something like:

static void commit_stack(void)
  char foo[1024*1024*2];
  foo[0] = foo[sizeof(foo)-1] = 0;

Assuming gcc will not optimize it away.

After this kernel should commit the memory, and musl's
pthread_getattr_np should return value reflecting that.


Received on Tue Feb 23 2016 - 17:04:46 UTC