Presentation is loading. Please wait.

Presentation is loading. Please wait.

中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall 第七讲 存储器管理 中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall.

Similar presentations


Presentation on theme: "中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall 第七讲 存储器管理 中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall."— Presentation transcript:

1 中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall
第七讲 存储器管理 中国科学技术大学计算机系 陈香兰 2013Fall

2 内容提要 存储器的层次结构 程序执行的基础知识、程序的装入和链接 连续分配存储管理方式 分页存储管理方式 分段存储管理 段页式存储管理

3 存储器的层次结构 存储器是计算机系统的重要组成部分 在现代计算机系统中,存储通常采用层次结构来组织 容量、价格和速度之间的矛盾
内存、外存;易失性和永久性 内存,是稀缺资源 在现代计算机系统中,存储通常采用层次结构来组织 多级存储器结构 主存与寄存器 高速缓存和磁盘缓存

4 多级存储器结构 Storage systems in a computer system can be organized in a hierarchy Speed, access time Cost per bit Volatility

5 主存 vs. 寄存器 Same: Access directly for CPU Different: access speed
Register name Memory address Different: access speed Register, one cycle of the CPU clock Memory, Many cycles (2 or more) Disadvantage: CPU needs to stall frequently & this is intolerable Remedy Cache

6 高级缓冲技术caching Caching Using of caching
Copying information into faster storage system When accessing, first check in the cache, if In: use it directly Not in: get from upper storage system, and leave a copy in the cache Using of caching Registers provide a high-speed cache for main memory Instruction cache & data cache Main memory can be viewed as a fast cache for secondary storage ……

7 Magnetic disks 磁盘 Transfer time 传输时间 TT≈ data size * Transfer rate
Transfer rate ≈ (n M/s)-1 ≈ ( n Byte/us )-1 ≈ 1/n us/Byte Positioning time 定位时间 Seek time 寻道 Ts Rotational latency 旋转延迟 TR TP ≈ Ts +TR ≈ m ms TT VS. TP Please Store data closely

8 内容提要 存储器的层次结构 程序执行的基础知识、程序的装入和链接 连续分配存储管理方式 分页存储管理方式 分段存储管理 段页式存储管理

9 程序执行的基础知识 Von Neumann architecture 冯·诺依曼体系结构(图) Process
Program must be brought into memory Main memory is usually too small Process Program must be placed within a process for it to be executed 作业池 User programs Where to place the program several steps(图)

10

11

12 When can the absolute address can be decided?
地址的类型 Absolute address 绝对地址 Address seen by the memory unit Physical address 物理地址 Relative address 相对地址 Linear address 线性地址 Logical address 逻辑地址 Generated by the CPU Virtual address 虚拟地址 When can the absolute address can be decided?

13

14 Address binding 地址的绑定 Address binding 地址绑定, the binding of instructions and data to memory, 可以在三种时刻进行 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. 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)

15 逻辑地址空间和物理地址空间 Logical address space 逻辑地址空间
The set of all logical addresses generated by a program Physical address space 物理地址空间 The set of all physical addresses corresponding to theses logical addresses Logical = physical compile-time & load-time address-binding logical (virtual) != physical addresses execution-time address-binding MMU (hardware device)

16 Memory-Management Unit (MMU)
Hardware device, 逻辑地址  物理地址 Relocation register 重定位寄存器 Added to every address generated by a user process at the time it is sent to memory E.g. MS-DOS on 80x86 User program deals with logical addresses, it NEVER sees the real physical addresses.

17 是否需要将进程的所有代码和数据一次性装入?
Shall we put the entire program & data of a process in physical memory before the process can be executed? For better memory space utilization Dynamic loading Dynamic linking Overlays Swapping

18 程序的装入 绝对装入方式 可重定位装入方式 动态运行时装入方式

19 绝对装入方式 编译时,产生absolute code,即使用绝对地址的代码 装入时,必须装入到指定的地址 无需对程序和数据的地址进行修改
适用于单道系统

20 可重定位装入方式 大多数情况下,不能预知装入地址,只能在装入时确定 编译时,产生可重定位代码,即使用相对地址的代码 装入时,必须重定位
通常把在装入时对目标程序中指令和数据的修改过程称为重定位。 由于地址变换是在装入时一次性完成的,以后不再改变,故称为静态重定位 可用于多道系统

21 动态运行时重定位 有时候,程序会在内存中移动位置 需要能支持在运行过程中动态改变程序在内存中的位置
例如对换 需要能支持在运行过程中动态改变程序在内存中的位置 方法:推迟重定位时机 即从相对地址到绝对地址的转换推迟到程序真正执行时才进行 因此,装入内存中的代码和数据的地址仍然是相对地址 需要重定位寄存器的支持

22 动态运行时装入方式 根据程序运行的局部性,让程序及其数据在需要时才被装入
Better memory-space utilization; unused routine is never loaded. Useful when large amounts of code are needed to handle infrequently occurring cases Error routine No special support from OS is required implemented through program design Due to the users

23 Overlays 覆盖技术 Keep in memory only those are needed at any given time. Needed when process is larger than amount of memory allocated to it. Implemented by user, no special support needed from OS, programming design of overlay structure is complex

24 程序的链接 多个源程序编译多个目标模块;库。 需要链接成可装入模块 根据链接时间的不同 静态链接方式:装入前很早就链接
装入时动态链接:边装入,边链接 运行时动态链接:运行时才链接

25 静态链接方式 静态链接方式: 在程序运行之前,先将各目标模块以及它们所需要的库函数,链接成一个完整的装配模块,以后不再拆开。 要解决的问题:
各目标模块内:相对地址 存在目标模块之间的调用关系 外部调用符号 要解决的问题: 修改相对地址: 多个相对地址空间一个统一的相对地址空间 变换外部调用符号

26 装入时动态链接 在装入时,根据外部模块调用事件,使用装入程序去寻找相应的外部目标模块,并装入,在装入时,修改相对地址 优点: 便于修改和更新
便于实现对目标模块的共享

27 运行时动态链接 程序的每次运行,可能要执行的目标模块集是不同的 全部装入?按需装入? 运行时动态链接将对某些模块的链接推迟到程序执行时才进行
需要操作系统配合 优点:程序运行前的装入速度加快;省空间

28 作业: 从一个源程序到一个在内存中可执行的程序,一般需要哪几个步骤? 有哪几种地址类型? 有哪几种程序装入方式和链接方式?


Download ppt "中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall 第七讲 存储器管理 中国科学技术大学计算机系 陈香兰 xlanchen@ustc.edu.cn 2013Fall."

Similar presentations


Ads by Google