Why do we need separation between kernel space and user space, when every data structure, every memory resource is managed by the kernel even if we create a process in user space? Why do we need such a big architecture?
All the page tables, context switching etc. are managed by the kernel, then why user space? Can we not use only one space and develop all the things over it?
This question may sound weird, but I want to really understand why is it required? If I have to design a completely new OS and I do not perform such division between kernel space and user space, what would be the problem?
Thanks
Your question is not weird at all -- are absolutely correct in you intuition that the kernel space may represent an unnecessary overhead. Indeed, it is overhead that many operating systems do not have. Your OS most likely won't have it either.
The rationale for the extra complexity goes something like this:
We want process/task separation. We want to make sure that one task doing bad things does not affect another one. This requires that the tasks execute in their respective isolated spaces.
We want similar protection for shared hardware controllers.
A task cannot set up its own boundaries; if that was the case a misbehaving task could purposely break the rules. So we need a third party with higher privileges than what the tasks have, and there is your kernel (or privileged) space.
If the cost of the extra kernel space and separation is too high, either in size or in computation overhead, the operating system will not have those features. Many real-time or embedded systems run in a single space with a single (same) privilege level (the privilege levels are sometimes referred to as protection rings) exactly as you described it.
If there is no protection between kernel space and user space or between different user processes then anybody can write some code which will intentionally or accidentally modify either memory in kernel space or memory in the space of another user process. Look into the good old MS-DOS which lacked this protection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With