Erlang using Linux native threads - a waste of space

Ryan Rawson <>
Sun Sep 3 08:10:02 CEST 2006

What about the cost of actually executing the context switch and the
flushing of pipelines?  A kernel call on i386 is executed via the
software interrupt which is the equivalent of a long jump, thus your
pipeline is invalidated.

If you are trying to get huge performance, avoiding context switches
should be on the list of top 10 issues, no?


On 9/2/06, Roger Larsson <> wrote:
> On Tuesday 29 August 2006 15:47, you wrote:
> > On Tue, 29 Aug 2006, lang er wrote:
> > > If OS support erlang's lightweight  process in kernel,  many programming
> > > languages could have  erlang's concurrent capability.I think it is not
> > > impossible.
> >
> > The reason that Erlang processes are lightweight is that they do not
> > require a context switch from userland -> kernel -> userland in order to
> > schedule the next thread. Erlang can rely on the properties of the
> > language, specifically no shared mutable data, in order to isolate
> > processes from each other. The kernel must use the CPU's virtual memory
> > support to do this, because it cannot make assumptions about the languages
> > used to write userland processes, and switching pages tables is expensive.
> Linux does not switch the page tables if the new process has the same
> memory map as the previous - i.e. an thread.
> But you still have the cost of checking that together with entering/leaving
> the kernel. In addition to this the kernel needs to store thread information
> and a (kernel) stack.
> The stack is a problem when executing in kernel, as all threads will do.
> - It can not be placed in user memory (another concurrently executing thread
>  might modify it - by accident or not... Causing severe corruptions).
> - It needs to be big enough to store data from all possible kernel callchains
>   including local variables - how big does it need to be???
> - As an optimization it does hold the thread information for quick access
> Linux
>         Kernel 2.4 uses 8 kB stacks,
>         this has been optimized to 4 kB in 2.6 on i386 architectures, by
>         using option CONFIG_4KSTACKS, possible since 2.6 has independent
>         interrupt stack, exception stack..., x86-64 bit architecture could thus
>         continue        to use an 8 kB stack.
>         The task description alone (stored in the stack) is about  1.7 kB
>         Good information at (over one year old...)
>         More about threads
> In addition to this all threads needs a userspace stack too.
> Erlang
>         Saw some Erlang numbers earlier but I can not find it.
>         Note: nothing needs to be stored per Erlang process in kernel.
> /RogerL

More information about the erlang-questions mailing list