当前位置:网站首页>分页的相关知识
分页的相关知识
2022-07-25 00:33:00 【华为云】
什么是分页?
把内存空间划分为大小相等且固定的块,作为主存的基本单位。因为程序数据存储在不同的页面中,而页面又离散的分布在内存中,因此需要一个页表来记录映射关系,以实现从页号到物理块号的映射。
访问分页系统中内存数据需要两次的内存访问 (一次是从内存中访问页表,从中找到指定的物理块号,加上页内偏移得到实际物理地址;第二次就是根据第一次得到的物理地址访问内存取出数据)。
什么是分段?
分页是为了提高内存利用率,而分段是为了满足程序员在编写代码的时候的一些逻辑需求(比如数据共享,数据保护,动态链接等)。
分段内存管理当中,地址是二维的,一维是段号,二维是段内地址;其中每个段的长度是不一样的,而且每个段内部都是从0开始编址的。由于分段管理中,每个段内部是连续内存分配,但是段和段之间是离散分配的,因此也存在一个逻辑地址到物理地址的映射关系,相应的就是段表机制。
分页和分段有什区别?
分页对程序员是透明的,但是分段需要程序员显式划分每个段。
分页的地址空间是一维地址空间,分段是二维的。
页的大小不可变,段的大小可以动态改变。
分页主要用于实现虚拟内存,从而获得更大的地址空间;分段主要是为了使程序和数据可以被划分为逻辑上独立的地址空间并且有助于共享和保护。 什么是交换空间?
操作系统把物理内存(physical RAM)分成一块一块的小内存,每一块内存被称为页(page)。当内存资源不足时,Linux把某些页的内容转移至硬盘上的一块空间上,以释放内存空间。硬盘上的那块空间叫做交换空间(swap space),而这一过程被称为交换(swapping)。物理内存和交换空间的总容量就是虚拟内存的可用容量。
用途:
物理内存不足时一些不常用的页可以被交换出去,腾给系统。
程序启动时很多内存页被用来初始化,之后便不再需要,可以交换出去。
页面替换算法有哪些?
在程序运行过程中,如果要访问的页面不在内存中,就发生缺页中断从而将该页调入内存中。此时如果内存已无空闲空间,系统必须从内存中调出一个页面到磁盘对换区中来腾出空间。
包括以下算法:
最佳算法:所选择的被换出的页面将是最长时间内不再被访问,通常可以保证获得最低的缺页率。这是一种理论上的算法,因为无法知道一个页面多长时间不再被访问。
先进先出:选择换出的页面是最先进入的页面。该算法将那些经常被访问的页面也被换出,从而使缺页率升高。
LRU:虽然无法知道将来要使用的页面情况,但是可以知道过去使用页面的情况。LRU 将最近最久未使用的页面换出。为了实现 LRU,需要在内存中维护一个所有页面的链表。当一个页面被访问时,将这个页面移到链表表头。这样就能保证链表表尾的页面是最近最久未访问的。因为每次访问都需要更新链表,因此这种方式实现的 LRU 代价很高。
时钟算法:时钟算法使用环形链表将页面连接起来,再使用一个指针指向最老的页面。它将整个环形链表的每一个页面做一个标记,如果标记是0,那么暂时就不会被替换,然后时钟算法遍历整个环,遇到标记为1的就替换,否则将标记为0的标记为1。
边栏推荐
- This visual is not connected to the presentationsource.
- EF core :自引用的组织结构树
- Where is the most formal account opening for futures trading? Capital security?
- How to use measurement data to drive the improvement of code review
- Nodejs package
- C语言学习之分支与循环语句
- 【无标题】
- Technical operation
- [mindspore ascend] [user defined operator] graph_ In mode, customize how to traverse tensor
- [Bert] transformer/bert/attention interview questions and answers
猜你喜欢

Redis6.2 SYSTEMd startup prompt redis service: Failed with result ‘protocol‘.

This visual is not connected to the presentationsource.

Qt学习-利用数据库单例完成 登录匹配 + 注册 功能实现
![[untitled]](/img/8a/c51328240e28459e98aedcf107c0a3.png)
[untitled]

C # "learning code snippet" - recursively obtain all files under the folder

Sql文件导入数据库-保姆级教程

SQL file import database - Nanny level tutorial
![[Bert] QA, reading comprehension, information retrieval](/img/3b/f632271be813cd71a44b204f5060c4.png)
[Bert] QA, reading comprehension, information retrieval

3. Pressure test

Which automation tools can double the operation efficiency of e-commerce?
随机推荐
线段树杂谈
痛并快乐的-NIO编程
GUI basic application
Why does [mindspore ascend] [custom operator] repeatedly assign values to one tensor affect another tensor?
Heap and stack in embedded development
C language force buckle the eleventh question to find the maximum capacity of the bucket. (two methods)
Leetcode 1260. two dimensional grid migration: two solutions (k simulations / one step)
Number of palindromes in question 5 of C language deduction (two methods)
Server intranet and Extranet
[mindspore] [training warning] warning when executing training code
Qt学习-利用数据库单例完成 登录匹配 + 注册 功能实现
Redis6.2 SYSTEMd startup prompt redis service: Failed with result ‘protocol‘.
Dpdk based basic knowledge sorting-01
Soft test --- fundamentals of programming language (Part 2)
===、==、Object. Is basic package type
Research and Multisim Simulation of linear circuit characteristics (engineering documents attached)
Leetcode 0123. the best time to buy and sell stocks III: dynamic programming + simulation in constant space
LeetCode_6124_第一个出现两次的字母
jquer $(‘div li‘) $(‘div,li‘) $(‘div>li‘) $(‘div‘,‘li‘)
R language uses ISNA function to check whether the list and dataframe contain missing values, marks abnormal values in data columns in dataframe as missing values Na, and uses na.omit function to dele