Now I know that developing an app that goes into kernel space should be avoided - its hard to debug, complex etc.... with that off the table what are some advantages to moving an app from user space to the kernel? after all if there were no plus sides it would never be done...what are some?
A user space process is executed by a user in the operating system, rather than being part of the operating system itself. It might also be executed by an init system (e.g. systemd), but it isn't part of the kernel. User space is the area of memory that non-kernel applications run in.
Kernel space is where the kernel (i.e., the core of the operating system) executes (i.e., runs) and provides its services.” – Kernel Space Definition, The Linux Information Project 2005.
User space refers to all of the code in an operating system that lives outside of the kernel. Most Unix-like operating systems (including Linux) come pre-packaged with all kinds of utilities, programming languages, and graphical tools - these are user space applications. We often refer to this as “userland.”
Whilst a user-space program is not allowed to access kernel memory, it is possible for the kernel to access user memory. However, the kernel must never execute user-space memory and it must also never access user-space memory without explicit expectation to do so.
Some possible advantages:
system calls might be faster (i.e. lower latencies), as the CPU doesn't have to switch from application mode into kernel mode. (This is not necessarily true, as the CPU might make a finer distinction than simply "user space" and "kernel space". Intel x86 CPUs for example have a ring model encompassing 4 distinct privilege levels.) 1)
you might get direct access to the system's hardware via memory and I/O ports.
you might be able to suppress task switching, if you need to do something without being interrupted
you might be able to circumvent security mechanisms enforced by the operating system (e.g. read/modify other processes' memory). (Malware could take advantage of this if it gets installed as a kernel-mode device driver.)
(And of course, as you are aware, there's many many disadvantages and security risks. The distinction between application space and kernel space is there for good reasons.)
1) See e.g. the article Making system calls from kernel space from Linux mag:
For example, a high-performance Web server may wish to reside in the kernel for increased throughput and lower latency. However, there is also a safety tradeoff [...]
You get the chance for a tiny bug in your program to scribble all over memory and corrupt the entire system and all its processes and functions. If you are lucky, the system will crash.
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