What is the difference between the kernel space and the user space?

前端 未结 16 1267
渐次进展
渐次进展 2020-11-30 16:28

What is the difference between the kernel space and the user space? Do kernel space, kernel threads, kernel processes and kernel stack mean the same thing? Also, why do we n

16条回答
  •  离开以前
    2020-11-30 16:39

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

    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.

    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.

提交回复
热议问题