标签:空间 poi hit constant 过程 for resources dram 例子
1.虚拟地址数=2^(虚拟地址位数)
最大可能的虚拟空间=虚拟地址数-1
2.
使用虚拟寻址,CPU需要将虚拟地址转换成物理地址,这样才能访问真实的物理内存
concepts:1)VM on disk,PM (DRAM cache)
2)page--cache blocks
3.page tables :an array of PTEs(page table entry) that map VP to PP
虚拟内存空间被组织为一个存放在硬盘上的M个连续的字节大小的单元组成的数组,每个字节都有一个唯一的虚拟地址
页数=虚拟地址数/页大小,每个页都需要一个PTE
操作系统通过将虚拟内存分割为大小固定的块来作为硬盘和内存之间的传输单位,这个块被称为虚拟页(Virtual Page, VP),每个虚拟页的大小为P=2^p
字节。物理内存也会按照这种方法分割为物理页(Physical Page, PP),大小也为P
字节。
CPU在获得虚拟地址之后,需要通过MMU将虚拟地址翻译为物理地址。而在翻译的过程中还需要借助页表
VP1,VP2,VP7,VP4被缓存到物理内存中(cached),VP3,VP6已被分配但尚未缓存到物理内存(uncached),VP0和VP5尚未分配(unallocated)
4.page hit
MMU根据虚拟地址在页表中寻址到PTE4,有效位为1,说明已经缓存到物理内存中,根据页表映射关系,指向PP1
5.page fault
虚拟页没有缓存在物理内存中
page fault execute page fault handler in kernel
page fault handler 选一个victim 在下述例子中选的是存放在PP3的VP4
如果牺牲页已被修改过,内核会先将它复制回硬盘(采用写回机制而不是直写也是为了尽量减少对硬盘的访问次数)
Kernel从disk复制VP3到PP3,更新PTE3
page fault handler 返回,重新执行导致缺页的命令
KEY POINT:demand paging
wait until the miss to copy the page to DRAM
In a system that uses demand paging, the operating system copies a disk page into physical memory only if an attempt is made to access it and that page is not already in memory (i.e., if a page fault occurs). It follows that a process begins execution with none of its pages in physical memory, and many page faults will occur until most of a process‘s working set of pages are located in physical memory.
6.局部性
根据空间局部性原则(一个被访问过的内存地址以及其周边的内存地址都会有很大几率被再次访问)与时间局部性原则(一个被访问过的内存地址在之后会有很大几率被再次访问),只要将工作集缓存在物理内存中,接下来的地址翻译请求很大几率都在其中,从而减少了额外的硬盘流量。
if(working set size<main memory size) after cold miss good performance for one process
if(working set size>main memory size)thrashing thrashing occurs when a computer‘s virtual memory resources are overused, leading to a constant state of paging and page faults, inhibiting most application-level processing.
Main memory refers to physical memory that is internal to the computer.
标签:空间 poi hit constant 过程 for resources dram 例子
原文地址:https://www.cnblogs.com/wwqdata/p/12000123.html