All the modern computer operating systems generally divide the virtual memory into two following spaces:
The primary reason for this separation is to protect memory and hardware from malicious or third-party software's errant behavior.
The memory space where the core of the operating system (kernel) executes and provides its services is known as kernel space. It's reserved for running device drivers, OS kernel, and all other kernel extensions.
The user space is also known as userland and is the memory space where all user applications or application software executes. Everything other than OS cores and kernel runs here.
One of the roles of the kernel is to manage all user processes or applications within user space and to prevent them from interfering.
Note: User process can access the kernel space through
. system calls System calls are requests in a Unix-like operating system by an active process for a service performed by the kernel, such as input/output (I/O) or process creation.
The CPU rings are the most apparent distinction between kernel space and user space or userland.
The CPU rings are the layers between the installed applications on a computer system and the core processes of the system. These structural rings are for the protection of the processes from interference.
When you're in x86 protected mode, the CPU is always in one of 4 rings. For example, the Linux kernel only uses 0 and 3:
The other differences are as follows:
Kernel Space | User Space |
Kernels and OS core execute here. | Normal program and applications softwares run here. |
Its the core space of OS. | It's a form of sand-boxing that restricts user processes to access OS kernel. |
It has full access to all memory and machine hardware. | It has limited access to memory and access kernel through system calls only. |
It contains the page table for process, kernel data structure, threads, and kernel code etc. | It contains the program code, data, stacks, and heap of the process. |
Let's have a look at the logical view of memory space segmentation.
Free Resources