Robin Lindner
Robin Lindner

Reputation: 605

Kernel-mode only operating system

A common x86 CPU has two different modes (here can we subdivide again into protection rings). One is the user mode and the other is the kernel mode.

The kernel mode has full access to the hardware. Basically you should be careful to execute something here.

For security reasons you choose the user mode for normal applications like a web server.

To call a kernel function, for example, an expensive context switch must take place.

Now to my question: Apart from the fact that it would be irresponsible to run a normal application in kernel mode, it would be possible in theory to run an application like a simple HTTP server in kernel mode.

However, the system would have to be perfect for this: The HTTP server is bug-free. This is basically not possible in practice. Also, the CPU could have a security hole, which makes this much more tragic.

Now we assume that the system would really be 100% perfect and we would run an application in kernel mode. Is this performance difference noticeable?

Has anyone tried this out and published benchmarks?

Upvotes: 0

Views: 242

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 364180

Yes, Linux had the TUX web server for a while. Years ago it maybe had some production usage, when CPUs were slower and security threats less severe. Only for serving static content. From Wikipedia, condensed:

The TUX web server is an unmaintained in-kernel web server for Linux licensed under the GNU General Public License (GPL). It was maintained by Ingo Molnár.
[...]

The main differences between TUX and other webservers include:

  • TUX runs partly within a customized version of the Linux kernel and partly as a userspace daemon. (Using the tux(2) system call)
  • With a capable network card, TUX enables scatter-gather DMA from the page cache directly to the network.
  • TUX is only able to serve static web pages.

Instead of user-space, presumably the daemon could be a "kernel thread", i.e. a schedulable task the runs in ring 0.

kHTTPd is I think the same thing? It says it can pass along requests for non-static content to a full web server like Apache. The site has some old benchmarks, like from a K6-2 at 350MHz, showing requests per second vs. concurrent requests, with Apache peaking at about 500 requests / sec (for a 1K file over a 100Mbit connection with apachebench). Zeus manages about 1900 req/s, but kHTTPd handled about 2300 req/s at best, with not-huge concurrency.

I'm sure you can google other benchmarks for Tux / kHTTPd now that you know what to search for.

Modern systems can come closer to saturating even 10Gbit network links with normal servers running in user-space, thanks to multi-core CPUs. So this idea has mostly been abandoned for web serving.

For local file-sharing, NFSd is still mostly done in-kernel.


https://en.wikipedia.org/wiki/In-kernel_web_server says there were actually implementations like that for multiple different OSes, including Solaris and HP-UX.

Upvotes: 2

Related Questions