Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in kernel and user space

Tags:

kernel

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?

like image 559
jtzero Avatar asked May 08 '10 14:05

jtzero


People also ask

What happens in user space and kernel space?

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.

What is in the kernel space?

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.

What is user space in Linux kernel?

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.”

Can kernel access user space memory?

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.


2 Answers

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 [...]

like image 86
stakx - no longer contributing Avatar answered Nov 23 '22 15:11

stakx - no longer contributing


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.

like image 39
msw Avatar answered Nov 23 '22 14:11

msw