简体   繁体   English

术语“用户空间”和“内核空间”是指物理内存吗?

[英]Does the terms “user space” and “kernel space” refer to physical memory?

When we use the term "user space", do we mean the area in physical memory that contains the code and data of user processes, or do we mean the 3 GB of virtual memory that each process have? 当我们使用术语“用户空间”时,我们是指物理内存中包含用户进程的代码和数据的区域,还是指每个进程具有3 GB的虚拟内存?

And wen we use the term "kernel space", do we mean the area in physical memory that contains the code and data of the kernel, or do we mean the 1 GB of virtual memory that each process have? 我们使用术语“内核空间”,我们是指物理内存中包含内核代码和数据的区域,还是指每个进程拥有的1 GB虚拟内存?

The terms 'kernel space' and 'user space' do not specifically refer to either the virtual or the physical memory. 术语“内核空间”和“用户空间”并不特指虚拟或物理内存。 Conceptually if you say 'kernel space' refers to 1GB of virtual memory each process has, it is still the same as referring to the kernel code and data residing in physical memory because the 1GB of virtual memory is mapped to the physical memory holding the kernel code and data. 从概念上讲,如果你说'内核空间'是指每个进程有1GB的虚拟内存,它仍然与引用内核代码和驻留在物理内存中的数据相同,因为1GB的虚拟内存被映射到持有内核的物理内存代码和数据。

We use the terms 'Kernel space' and 'User space' to rather refer to who has the permission to access which part of the memory. 我们使用术语“内核空间”和“用户空间”来指代谁有权访问内存的哪一部分。 'Kernel Space' would refer to the memory to which just the kernel has access to, while 'User space' would be referring to the memory both the corresponding user process and kernel have access to. “内核空间”指的是内核可以访问的内存,而“用户空间”指的是相应的用户进程和内核都可以访问的内存。

It does not really refer to address space at all. 它根本没有真正涉及地址空间。

User Space: The processor executes something in a unpriviledged context. 用户空间:处理器在无特权的上下文中执行某些操作。

Kernel Space: The processor executes something in a priviledged context. 内核空间:处理器在特权上下文中执行某些操作。

In the priviledged context everything is allowed, in the unpriviledged context some processor functions are limited. 在特权环境中,一切都被允许,在无特权的环境中,一些处理器功能是有限的。 This is implemented in hardware, so the processor must support at least two modes for linux. 这是在硬件中实现的,因此处理器必须至少支持两种Linux模式。

So to switch from user space to kernel space you need to switch the context (with a system call). 因此,要从用户空间切换到内核空间,您需要切换上下文(使用系统调用)。

You can allocate virtual memory ( vmalloc ) as well as physical memory ( kmalloc ) inside kernel space, so it is not related to memory directly. 您可以在内核空间内分配虚拟内存( vmalloc )和物理内存( kmalloc ),因此它与内存无直接关系。

In user space you can only allocate virtual memory ( vmalloc = malloc ). 在用户空间中,您只能分配虚拟内存( vmalloc = malloc )。

"User space" and "kernel space" refer to ranges of logical addresses . “用户空间”和“内核空间”指的是逻辑地址的范围。

The kernel space is identical for all processes, whereas the user space is unique to each process. 内核空间对于所有进程都是相同的,而用户空间对于每个进程都是唯一的。 However, it is possible for user address spaces to share mappings to physical memory. 但是,用户地址空间可以共享映射到物理内存。

In theory, two processes could have identical user spaces, but that does not happen in practice. 理论上,两个进程可以具有相同的用户空间,但这在实践中不会发生。

In terms of the process concept : 流程概念方面

We can say that a process can run in the 'kernel space' or in the 'user space', not both concurrently. 我们可以说一个进程可以在“内核空间”或“用户空间”中运行,而不是同时运行。 Normally a process runs in the 'user space'. 通常,进程在“用户空间”中运行。 If the process needs to access a protected resource, it should jump into the 'kernel space' because only the kernel has the privilege to access a protected resource. 如果进程需要访问受保护资源,它应该跳转到“内核空间”,因为只有内核才有权访问受保护资源。 To do this we have to use a system call. 为此,我们必须使用系统调用。

In terms of the address space : 地址空间而言

We can say that a (virtual) memory can be in the 'kernel (address) space' or in the 'user (address) space'. 我们可以说(虚拟)内存可以位于“内核(地址)空间”或“用户(地址)空间”中。 In a 32bit normal linux system, the user address space range is [0,0xbfffffff] , the kernel address space is [0xc0000000, 0xffffffff] . 在32位普通linux系统中,用户地址空间范围是[0,0xbfffffff] ,内核地址空间是[0xc0000000, 0xffffffff]

You are correct in part. 你的部分是正确的。 System Memory is divided in these two types of memory : 系统内存分为以下两种类型的内存:

User Space is a portion of the system memory in which user processes run. 用户空间是用户进程运行的系统内存的一部分。 This contrasts with kernel space, which is that portion of memory in which the kernel executes and provides its services. 这与内核空间形成对比,内核空间是内核执行并提供其服务的内存部分。

The contents of memory, which consists of dedicated RAM (random access memory) VLSI (very large scale integrated circuit) semiconductor chips, can be accessed (ie, read and written to) at extremely high speeds but are retained only temporarily 存储器的内容由专用RAM(随机存取存储器)VLSI(超大规模集成电路)半导体芯片组成,可以极高速度访问(即读取和写入),但仅暂时保留

Kernel Space is a memory that constitutes the central core of a computer operating system. 内核空间是构成计算机操作系统核心的内存。 It is in-fact a process, that controls all other processes, and it has complete control over everything that occurs on the system. 它实际上是一个控制所有其他进程的进程,它可以完全控制系统上发生的所有事情。 This includes managing system resources of HW (managing devices) and SW (individual user processes, within user space and preventing them from interfering with each other. It's basically where the OS runs on. 这包括管理硬件(管理设备)和软件(用户空间内的单个用户进程)的系统资源,防止它们相互干扰。它基本上是运行操作系统的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM