Wednesday, January 25, 2012

1-1 beats N-M

SpiderMonkey, the JavaScript engine in Firefox, is moving towards a 1-1 threading model, away from a N-M model: JSRuntime is now officially single-threaded. Let me explain by looking back.

In Solaris the threading model is M-N, that is, for each program with N user threads there are M kernel threads servicing the program. This was thought to be the most flexible design and kernel threads were a limited resource.

Linux eventually settled on a 1-1 model, that is, for each program with N user threads there are N kernel threads each mapped uniquely to a user thread. This was found to be the simplest to code and the most performant in practice.

Back to JavaScript:

A single SpiderMonkey runtime (that is, instance of JSRuntime) — and all the objects, strings and contexts associated with it — may only be accessed by a single thread at any given time. However, a SpiderMonkey embedding may create multiple runtimes in the same process (each of which may be accessed by a different thread).

I read this to say: 1-1 mapping from SpiderMonkey to user thread. The same simplifications and performance gains Linux saw from the 1-1 model will be gained for SpiderMonkey.

Old lessons learned again; better than the alternative.

2 comments:

Anonymous said...

The default Solaris threading model has been 1-1 since Solaris 9 (Solaris 8u7 with options)

Brian Oxley said...

Shows my age. :)