版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Chapter 9: Memory Management,Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging *,Operating System Concepts,9.1 Background,Program must be brought into memory and placed within a process for it to be run. Input queue the collection of processes on the disk that ar
2、e waiting to be brought into memory to run the program. The normal procedure is to select one of the processes in the input queue and to load that process into memory. Most systems allow a user process to reside in any part of the physical memory.,Operating System Concepts,9.1.1 Address Binding,Usua
3、lly, user programs go through several steps before being run. Addresses may be represented in different ways during these steps. Addresses in source program are generally symbolic ( such as count, i, j etc.) Compiler typically binds these symbolic addresses to relocatable addresses (such as “14 byte
4、s from the beginning of this module”) Linkage editor or loader will bind these relocatable addresses to absolute addresses in turn. Each binding is a mapping from one address space to another.,Operating System Concepts,9.1.1 Address Binding (1),Binding of instructions and data to memory addresses ca
5、n happen at three different stages. Compile time - If known starting location in memory, absolute code can be generated; but must recompile code if starting location changes. ( e.g. .COM files in MS-DOS) Load time - Must generate relocatable code if memory location is not known at compile time. The
6、final binding is delayed until load time. Execution time Binding is delayed until run time, if the process can be moved during its execution from one memory segment to another. Need special hardware support for address maps (e.g., base and limit registers). Used by most general-purpose OS,Operating
7、System Concepts,Operating System Concepts,Multistep Processing of a User Program,Return,9.1.2 Logical vs Physical Address Space,The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. Logical address generated by CPU; also ref
8、erred to as virtual address. The set of all logical addresses generated by a program is a logical-address space. Physical address address seen by the memory unit. The set of all physical addresses corresponding to these logical addresses is a physical-address space. Compile-time and load-time addres
9、s-binding schemes generate identical logical and physical addresses; but they differ in execution-time address-binding scheme.,Operating System Concepts,9.1.2 Logical vs Physical Address Space(1),Memory-Management Unit (MMU) - Hardware device that maps virtual address to physical address in run-time
10、. In MMU scheme, value in relocation register is added to every address generated by a user process when it is sent to memory. Ranges for different types of addresses Logical addresses range 0 to max Physical addresses - range R+0 to R+max for a base value R The user program deals with logical addre
11、sses and never sees the real physical addresses. - User only thinks that the process runs in location 0 to max.,Operating System Concepts,9.1.2 Logical vs Physical Address Space(2),Dynamic relocation using a relocation register,Operating System Concepts,9.1.3 Dynamic Loading,Dynamic loading Routine
12、is not loaded until it is called, which are kept on disk in a relocatable load format. Used to obtain better memory-space utilization. Unused routine is never loaded. It is useful when large amounts of code are needed to handle cases occurring infrequently. No special support is required from the op
13、erating system when implemented through program design. Operating system can provide library routines to implement dynamic loading for programmer.,Operating System Concepts,9.1.4 Dynamic Linking,Linking is postponed until execution time. Small piece of code, stub, used to locate the appropriate memo
14、ry-resident library routine. Stub replaces itself with the address of the routine, and executes the routine. Operating system needed to check if the routine is in processes (itself or another) memory address. Dynamic linking is particularly useful for shared libraries updating (such as bug fixes) ,
15、which called dynamically linked libraries (DLL).,Operating System Concepts,9.1.5 Overlays,Overlays to keep in memory only those instructions and data that are needed at any given time. When other instructions are needed, they are loaded into space occupied previously by instructions that are no long
16、er needed. Needed when process is larger than the amount of memory allocated to it. Implemented by user, no special support needed from operating system, programming design of overlay structure is complex. Overlays is currently limited to microcomputer and other systems that have limited amounts of
17、physical memory and that lack hardware support for more advanced techniques.,Operating System Concepts,Operating System Concepts,Overlays for a Two-Pass Assembler,9.2 Swapping,A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execu
18、tion. Backing store a fast disk that must be large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images. Roll out, roll in a variant of swapping policy is used for priority-based scheduling algorithms; lower-priority process is swapped ou
19、t, so higher-priority process can be loaded and executed. 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 used in many systems, e.g., UNIX, Linux, and Windows. Only used when the load on the sys
20、tem is high, or it is disable.,Operating System Concepts,Schematic View of Swapping,Operating System Concepts,9.3 Contiguous Allocation,Main memory is usually divided into two partitions: System area - usually in low memory, used to hold resident operating system with interrupt vector. User area - i
21、n high memory, used to hold user processes. Memory protection is needed. Relocation-register scheme is used to protect user processes from each other, and from changing operating-system code and data. Relocation register contains the value of the smallest physical address; limit register contains th
22、e range of the logical addresses each logical address must be less than the limit register.,Operating System Concepts,9.3 Contiguous Allocation (1),Hardware Support for Relocation and Limit Registers,Operating System Concepts,9.3 Contiguous Allocation (2),Single-partition allocation only one user pr
23、ocess is contained in user area. Only used in single-user, single-task system, such as MS-DOS、CP/M、RT-11. Multiple-partition allocation The simplest is to divided memory into several fix-sized partitions, called fix-sized partition allocation, which is the earliest method for multiprogramming and is
24、 no longer in use. The degree of multiprogramming is bound by the number of partitions. Now, vary-sized partition allocation is used. Hole one block of available memory; a set of holes, of various size, are scattered throughout memory at any time.,Operating System Concepts,9.3 Contiguous Allocation
25、(3),When a process arrives, it is allocated memory from a hole large enough to accommodate it. When it terminates, it releases its block of memory, which is then placed back in the set of holes. This is dynamic allocation. Operating system maintains information in a table about:a) allocated partitio
26、ns b) free partitions (hole),Operating System Concepts,9.3 Contiguous Allocation (4),Dynamic Storage-Allocation Problem - How to satisfy a request of size n from a list of free holes. First-fit- Allocate the first hole that is big enough. Searching can start either at the beginning of the list or wh
27、ere the previous first-fit search end. Searching stops as soon as finding a free hole that is large enough. Best-fit - Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. produces the smallest leftover hole. Worst-fit - Allocate the largest hole; must also
28、 search entire list , unless ordered by size. Produces the largest leftover hole. First-fit and best-fit better than worst-fit in terms of speed and storage utilization.,Operating System Concepts,9.3 Contiguous Allocation (5),External Fragmentation the total free memory space exists to satisfy a req
29、uest, but it is not contiguous; storage is fragmented into a large number of small holes. Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. Reduce external fragmentation by compaction Shuf
30、fle memory contents to place all free memory together in one large block. Compaction is possible only if relocation is dynamic, and is done at execution time. Another possible solution - to permit the logical-address space of a process to be noncontiguous; process is allocated physical memory whenev
31、er the latter is available. Paging and segmentation can achieve this.,-Fragmentation,Operating System Concepts,9.4 Paging,Basic Method Hardware Support Memory Protection Structure of Page Table Shared Pages,Operating System Concepts,9.4.1 Basic Method,Permits the logical address space of process can
32、 be noncontiguous. Divide physical memory into fixed-sized blocks called frames Size of frame is a power of 2, between 512 bytes and 16M bytes, depending on computer architecture. Today, pages typically are between 4KB and 8KB. Selection of a power of 2 as page size makes the translation of a logica
33、l address into a page number and page offset particularly easy. Divide logical memory into blocks of same size called pages. To run a program of size n pages, need to find n free frames and load program. Internal fragmentation can never be used.,Operating System Concepts,9.4.1 Basic Method(1),Set up
34、 a page table to translate logical to physical addresses. (When a page table is used?) Each address generated by CPU is divided into: Page number (p) used as an index into a page table which contains base address of each page in physical memory. Page offset (d) combined with base address to define t
35、he physical memory address that is sent to the memory unit. If the size of logical-address space is 2m, and a page size is 2n addressing units, then the high-order m-n bits of a logical address designate the page number and the n low-order bits designate the page offset.,-Address Translation Scheme,
36、Operating System Concepts,Operating System Concepts,9.4.1 Basic Method (2),Paging model of logical and physical address,9.4.1 Basic Method (3),To manage physical memory, OS needs to keep track of all free frames by a frame table for the allocation details of physical memory. Frame table a data struc
37、ture to record which frames are allocated, which frames are available, how many total frames there are, and so on. (When it is used?) Each physical page frame has one entry in the frame table, indicating whether the frame is free or allocated and, if it is allocated, to which page of which process o
38、r processes.,Operating System Concepts,Operating System Concepts,9.4.1 Basic Method (4),Address Translation Architecture,Operating System Concepts,9.4.1 Basic Method(5),Paging Example show how the users view of memory can be mapped into physical memory. Question: if the page size is 2048 byte, a pro
39、cess have 72766 bytes. How many pages would it need?,Operating System Concepts,9.4.1 Basic Method (6) -Free Frames,Before allocation,After allocation,9.4.1 Basic Method (7),*If a process arriving in the system requires n pages, at least n frames must be available in memory. If n frames are available
40、, they are allocated to this arriving process. The first page of the process is loaded into one of the allocated frames, and the frame number is put in the page table for this process. The next page is loaded into another frame, and its frame number is put into the page table. An important aspect of
41、 paging is the clear separation between the users view of memory and the actual physical memory. User views memory as one single contiguous space, containing only this one program. In fact, user program is scattered throughout physical memory, which also holds other programs. Operation of logical ad
42、dresses translated into physical addresses is hidden from the user and is controlled by OS.,Operating System Concepts,9.4.2 Hardware Support,Page table can be implemented as a set of dedicated registers when it is reasonably small (i.e. 256 entries). Most contemporary computers allow page table to b
43、e very large. Page table is kept in main memory. Page-table base register (PTBR) points to the page table. Changing page tables needs changing only this one register. Page-table length register (PTLR) indicates the size of a page table. In this scheme every data/instruction access requires two memor
44、y accesses. One for the page table and one for the data/instruction. This problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs),Operating System Concepts,9.4.2 Hardware Support (1),Associative memory parallel searc
45、h with all keys Address translation (A, A) If A is in associative register, get frame# out. Otherwise get frame# from page table in memory,Operating System Concepts,Operating System Concepts,9.4.2 Hardware Support (2),Paging Hardware With TLB,9.4.2 Hardware Support (3),Associative Lookup (Time for s
46、earch TLB) = time unit Assume memory cycle time is 1 microsecond Hit ratio percentage of times that a page number is found in the associative registers; ration related to number of associative registers. Hit ratio = Effective Access Time (EAT) EAT = (1 + ) + (2 + )(1 ) = 2 + ,- Effective Access Time
47、 *,Operating System Concepts,9.4.3 Memory Protection,Memory protection implemented by associating protection bit with each frame. And these bits are kept in page table. Valid-invalid bit attached to each entry in the page table: “valid” - indicates that the associated page is in the process logical
48、address space, and is thus a legal page. “invalid” - indicates that the page is not in the process logical address space. Another solution to verify whether the logical address is in the valid rang for the process is to use page-table length register (PTLR) .,Operating System Concepts,Operating Syst
49、em Concepts,Valid (v) or Invalid (i) Bit In A Page Table,9.4.4 Structure of Page Table,Hierarchical Paging Hashed Page Tables * Inverted Page Tables *,Operating System Concepts, Hierarchical Paging,Most modern computer systems support a larger logical-address space( 232 264). So the page tabl
50、e becomes excessively large. Break up the logical address space into multiple smaller page tables. A simple technique is a two-level page table page table itself is also paged. Such as VAX is a 32-bits machine, supporting a variation of two-level paging. (section+ page+offset) Two-level paging schem
51、e is no longer appropriate for a system with a 64-bits logical-address space. Outer page table is paged. So three-level, even four-level paging scheme is needed. In fact, for 64-bits architectures, hierarchical page tables are considered inappropriate.,Operating System Concepts, Hierarchical
52、Paging (1),A logical address (on 32-bit machine with 4K page size) is divided into: a page number consisting of 20 bits. a page offset consisting of 12 bits. Since the page table is paged, the page number is further divided into: a 10-bit page number. a 10-bit page offset. Thus, a logical address is
53、 as follows: where p1 is an index into the outer page table, and p2 is the displacement within the page of the outer page table.,-Two-Level Paging Example,Operating System Concepts,Operating System Concepts, Hierarchical Paging (2),Two-Level Page-Table Scheme, Hierarchical Paging (3),A
54、ddress-translation scheme for a two-level 32-bit paging architecture( outer-page table has only one, page table has 1024 and the size of each is 1024),Operating System Concepts, Hashed Page Tables,Commonly used in address spaces 32 bits. The virtual page number is hashed into a page table. Th
55、is page table contains a chain of elements hashing to the same location (to handle collisions). Each element consists of three fields virtual page number, value of the mapped page frame, and a pointer to the next element in the linked list. Virtual page numbers are compared in this chain searching f
56、or a match. If a match is found, the corresponding physical frame is extracted.,Operating System Concepts,Operating System Concepts, Hashed Page Tables (1),Hashed Page Table, Inverted Page Table,Has one entry for each real page of memory. Entry consists of the virtual address of the pa
57、ge stored in that real memory location, with information about the process that owns that page. Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs. Use hash table to limit the search to one or at most a few page-table entries.
58、 Examples of systems using inverted page table include the 64-bit UltraSPARC and PowerPC.,Operating System Concepts,Operating System Concepts, Inverted Page Table (1),Inverted Page Table Architecture,9.4.5 Shared Pages,Shared code One copy of read-only code is shared among processes (i.e., te
59、xt editors, compilers, window systems). Some OS implement shared memory using shared pages. Private code and data Each process keeps a separate copy of the code and data. The pages for the private code and data can appear anywhere in the logical address space.,Operating System Concepts,Operating System Concepts,9.4.5 Shared Pages (1),Sharing of code in a paging environment,9.5 Segmentation,Basic Method Hardware Protection and Sharing Fragmentation,Operating System Concepts,9.5.1 Basic Method,Segmentation - Memory-management scheme that supports user view of memo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 荫罩制板工岗前技能竞赛考核试卷含答案
- 数控水射流切割机操作工岗前安全防护考核试卷含答案
- 联碱结晶工操作技能强化考核试卷含答案
- 2026年推拿疗法考试题库带答案
- 2026年药品购销员考核题库及参考答案
- 2026年天津摩托驾照题库及答案
- 2026年航天常识国考题库及参考答案
- 2026年航天宏图考试题库及答案
- 2026年国企中层考试题库及答案
- 2026年基础治理试题库及答案
- 2026年湖南生物机电职业技术学院高职单招笔试职业适应性测验历年参考题库含答案解析
- 2027年备考军队文职人员招聘之军队文职法学能力测验试题高频卷附答案
- T/CSPSTC 204-2026民用航空发动机火山灰单粒子撞击行为测试方法
- 2026年《中国急性缺血性脑卒中诊疗指南(2026版)》
- 2026年宁夏中考地理题(含答案)
- 2026年CSCO胃癌诊疗指南解读课件
- 2026浙江宁波市镇海区蛟川街道办事处招聘5人笔试备考题库及答案详解
- 新时代陕西省立德树人工作指南细则
- 心脏介入患者舒适护理措施
- 2026年7上数学期中测试题及答案
- 广东省粤科金融集团有限公司招聘笔试题库2026
评论
0/150
提交评论