Re: mmap() versus read()

Linus Torvalds (torvalds@transmeta.com)
Tue, 10 Mar 1998 20:21:20 -0800 (PST)


On Tue, 10 Mar 1998, Victor Yodaiken wrote:
>
> PPC Linux does this in the idle task -- a big win. So if the problem is speed
> of clone,then we should speed up clone.

clone() really _is_ very lightweight. I think that some of the confusion
comes from the timings of "pthread_create()" which is much less
lightweight partly due to memory allocation issues, partly just because
the Linux clone-based pthreads library hasn't had all that much time to be
optimized etc.

I'd be very surprised if a basic clone() call is any slower than even the
lightest-weight Solaris kernel threads: there really is almost no overhead
at all: most of it is a fairly simple memory allocation plus some slight
copying of kernel state to the new thread.

And partly _because_ Linux kernel threads created with clone() are not a
special case but a first-class citizen with any other process, a lot of
code is actually simplified and speeded up. For example, the context
switching doesn't have any special cases etc (it has a weight factor that
tries to give priority to threads that share the same memory management,
but that's a fairly simple mechanism for better performance).

I'm sure people can find threads that are even more light-weight than
clone(), but I don't think they'll be as generic as clone(), and I doubt
they'll be _much_ faster.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu