操作系统 CH8 Virtual Memory

合集下载

win8虚拟内存怎么开启

win8虚拟内存怎么开启

win8虚拟内存怎么开启win8虚拟内存开启方法一:1、右击“我的电脑”选择属性2、选择“高级”标签3、选择“性能”中的“设置”4、选择“高级”标签并选择“虚拟内存”中的“更改”5、选择一个空闲空间较大的非系统盘6、选择“自定义大小”并按照自己的内存大小分配(推荐设置自己内存大小的1.5~3倍,例如1gb的内存我们可以设置为2gb),但是系统要求输入以mb为单位的数值,(1gb=1024mb)。

(初始大小和最大值相同)7、点击“设置”根据提示选择“确定”,提示重启电脑以生效,重启电脑。

完成设置win8虚拟内存开启方法二:1、物理内存4g以内,虚拟内存一般设置为2倍的物理内存,比如1g的物理内存设置2g的虚拟内存。

通常这种情况,虚拟内存需要设置的较大一点。

2、物理内存4g以上,这时候设置虚拟内存一般是为了兼容较老的应用程序,一般设置在2gb~4gb即可。

3、具体设置:计算机右键——属性——高级系统设置——性能——设置——高级——虚拟内存,自定义大小,输入数字后点击“设置”,确定,退出重启系统即可。

win8虚拟内存开启方法三:1、要根据物理内存大小和个人使用情况来设置虚拟内存大小。

依次打开控制面板-管理工具-性能”,在出现的“性能”对话框中,展开左侧栏目中的“性能日志和警报”,选中其下的“计数器日志”,通过使用虚拟内存记录,计算虚拟内存的大小。

但这种方法很麻烦,一般使用一个大约值就可以了,如512mb物理内存,自定义虚拟内存,可选出设置小一点,如,初始值可设为512mb,最大值设为1024mb,如果在使用中发现不够用时,可再往大了设,如768/1653mb ,768/2048。

2、如果你只有一个硬盘,将虚拟内存设置在哪个分区中,对性能的影响都不是很大,但设置虚拟内存的分区一定要有足够的空间。

在一台电脑中,虚拟内存在一个分区中设置就够用了,不必在各个分区中设置虚拟内存。

3、置虚拟内存的方法是:右击我的电脑—属性—高级—性能设置—高级—虚拟内存更改—点选c盘—单选“自定义大小”—在下面的“初始大小”和“最大值”两个文本框中输入数值—“设置”—确定—重启,便完成了设置。

operating system《操作系统》ch08-main memory

operating system《操作系统》ch08-main memory
When a process arrives, it is allocated memory from a hole large enough to accommodate it
Operating system maintains information about: a) allocated partitions b) free partitions (hole)
8.12
Dynamic Linking
Linking postponed until execution time Small piece of code, stub, used to locate the appropriate memory-resident library routine Stub replaces itself with the address of the routine, and executes the routine Operating system needed to check if routine is in processes’ memory address Dynamic linking is particularly useful for libraries System also known as shared libraries
8.16
Contiguous Allocation (Cont.)
Multiple-partition allocation
Hole – block of available memory; holes of various size are scattered throughout memory
8.6
Binding of Instructions and Data to Memory

Red Hat Enterprise Linux 8 虚拟化配置和管理说明书

Red Hat Enterprise Linux 8 虚拟化配置和管理说明书

Red Hat Enterprise Linux 8配置和管理虚拟化设置您的主机、创建和管理虚拟机并了解 Red Hat Enterprise Linux 8 中的虚拟化功能Last Updated: 2023-08-03Red Hat Enterprise Linux 8 配置和管理虚拟化设置您的主机、创建和管理虚拟机并了解 Red Hat Enterprise Linux 8 中的虚拟化功能法律通告Copyright © 2023 Red Hat, Inc.The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.Linux ® is the registered trademark of Linus Torvalds in the United States and other countries. Java ® is a registered trademark of Oracle and/or its affiliates.XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other countries.Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.All other trademarks are the property of their respective owners.摘要要将 Red Hat Enterprise Linux (RHEL)系统用作虚拟化主机,请按照本文档中的说明操作。

为什么需要虚拟内存?虚拟内存的概念与实现

为什么需要虚拟内存?虚拟内存的概念与实现

为什么需要虚拟内存?虚拟内存的概念与实现面试的时候经常会被问到malloc 的实现。

从(操作系统)层面来说,malloc 确实是考察面试者对操作系统底层的存储管理理解的一个很好的方式,涉及到虚拟内存、分页/分段等。

下面逐个细说。

1. 虚拟内存首先需要知道的是程序运行起来的话需要被加载的物理内存中,具体到计算机(硬件)就是内存条。

操作系统启动的时候先把自己加载到物理内存的固定位置(一般为底部),物理内存的其他位置就用来运行用户程序。

程序就是一堆指令,程序运行可以简单抽象为把指令加载到内存中,然后(CPU)将指令从内存载入执行。

1. 为什么需要虚拟内存?CPU 对内存的寻址最简单的方式就是直接使用物理内存地址,这种方式一般叫做物理寻址。

早期的PC 使用物理寻址,而且像(数字信号)(处理器)、(嵌入式)(微控制器)也使用物理寻址。

物理寻址的好处是简单,坏处也有很多,比如:不安全:操作系统的地址直接暴露给用户程序,用户程序可以破坏操作系统。

这种解决方案是采用特殊的硬件保护。

同时运行多个程序比较困难:多个用户程序如果都直接引用物理地址,很容易互相干扰。

那么是不是可以通过不断交换物理内存和磁盘来保证物理内存某一时间自由一个程序在运行呢?当时是可以的,但是这引入很多不必要和复杂的工作。

用户程序大小受限:受制于物理内存大小。

我们现在的错觉是应用程序大小都小于物理内存,这主要是因为现在PC 的物理内存都比较大。

实际上只有1G 物理内存的PC 是可以运行2G 的应用程序的。

说明:1、chunk指针指向chunk开始的地址;mem指针指向用户内存块开始的地址。

2、p=0时,表示前一个chunk为空闲,prev_size才有效3、p=1时,表示前一个chunk正在使用,prev_size无效p主要用于内存块的合并操作;ptmalloc 分配的第一个块总是将p设为1, 以防止程序引用到不存在的区域4、M=1 为mmap映射区域分配;M=0为heap区域分配5、A=0 为主分配区分配;A=1 为非主分配区分配。

操作系统课件:ch9-虚拟内存(virtual memory)

操作系统课件:ch9-虚拟内存(virtual memory)
–请求分段调度(Demand segmentation)
虚拟内存的实现过程
1. 在程序装入时,不必将其全部读入到内存,而 只需将当前需要执行的部分页或段读入到内存, 就可让程序开始执行。
2. 在程序执行过程中,如果需执行的指令或访问 的数据尚未在内存(称为缺页或缺段),则由 处理器通知操作系统将相应的页或段调入到内 存,然后继续执行程序。
内存中可以放更多进程,并发度好,效率高
将需要的部分放入内存,有些用不到的部分从来不
放入内存,内存利用率高
Байду номын сангаас
如一些处理异常
程序开始执行、响应时间等更快
的代码!
虚拟内存思想既有利于系统,又有利于用户
如何实现虚拟内存!
虚拟内存
1.1 • 虚拟内存引入的原因 1.2 • 虚拟内存 1.3 • 虚拟内存的实现
•加载进程A
0
A.0
1
A.1
2
A.2
3
A.3
4
5
6
7
8
9
10
11
12
13
14
分页示例
•加载进程B
0
A.0
1
A.1
2
A.2
3
A.3
4
B.0
5
B.1
6
B.2
7
8
9
10
11
12
13
14
本章教学目标
• 虚拟内存引入的原因 • 虚拟内存 • 虚拟内存实现原理:调页 • 虚拟内存考虑的问题
一个游戏引起的联想…
用户眼里的内存!
4G 操作系统段
用户代码段
cs:ip 逻辑地址
用户数据段

operating system操作系统ch09 virtual memory 70 文档

operating system操作系统ch09 virtual memory 70 文档
algorithms, and allocation of page frames ? To discuss the principle of the working-set model
9.2
Content Overview
? Background ? Demand Paging ? Copy-on-Write ? Page Replacement ? Allocation of Frames ? ThrashБайду номын сангаасng ? Memory-Mapped Files ? Allocating Kernel Memory ? Other Considerations ? Operating-System Examples
9.12
Page Fault (Cont.)
? Restart instruction ? block move
? auto increment/decrement location
9.13
Steps in Handling a Page Fault
9.14
Performance of Demand Paging
9.3
9.1 Background
? Virtual memory – separation of user logical memory from physical memory.
? Only part of the program needs to be in memory for execution ? Logical address space can therefore be much larger than physical
1. Operating system looks at another table to decide:

操作系统课件:ch8-内存管理 (Memory Management ) (2)

操作系统课件:ch8-内存管理 (Memory Management ) (2)
动态分区时的回收与拼接
上空闲区
上空闲区
下空闲区
下空闲区
上下相邻区都是空闲 区
上相邻区是空闲区
下相邻区是空闲区 上下相邻区都不是空闲 区
本章教学目标
• 内存分配方法
✓分页 ✓分段 ✓段页式
内存管理
• 分页
1.1
1.2 • 分段 1.4 • 段页式
分页 (Paging)!
从连续到离散
只有吃到最后才能知道到底有多饿!
页框3
页2
页框2
页框1
页1
页框0
分页-内存保护
• 保护位
页号 0 1 2 3
页框号 5 1 3 7
保护 R
R/W R R
–每个Frame中有一个保护位(指示:可读、可写、 只可读),记录在页表中;在计算物理地址时, 可通过检查保护位来验证操作的正确性;
• 有效-无效位
–有效:表示相关的页在进程的逻辑地址空间内, 是有效页(可以访问)
第8章 内存管理 (Memory Management )
内容回顾:交换与覆盖
能让更多的进程并发
常驻程序 (操作系统)
进程2
装载后仍 需移动!
程序1仍 应该是可 重定位的!
进程12 进程1睡眠 换出 进程31 进程3睡眠 换出
进程1 进程3
内存
磁盘
再谈分配 碎片
• 碎片:很多小的内存空间
–内碎片:分区内的(分页、分段) –外碎片:分区与分区之间的
3
Intel x86结构的PTE
页框号 5 1
7
保护 R
R/W
R
有效 1 1 0 1
PWT PCD
页框号(物理页号)ppn

operating system《操作系统》ch08-main memory-57-PPT课件

operating system《操作系统》ch08-main memory-57-PPT课件

8.6
Binding of Instructions and Data to Memory
Address binding of instructions and data to memory
addresses can happen at three different stages

Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes Load time: Must generate relocatable code if memory location is not known at compile time
Routine is not loaded until it is called Better memory-space utilization; unused routine is never


Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers)
8.4
Base and Limit Registers
A pair of base and limit registers define the logical addressress protection with base and limit registers

Linux0.11内核在X86下的内存管理(MMU)学习笔记

Linux0.11内核在X86下的内存管理(MMU)学习笔记

Linux0.11内核在X86下的内存管理(MMU)学习笔记最近看了很多关于内存管理的资料,总结异同,记录下近期学习的⼼得,以后,可能没这么多时间写⼼得了。

1 基本概念1.1物理内存在Linux0.11内核中,为了有效的使⽤机器中的物理内存,在系统初始化阶段内存被划分成为⼏个功能区域,如下图:其中,Linux内核程序占据在物理内存的开始部分,接下来是供硬盘或软盘等块设备使⽤的⾼速缓冲部分(其中要扣除显卡内存和ROM BIOS所占⽤的内存地址范围640K—1MB)。

当⼀个进程需要读取块设备中的数据时,系统会⾸先把数据读到⾼速缓冲区中;当有数据需要⽤到块设备上去时,系统也是先将数据放到⾼速缓冲区中,然后由块设备驱动程序写到相应的设备上。

内存的最后部分是供所以程序可以随时申请和使⽤的主内存区。

内核程序在使⽤主内存区是,也同样⾸先要向内核内存管理模块提出申请,并在申请成功后⽅能使⽤。

对于含有RAM虚拟盘的系统,主内存区头部还要划去⼀部分,供虚拟盘存放数据。

1.2内存寻址内存是指⼀组有序字节组成的数组,每个字节有唯⼀的内存地址。

内存地址则是指对存储在内存中的某个指定数据对象的地址进⾏定位。

数据对象是指存储在内存中的⼀个指定数据类型的数值或字符串。

80X86⽀持多种数据类型:1字节、2字节(1个字)、或4字节(双字或长字)的⽆符号整型数或带符号整型数,以及多字节字符串等。

对于80X86CPU来说,其地址总线宽度为32位,因此可寻址的地址空间范围是0—2^32(4GB)的物理内存,这是就产⽣⼀个冲突,我们实际上使⽤的物理内存⼀般没有4GB 这么⼤阿,怎么办,于是就引⼊了⼀个关键的技术:内存管理(MMU)。

1.3 地址转换过程中3个特殊地址的概念虚拟地址(VA, Virtual Address)是指由程序产⽣的由段选择符和段内偏移地址两个部分组成的地址。

因为这两部分组成的地址并没有直接⽤来访问物理内存,⽽是需要通过分段地址变换机制处理或映射后才对应到物理内存地址上,因此这种地址被称为虚拟地址。

operating system操作系统-ch08-main memory-57 共58页

operating system操作系统-ch08-main memory-57 共58页
Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped
Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows)
Logical address – generated by the CPU; also referred to as virtual address
Physical address – address seen by the memory unit
Logical and physical addresses are the same in compiletime and load-time address-binding schemes;
8.3
8.1 Background
Program must be brought (from disk) into memory and placed within a process for it to be run
Main memory and registers are only storage CPU can access directly
8.4
Base and Limit Registers
A pair of base and limit registers define the logical address space
8.5
HW address protection with base and limit registers

x86硬件辅助虚拟化技术解析

x86硬件辅助虚拟化技术解析

x86硬件辅助虚拟化技术解析HJCBUG 《微型计算机》2010年4月下期2010-05-13在计算机领域,虚拟化技术从最初概念的提出到现在已经走过了几十个年头。

虚拟化技术在很多领域都已经被广泛运用,但我们最常用的x86平台却迟迟没有提供硬件级虚拟化支持。

近几年来x86平台硬件性能大幅提高,硬件资源浪费的现象越来越严重。

而虚拟化技术可以在一台计算机上运行多个独立的虚拟操作系统,维护成本和其它非技术成本会有相当程度的降低。

随着英特尔和AMD的硬件辅助虚拟化技术的成熟,虚拟化技术成了近来IT界的热点话题。

然而,大家对于虚拟化的认识大多还停留在字面理解上,什么是虚拟化?x86硬件辅助虚拟化(Intel VT和A MD-V)又是怎么一回事呢?希望本文能够为大家解开谜团。

2005年英特尔发布了第一款支持虚拟化技术的处理器,其竞争对手A MD也在2006年紧接着将虚拟化技术应用到处理器产品上。

随着两大核心平台厂商虚拟化技术的逐渐成熟并获得周边虚拟化软件厂家的支持,硬件辅助虚拟化正以不可阻挡之势来到众人面前,越来越多的桌面CPU和芯片组开始支持虚拟化技术,让这个以前主要应用在服务器和大型机领域的技术渐渐走入寻常百姓家。

从表格中大家就能够看出,硬件辅助虚拟化技术可以说囊括了计算机体系架构中最重要的几个方面,而且还在一直发展当中。

到现在为止,两家的CPU虚拟化技术走过了四五年时间已经慢慢成熟,内存和I/O虚拟化也都有了成熟的规范,可以说已经进入了虚拟化2.0的时代。

英特尔/AMD硬件辅助虚拟化技术对比虚拟化起源于对分时系统的需求,在1959年的国际信息处理大会上,一篇名为《大型高速计算机中的时间共享》被认为是虚拟化技术的最早论述。

抽象地说,虚拟化是资源的逻辑表示,它不会受物理限制的约束。

在计算机科学方面的虚拟化定义有很多种,其中有一种定义笔者认为相对更贴切和便于理解:“虚拟化是以某种用户和应用程序都可以很容易从中获益的方式来表示计算机资源的过程,而不是根据这些资源的实现、地理位置或物理包装的专有方式来表示它们。

虚拟存储器word版

虚拟存储器word版

虚拟存储器虚拟存储器(Virtual Memory虚拟存储器(Virtual Memory):在具有层次结构存储器的计算机系统中,自动实现部分装入和部分替换功能,能从逻辑上为用户提供一个比物理贮存容量大得多,可寻址的“主存储器”。

虚拟存储区的容量与物理主存大小无关,而受限于计算机的地址结构和可用磁盘容量。

作用虚拟内存的作用内存在计算机中的作用很大,电脑中所有运行的程序都需要经过内存来执行,如果执行的程序很大或很多,就会导致内存消耗殆尽。

为了解决这个问题,Window虚拟存储器s中运用了虚拟内存技术,即拿出一部分硬盘空间来充当内存使用,当内存占用完时,电脑就会自动调用硬盘来充当内存,以缓解内存的紧张。

举一个例子来说,如果电脑只有128MB 物理内存的话,当读取一个容量为200MB的文件时,就必须要用到比较大的虚拟内存,文件被内存读取之后就会先储存到虚拟内存,等待内存把文件全部储存到虚拟内存之后,跟着就会把虚拟内存里储存的文件释放到原来的安装目录里了。

编辑本段设置虚拟内存的设置对于虚拟内存主要设置两点,即内存大小和分页位置,内存大小就是设置虚拟内存最小为多少和最大为多少;而分页位置则是设置虚拟内存应使用那个分区中的硬盘空间虚拟存储器。

对于内存大小的设置,如何得到最小值和最大值呢?你可以通过下面的方法获得:选择“开始→程序→附件→系统工具→系统监视器”(如果系统工具中没有,可以通过“添加/删除程序”中的Windows安装程序进行安装)打开系统监视器,然后选择“编辑→添加项目”,在“类型”项中选择“内存管理程序”,在右侧的列表选择“交换文件大小”。

这样随着你的操作,会显示出交换文件值的波动情况,你可以把经常要使用到的程序打开,然后对它们进行使用,这时查看一下系统监视器中的表现值,由于用户每次使用电脑时的情况都不尽相同,因此,最好能够通过较长时间对交换文件进行监视来找出最符合您的交换文件的数值,这样才能保证系统性能稳定以及保持在最佳的状态。

虚拟存储器

虚拟存储器

1 1 1 1 1 1* 3* 3* 3 3
最优替换 OPT算法
2 2 2 2* 2 2 2 2 2
5次
5* 4 4 4 4 4 4
调入 调入 命中 调入 替换 命中 替换 命中 命中 命中
页式虚拟存储器替换策略
例1:一个程序共有5个页面组成,在程序执行过程中,页面地址流 如下, P1、 P2、 P1、 P5、 P4、 P1、 P3、 P4、 P2、 P4,假 设在程序执行过程中分配给这个程序的主存储器只有3个页面。
虚拟存储器
什么是虚拟存储器
虚拟存储器是建立在主存—辅存物理结构的基础之上,由附加的硬件 装置及操作系统存储管理软件组成的一种存储体系。
例如:一个只提供128M字节DRAM的计算机,可以用硬盘高效提供 2GB的存储。较大的2GB存储空间被称为虚拟存储器(virtual memory), 较小的128MB主存称为物理存储器(physical memory)
3、CPU访问Cache比访问慢速主存快5~10倍;而虚存中主存速度比辅 存快100~1000倍;
虚拟存储器与cache存储器比较
两者也有许多不同之处: 4、主存—cache体系中,CPU与二者都有直接的通路;而虚存中辅存
与CPU之间无直接通路(辅存向主存调块时间为ms级); 5、Cache存储器存取信息、地址变换和替换策略全部用硬件实现,因
虚拟存储器与cache存储器比较
两者也有许多不同之处: 1、Cache为了弥补速度差距;而虚存主要用来弥补容量差距; 2、两个存储体系均以信息块作为存储层次之间信息传送的单位,但
Cache与主存每次传送的信息块定长,常为几十个字节;而主存和 辅存之间即虚拟信息块的划分却有多种方案:页、段等,块长通 常为几百~几百K字节;

CCH10_Virtual memory(操作系统)

CCH10_Virtual memory(操作系统)

CPU检索快表 检索快表
是 否

页表项是否在快表中? 页表项是否在快表中 ? 产生缺页中
是 断请求调页 是

访问页表 页是否在内存中 ? 修改快表 修改访问位和修改位 形成物理地址
将一页从外存换入内存 地址变换结束 修改页表
Steps in Handling a Page Fault
Steps in handling a page fault
• • •
缺页中断在指令执行期间产生和处理中断信号, 缺页中断在指令执行期间产生和处理中断信号,而一般中断在一条 指令执行完后检查和处理中断信号。 指令执行完后检查和处理中断信号。 缺页中断返回到该指令的开始重新执行该指令, 缺页中断返回到该指令的开始重新执行该指令,而一般中断返回到 该指令的下一条指令执行。 该指令的下一条指令执行。 一条指令在执行期间,可能产生多次缺页中断。 一条指令在执行期间,可能产生多次缺页中断。
9.1 Background
Virtual memory is a technique that allows the execution of processes that may not be completely in memory.(虚拟内存是一 ( 种允许进程部分装入内存就可以执行的技术) 种允许进程部分装入内存就可以执行的技术) principle of locality局部性原理 : 时间局部性,空间局部性 局部性原理 时间局部性, Only part of the program needs to be in memory for execution (只有运行的部分程序需要在内存中). 只有运行的部分程序需要在内存中) Logical address space can therefore be much larger than physical address space(逻辑地址空间能够比物理地址空间大). (逻辑地址空间能够比物理地址空间大) Need to allow pages to be swapped in and out(必须允许页面 ( 能够被换入和换出) 能够被换入和换出). Virtual memory can be implemented via(虚拟内存能够通过以下手 段来执行): Demand paging (请求页式) Demand segmentation(请求段式)

operating system操作系统-ch09-virtual memory-70

operating system操作系统-ch09-virtual memory-70
Swapper that deals with pages is a pager
9.8
Transfer of a Paged Memory to Contiguous Disk Space
9.9
Valid-Invalid Bit
With each page table entry a valid–invalid bit is associated (v in-memory, i not-in-memory)
= (1 – p x 200 + p x 8,000,000 = 200 + p x 7,999,800
If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds.
This is a slowdown by a factor of 40!!
9.29
FIFO Illustrating Belady’s Anomaly
9.18
Before Process 1 Modifies Page C
9.19
After Process 1 Modifies Page C
9.20
What happens if there is no free frame?
Page replacement – find some page in memory, but not really in use, swap it out
9.3
9.1 Background
Virtual memory – separation of user logical memory from physical memory.
Only part of the program needs to be in memory for execution Logical address space can therefore be much larger than physical address space Allows address spaces to be shared by several processes Allows for more efficient process creation

operating system《操作系统》ch09-virtual memory-70-PPT精品文档

operating system《操作系统》ch09-virtual memory-70-PPT精品文档

only modified pages are written to disk
Page replacement completes separation between logical
memory and physical memory – large virtual memory can be provided on a smaller physical memory
Virtual memory can be implemented via:

Demand paging Demand segmentation
9.4
Virtual Memory That is Larger Than Physical Memory

9.5
Virtual-address Space
9.6
Shared Library Using Virtual Memory
9.7
9.2 Demand Paging
Bring a page into memory only when it is needed

Less I/O needed Less memory needed Faster response
= (1 – p x 200 + p x 8,000,000 = 200 + p x 7,999,800
If one access out of 1,000 causes a page fault, then
EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!


Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

ch8-虚拟内存

ch8-虚拟内存

现在
-8-
从段页式内存管理开始
段号+偏移(cs:ip) 逻辑地址
段号 0 1 2 3 基址 0x4000 0x4800 0xF000 0x0000 长度 0x0800 0x1400 0x1000 0x3000 保护 R R/W R/W R
部分逻辑地址对 应段表项,发现 缺段后调入
部分线性地址对 应页表项,发现 缺页后调入
继续上面的实例: (3frame)A B C A B D A D B C B A B C A B D A D B C B 页码栈 A B A C B A A C B B A C D B A A D B D A B B D A C B D B C D
选栈底页淘汰! 每次地址访问都需要修改栈(修改10次左右栈指 针) … 实现代价仍然较大 LRU准确实现用的少
- 24 -
Clock算法分析的改造
R=1
R=1
R=1
R=0
R=0 R=1
R=0
R=1 R=1 R=1
如果缺页很少,会? 所有的R=1 R=0 R=0 hand scan一圈后淘汰当前页,将调入页 插入hand位置,hand前移一位 退化为FIFO! 更像 原因: 记录了太长的历史信息… 怎么办? Clock吧! 定时清除R位… 再来一个扫描指针! R=1
-2-
内存不够怎么办?
最大 栈
页0 页1 页2
堆 数据 代码
内存映射
0
页m
物理内存
-3-
辅存(磁盘)
用户虚拟地址空间 虚拟内存
内存管理视图
4G 操作系统段
0x7008
用户代码段
0x00345008
cs:ip
用户数据段

第三章x86的虚拟存储系统

第三章x86的虚拟存储系统

第三章x86的虚拟存储系统Linux操作系统当前主要在Intel 80386、80486和Petium系列机器上运行,它们统称为x86机器。

x86具有两种存储器管理模式:实地址模式和受保护的虚地址模式,后者简称保护模式。

在实地址模式下,CPU只能寻址1MB的内存空间。

在保护模式下,x86提供了实现虚拟存储的硬件机制,它是操作系统实现多进程〔多进程〕存储管理以及提供存储保护的硬件根底。

§3.1 80386的虚拟地址空间x86的系统结构中专门设置了用于实现虚拟存储技术的硬件机制,即分页和分段机制。

各个进程的存储区域彼此隔离,每个进程都可以独立使用自己的虚拟地址空间,从而保证了进程的信息平安。

一.x86的地址转换机制程序代码和数据都是存放在内存储器中,内存储器又称物理存储器,物理存储器是CPU可以直接访问的存储空间。

80386机器的地址总线为32位,由它确定的物理地址空间的范围可达232字节,即4G字节。

指令中访问存储空间的地址称为逻辑地址,由逻辑地址确定的存储空间称为逻辑地址空间。

x86的逻辑地址为48位,由它确定的逻辑地址空间可达64T字节。

逻辑地址必须转换成物理地址后才能访问物理存储器。

在x86中逻辑地址由分段机制把逻辑地址转换成线性地址。

再由分页机制把线性地址转换成物理地址。

二.80386的虚拟地址空间x86把虚拟地址空间分成性质不同的两局部:全局地址空间和局部地址空间。

全局地址空间是系统中所有的进程共享的地址空间,通常存放操作系统资源和数据。

局部地址空间由各个进程使用,用于存储进程各自的代码和数据等。

x86分段机制对虚拟地址空间实行分段管理,把虚拟地址空间分成大小不同的存储段。

一个段的空间最大可达232字节,即4GB。

64TB的虚拟地址空间最多可以分为16 K个段。

其中全局地址空间和局部地址空间最多可以各有8K个段,称为全局段和局部段。

§段描述符表一.段描述符表在分段存储管理中,使用段描述符表记录各个进程使用的段空间位置、大小和有关属性。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

6
Thrashing(颠簸)
Swapping out a piece of a process just before that piece is needed The processor spends most of its time swapping pieces rather than executing user instructions
32
Page Size
Small page size, large number of pages will be found in main memory As time goes on during execution, the pages in memory will all contain portions of the process near recent references. Page faults low. Increased page size causes pages to contain locations further from any recent reference. Page faults rise.
Virtual Memory
Chapter 8
1
Hardware and Control Structures
A process may be swapped in and out of main memory such that it occupies different regions. Memory references are dynamically translated into physical addresses at run time A process may be broken up into pieces that do not need to located contiguously in main memory All pieces of a process do not need to be loaded in main memory during execution
A process may be larger than all of main memory
5
Types of Memory
Real memory
Main memory
Virtual memory
Memory on disk Allows for effective multiprogramming and relieves the user of tight constraints of main memory
22
Inverted Page Table
Page number Process identifier Control bits Chain pointer
23
Translation Lookaside Buffer
Each virtual memory reference can cause two physical memory accesses
26
Translation Lookaside Buffer
First checks if page is already in main memory
If not in main memory a page fault is issued
The TLB is updated to include the new page entry
2
Execution of a Program
Operating system brings into main memory a few pieces of the program Resident set - portion of process that is in main memory An interrupt(Page Fault) is generated when an address is needed that is not in main memory.Operating system places the process in blocking state
27
Translation Lookaside Buffer
28
Translation Lookaside Buffer
29
30
31
Page Size
Smaller page size, less amount of internal fragmentation Smaller page size, more pages required per process More pages per process means larger page tables Larger page tables means large portion of page tables in virtual memory Secondary memory is designed to efficiently transfer large blocks of data so a large page size is better
4
Advantages of Breaking up a Process
More processes may be maintained in main memory
Only load in some of the pieces of each process With so many processes in main memory, it is very likely a process will be in the Ready state at any particular time
Virtual Address Space
11
Virtual Address and Page Table Entry
12
Page Table Entry(PTE)
13
Modify Bit in Page Table
Modify bit is needed to indicate if the page has been altered since it was last loaded into main memory If no change has been made, the page does not have to be written to the disk when it needs to be swapped out
24
Translation Lookaside Buffer
25
Translation Lookaside Buffer
Given a virtual address, processor examines the TLB If page table entry is present (TLB hit), the frame number is retrieved and the real address is formed If page table entry is not found in the TLB (TLB miss), the page number is used to index the proceeded for Virtual Memory
Hardware must support paging and segmentation Operating system must be able to manage the movement of pages and/or segments between secondary memory and main memory
9
Paging
10
Paging
Each process has its own page table Each page table entry contains the frame number of the corresponding page in main memory.
A bit is needed in PTE to indicate whether the page is in main memory or not
7
Principle of Locality(局部性原理)
Program and data references within a process tend to cluster Only a few pieces of a process will be needed over a short period of time Possible to make intelligent guesses about which pieces will be needed in the future This suggests that virtual memory may work efficiently
14
Address Translation(Mapping)
15
Address Translation (Cont.)
16
Address Translation (Cont.)
17
Page Tables
The entire page table may take up too much main memory Page tables are also stored in virtual memory When a process is running, part of its page table is in main memory
3
Execution of a Program (Cont.)
Piece of process that contains the logical address is brought into main memory
相关文档
最新文档