Table of Contents
分段(segmentation)
分页(paging)
Home Database Mysql Tutorial 【程序员的自我修养】从分段机制到分页机制

【程序员的自我修养】从分段机制到分页机制

Jun 07, 2016 pm 03:28 PM
segmentation Pagination Multitasking operating system mechanism programmer

操作系统的多任务性使得CPU在多个进程之间共享,从进程的角度来看,就是一个进程独占一个CPU,IO抽象模型也很好地实现了IO设备的共享,那么内存的分配与共享就交给虚拟存储器来管理了。 早期计算机中,程序是直接运行在物理内存上的,就是程序运行时访问的都

操作系统的多任务性使得CPU在多个进程之间共享,从进程的角度来看,就是一个进程独占一个CPU,IO抽象模型也很好地实现了IO设备的共享,那么内存的分配与共享就交给虚拟存储器来管理了。

早期计算机中,程序是直接运行在物理内存上的,就是程序运行时访问的都是PA(物理地址),我们必须同时在内存中运行多个程序,那么有限的RAM空间如何分配呢?直接分配的策略有如下问题:

1:地址空间不隔离,所有程序直接访问PA,内存空间没有隔离,恶意修改数据有可能造成安全问题。

2:内存使用率低下,程序之间换进换出(RAM和Disk之间),因为这里还没有分段和分页机制。

3:程序运行的地址不确定。

解决这些问题:

首先引入虚拟地址的概念,把程序给出的地址看成是VA(虚拟地址),通过映射机制(MMU+paging)把VA翻译成PA,这样只需管理这个VA到PA的映射过程就可以保证程序之间的PA区域不会重叠。

每个进程都有自己独立的VA空间,每个进程只能访问自己的虚拟地址空间,这样做到进程隔离。

分段(segmentation)

程序所需要的内存空间大小的虚拟空间映射到每个物理地址空间中,一一映射,它能解决隔离问题,不同的物理地址空间,但是分段没有解决内存使用率低下的问题,分段对内存区域的映射是按照程序为单位的,如果内存不足,被换入换出到磁盘的都是整个程序,造成大量的磁盘访问,粒度较大。根据程序的局部性原理,一个程序运行时,在某个时间段内,它只是频繁使用到了一部分数据和指令,更小粒度的内存分割和映射方法---->分页机制。提高内存使用率。

分页(paging)

我们可以把进程的虚拟地址空间按页分割,一般一个page的大小为4KB或者8KB,把常用的数据和代码装载到RAM中,把不常用的代码和数据保存在Disk中,等到需要使用的时候通过page fault调入RAM,这时候如果没有空闲的页,那么会使用页面替换算法牺牲一个页来覆盖(LRU最近最少使用算法)。

通过页映射机制,可以保存程序数据,我们可以给每个页设置权限属性(一些标志位)来控制该页的访问权限(内核还是用户)还有RWX权限等。分页需要MMU硬件单元,该单元集成在CPU内部。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

How to run programs in terminal vscode How to run programs in terminal vscode Apr 15, 2025 pm 06:42 PM

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

Is the vscode extension malicious? Is the vscode extension malicious? Apr 15, 2025 pm 07:57 PM

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

How to choose the PyTorch version on CentOS How to choose the PyTorch version on CentOS Apr 14, 2025 pm 06:51 PM

When installing PyTorch on CentOS system, you need to carefully select the appropriate version and consider the following key factors: 1. System environment compatibility: Operating system: It is recommended to use CentOS7 or higher. CUDA and cuDNN:PyTorch version and CUDA version are closely related. For example, PyTorch1.9.0 requires CUDA11.1, while PyTorch2.0.1 requires CUDA11.3. The cuDNN version must also match the CUDA version. Before selecting the PyTorch version, be sure to confirm that compatible CUDA and cuDNN versions have been installed. Python version: PyTorch official branch

Can vscode run in Windows 7 Can vscode run in Windows 7 Apr 15, 2025 pm 07:27 PM

VS Code is still available on Windows 7, but is highly not recommended. Windows 7 lacks security updates and patches, resulting in security risks and VS Code compatibility issues. Although simple code editing is barely competent, it is recommended to upgrade to Windows 10 or later for complex development or for extensions.

See all articles