httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Robinson <>
Subject Re: Memory usage and freeing
Date Mon, 27 Jan 1997 18:42:42 GMT
On Mon, 20 Jan 1997, Cliff Skolnick wrote:

> On Mon, 20 Jan 1997, Ben Laurie wrote:
> > wrote:
> > > 
> > > > The other thing that makes it faster is the saving on context switches.
> > > > Thread context switching is considerably cheaper than process context
> > > > switching. 
> > > 
> > > Thread and process context switching under Linux is (or at least will be)
> > > equivalent.  There is no advantage of one over the other.
> There are two kinds of common thread, kernel bases threads and user level
> threads.  The kernel threads take almost as long to context switch as a
> process.  The user level thread will be faster if you are keeping the same
> kernel thread (1-n user threads are backed by one or more kernel threads). 
> One big advantage is that it is much cheaper to create a thread than a
> process.  Even with copy on write, there is still a lot of fiddling with
> tuff to mark those pages like that and you have to sort through file
> descriptors etc.  Thread creation is usually fast, in fact in Solaris it
> was faster to create a thread than to context switch into another kernel
> thread :)

Exactly. Although I would quibble with the terminology used here.
A 'kernel thread' is often used to mean 'part of the kernel software that
is running in a thread'. Here it is being used to mean a light-weight
process (LWP), i.e. a process that is dispatched by the kernel but does not
have its own address space. A LWP should be faster to create and context 
switch than a normal process, even if the same system call is used.

A system that provides LWPs is useless without a user-level threads system
based on top of that. The point of user-level threads is that they are
very fast to create, switch and destroy (hundreds of microseconds), and that 
there is NOT a one-to-one correspondence between user threads and system 
LWPs. Otherwise, there is little performance gain if every thread has to
have a LWP executing it.

Similarly, a user level threads package without a kernel support for LWPs
is not ideal. Whenever a thread blocks in a system call, the whole process
stops and no other threads can execute.

 David Robinson.

View raw message