Sitemap
Developer Notes

Developer Notes

There is nothing either good or bad but thinking makes it so..... Shakespeare

Kernel Space & User Space

3 min readNov 1, 2023

--

The Random Access Memory can be logically divided into two distinct regions namely — the kernel space and user space.

When a process is created and its virtual memory is divided into user-space and a kernel-space where user space region contains data, code, stack, heap of the process & kernel-space contains things such as the page table for the process, kernel data structures and kernel code etc. To run kernel space code, control must shift to kernel mode (0x80 software interrupt for system calls) & kernel stack is basically shared among all processes currently executing in kernel space.

The maximum size of the address space depends on the length of the address register on the CPU.

Kernel Space

Kernel can access all parts of Memory, and to access some part of the kernel, the user processes have to use the predefined system call such as “read”, “write”, “open”.

The system calls act as an interface between the user processes and the kernel processes. The access rights are placed on the kernel space in order to stop the users from messing up with kernel.

When a system call occurs, a software interrupt is sent to the kernel. The CPU may handover the control temporarily to the associated interrupt handler routine. The kernel process which was halted by the interrupt resumes after the interrupt handler routine finishes its job.

User Space

On systems with 32-bit address registers, the maximum size of address space is 232 bytes, or 4 GiB. Similarly, on 64-bit systems, 264 bytes can be addressed.

Get Developer Notes’s stories in your inbox

Join Medium for free to get updates from this writer.

Such address space is called virtual memory or virtual address space. It is not actually related to physical RAM size.

On Linux platforms, virtual address space is divided into kernel space and user space.

An architecture-specific constant called task size limit, or TASK_SIZE, marks the position where the split occurs:

  • the address range from 0 up to TASK_SIZE-1 is allotted to user space;
  • the remainder from TASK_SIZE up to 232-1 (or 264-1) is allotted to kernel space.

On a particular 32-bit system for example, 3 GiB could be occupied for user space and 1 GiB for kernel space.

Each application/program in a Unix-like operating system is a process; each of those has a unique identifier called Process Identifier (or simply Process ID, i.e. PID). Linux provides two mechanisms for creating a process: 1. the fork() system call, or 2. the exec() call.

A kernel thread is a lightweight process and also a program under execution. A single process may consist of several threads sharing the same data and resources but taking different paths through the program code. Linux provides a clone() system call to generate threads.

Example uses of kernel threads are: data synchronization of RAM, helping the scheduler to distribute processes among CPUs, etc.

References

Gaurav Sen Channel

Difference between Kernel Space & User Space

--

--

Developer Notes
Developer Notes

Written by Developer Notes

There is nothing either good or bad but thinking makes it so..... Shakespeare