What is the difference between the kernel and user spaces?

Overview

All the modern computer operating systems generally divide the virtual memory into two following spaces:

  • Kernel space
  • User space

The primary reason for this separation is to protect memory and hardware from malicious or third-party software's errant behavior.

Kernel space

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.

User space

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

Kernel space vs. user space

The CPU rings are the most apparent distinction between kernel space and user space or userland.

CPU rings

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:

  • 0 for the kernel space.
  • 3 for the user space.

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.

Logical view

Let's have a look at the logical view of memory space segmentation.

The simulation of OS-level space division

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved