ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

读CS:APP第九章(virtual memory)

2021-02-01 17:59:10  阅读:296  来源: 互联网

标签:APP virtual pages DRAM memory CS disk page


在这里插入图片描述

Recall that a DRAM is at least 10 times slower than an SRAM and that disk is about 100,000 times slower than a DRAM. Thus, misses in DRAM caches are very expensive compared to misses in SRAM caches because DRAM cache misses are served from disk, while SRAM cache misses are
usually served from DRAM-based main memory. Further, the cost of reading the first byte from a disk sector is about 100,000 times slower than reading successive bytes in the sector. The bottom line is that the organization of the DRAM cache is driven entirely by the enormous cost of misses.
Because of the large miss penalty and the expense of accessing the first byte, virtual pages tend to be large—typically 4 KB to 2 MB. Due to the large miss penalty, DRAM caches are fully associative; that is, any virtual page can be placed in any physical page. The replacement policy on misses also assumes greater importance, because the penalty associated with replacing the wrong virtual page
is so high. Thus, operating systems use much more sophisticated replacement algorithms for DRAM caches than the hardware does for SRAM caches. Finally, because of the large access time of disk, DRAM caches always use write-back instead of write-through.

页表的作用: maps virtual pages to physical pages.
判断一个virtual page是否在物理内存中,若在则要知道其dram位置;若不在则要知道其disk位置,且能提供一个替换决策。
在这里插入图片描述
PTE,page table entry
在图9.4中,VP05未分配,VP1247属于cached,VP36属于未cached

在这里插入图片描述

operating systems provide a separate page table, and thus a separate virtual address space, for each process. Notice that multiple virtual pages can be mapped to the same shared physical page.

使用VM的好处:
1.Simplifying linking. every process on a given Linux system has a similar memory format.
2.Simplifying loading. loader本身不需要把数据从disk搬运到dram,只需要在页表中分配virtual page.
3.the operating system can arrange for multiple processes to share a single copy of this code by mapping the appropriate virtual pages in different processes to the same physical pages.(如图9.9)
4.Simplifying memory allocation. 在VM中连续的page可以指向physical memory的多处(而无需连续分配)
5.内存保护,如图9.10
在这里插入图片描述

原书中关于地址翻译的部分我就跳过了。

在这里插入图片描述
每个segment在virtual memory中是连续的,不同segment在virtual memory中可以有gap。
在这里插入图片描述

在这里插入图片描述

at any point in time, the swap space bounds the total amount of virtual pages that can be allocated by the currently running processes.

mmap()系统调用使得进程之间通过映射同一个普通文件实现共享内存。普通文件被映射到进程地址空间后,进程可以像访问普通内存一样对文件进行访问,不必再调用read(),write()等操作。

P858,下次继续。

标签:APP,virtual,pages,DRAM,memory,CS,disk,page
来源: https://blog.csdn.net/weixin_42100211/article/details/113523084

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有