系统相关
首页 > 系统相关> > Linux不使用分段而只使用分页吗?

Linux不使用分段而只使用分页吗?

作者:互联网

Linux编程接口显示进程的虚拟地址空间的布局.图中的每个区域都是一个细分市场吗?

enter image description here

从了解Linux内核,

以下是否正确,MMU中的分段单元将段内的段和偏移映射到虚拟内存地址,然后寻呼单元将虚拟内存地址映射到物理内存地址?

The Memory Management Unit (MMU) transforms a logical address into a linear
address by means of a hardware circuit called a segmentation unit; subsequently, a second hardware circuit called a paging unit transforms the linear address into a physical address (see Figure 2-1).

enter image description here

那为什么说Linux不使用分段而只使用分页呢?

Segmentation has been included in 80×86 microprocessors to encourage
programmers to split their applications into logically related
entities, such as subroutines or global and local data areas. However,
Linux uses segmentation in a very limited way. In fact, segmentation and paging are somewhat redundant, because both can be
used to separate the physical address spaces of processes:
segmentation can assign a different linear address space to each
process, while paging can map the same linear address space into
different physical address spaces. Linux prefers paging to
segmentation for the following reasons:

• Memory management is simpler when all processes use the same segment
register values—that is, when they share the same set of linear
addresses.

• One of the design objectives of Linux is portability to a wide range
of architectures; RISC architectures, in particular, have limited
support for segmentation.

The 2.6 version of Linux uses segmentation only when required by the
80×86 architecture.

解决方法:

x86-64体系结构在长模式(64位模式)下不使用分段.

四个段寄存器:CS,SS,DS和ES强制为0,限制为2 ^ 64.

https://en.wikipedia.org/wiki/X86_memory_segmentation#Later_developments

OS不再可能限制“线性地址”的哪个范围可用.因此它不能使用分段进行内存保护;它必须完全依赖于分页.

不要担心x86 CPU的细节,这些细节仅适用于在传统32位模式下运行时.用于32位模式的Linux没有那么多.它甚至可能被认为“处于良性忽视的状态”.见32-Bit x86 support in Fedora [LWN.net,2017].

(碰巧32位Linux也没有使用分段.但你不需要相信我,你可以忽略它:-).

标签:linux,kernel,virtual-memory
来源: https://codeday.me/bug/20190808/1624236.html