内核虚拟内存 space 和进程虚拟内存 space

Kernel virtual memory space and process virtual memory space

我正在阅读 textbook:Computer Systems A Programmer's Perspective,第 9.7.2 章:Linux Virtual Memory System(第三版),其中讨论了虚拟内存。

我对 linux 进程的虚拟内存结构有点困惑,如下所示:

我的问题是:内核虚拟内存是否为内核保留 运行 其余的虚拟内存为用户进程保留?内核代码和数据有什么作用?内核虚拟内存中的物理内存是什么?

does kernel virtual memory preserve for kernel to run and rest of the virtual memory preserve for user process?

是的,有一部分虚拟内存始终为内核保留,另一部分留给用户空间进程使用。每个进程都有自己的虚拟内存,但内核总是映射到虚拟内存的较高部分(较高地址)。此映射是否对进程可见取决于 Kernel Page Table Isolation.

另请参阅:Do the virtual address spaces of all the processes have the same content in their “Kernel” parts?

What does kernel code and data do?

部分高位虚拟内存是实际内核映像的直接映射。也就是说,内核可执行文件及其所有数据。您可以在内核文档的 this page 中看到更详细的信息,标记为 "kernel text mapping, mapped to physical address 0".

另请参阅:What's the use of having a kernel part in the virtual memory space of Linux processes?

And what does the physical memory in kernel virtual memory?

图片的那部分完全是误导。我不知道这本书的作者到底想传达什么信息,但物理内存绝对 不是 内核虚拟内存的一部分。他们可能试图解决这样一个事实,即在内核虚拟内存中存在所有物理内存的直接 映射 ,这可以在内核文档的 the same page 上再次看到,标记为 "direct mapping of all physical memory"

物理内存是指系统的真实内存(即RAM)。虚拟内存的每个区域都映射到物理内存的某个区域。这种虚拟到物理的映射对进程是完全透明的,并由内核管理。例如,以只读模式打开相同文件的两个可执行文件通常共享相同的 physical 内存区域,同时看到两个不同的 virtual地址。

这是对虚拟内存和物理内存之间关系的更准确描述:

来源:https://computationstructures.org/lectures/vm/vm.html

引用自 CSAPP 书籍,第 3 版,第 9.7.2 节,其中显示了图片。

Interestingly, Linux also maps a set of contiguous virtual pages (equal in size to the total amount of DRAM in the system) to the corresponding set of contiguous physical pages. This provides the kernel with a convenient way to access any specific location in physical memory—for example, when it needs to access page tables or to perform memory-mapped I/O operations on devices that are mapped to particular physical memory locations.

我觉得图中的Physical memory正好反映了上面的描述:一个映射到整个物理内存的虚拟内存区域。