5 ms·
There is a reason why kernel code run in privileged mode, speed! If you run more kernel code in privileged mode then you do not need to copy as much data betwee
by acd 8y ago
There is a reason why kernel code run in privileged mode, speed! If you run more kernel code in privileged mode then you do not need to copy as much data between the kernel and user space. Vs a micro kernel you will have to copy more data up to user space. Copying data to user space causes context switches and gives less performance.
Larger mono kernels:
Speed
Micro kernels have advantages such as:
smaller privileged attack surface and thus more secure,
more crash proof as you can restart user land processes for example device drivers
https://en.wikipedia.org/wiki/Microkernel https://en.wikipedia.org/wiki/Microkernel
- pradn 8y agoDo you really need to do a full copy? What if you had a shared page and notified the user process when the data in the page was available at a certain offset. Take a look at this paper (FlexSC: Flexible System Call Scheduling with Exception-Less System Calls): https://www.usenix.org/legacy/event/osdi10/tech/full_papers/Soares.pdf https://www.usenix.org/legacy/event/osdi10/tech/full_papers/...
- tlb 8y agoSharing pages between user processes and kernel is extremely bug-prone, because threads in the user process can mutate the data while the kernel is reading it, leading to all kinds of race conditions. You can't depend on user processes respecting mutexes for security. You can make this work by removing the page from the user process before making it available to the kernel, but the synchronization overhead of doing this (especially on a NUMA system) is probably worse than copying moderate amounts of data.
- pradn 8y agoHmm. Perhaps temporarily switching the TLB entry to read-only mode for that page during kernel accesses? There might be some interesting software-hardware co-design solutions here.
- naasking 8y ago> If you run more kernel code in privileged mode then you do not need to copy as much data between the kernel and user space. Microkernels don't copy data into the kernel address space, they copy data between userland address spaces. Which still happens in monolithic systems anyway when you're doing IPC. These are typically short messages, often only data passed in registers. And if copying is going to be a bottleneck, then you negotiate a shared address space just like in Unix, and no more copying.
- hinkley 8y agoCode doesn't run faster because it's in the kernel. The speed you're talking about comes from avoiding transitions in and out of a given space. If you stay out or stay in the results are pretty similar. Except for your tooling. Cloudflare article from a couple years ago on why they don't use user-space network stack: https://blog.cloudflare.com/why-we-use-the-linux-kernels-tcp-stack/ https://blog.cloudflare.com/why-we-use-the-linux-kernels-tcp... and the tl:dr is a profound lack of feature parity. They use everything from iptables to tcpdump. If someone else worked on feature parity (they say it's too expensive for too small a gain for them), I expect they'd change their tune.
- Dylan16807 8y ago> If you stay out or stay in the results are pretty similar. Which is impossible when service A and service B are both in user space, because they are in separate spaces. Ring 0 isn't special, but you need to be monolithic if you want to avoid transitions.
- Sporktacular 8y agoIn a world of constant security threats and 2 GHz CPUs dedicated to cat videos - needing speed can no longer be the excuse for poor design. And "embedded CPUs need every precious cycle" is not an argument either. As the paper says modern microkernals have a negligible speed penalty while IoT/networked industrial controllers are a security backwater.