1 / 157

Chapter 3

Chapter 3. Memory Management. Content. Why need memory management Memory partitioning Paging Segmentation. 3.1 Memory Management Requirements (p289). Relocation( 重定位 ) Memory Protection (保护) Memory Sharing (共享) Logical Organization (逻辑组织) Physical Organization (物理组织).

Download Presentation

Chapter 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 Memory Management

  2. Content Why need memory management Memory partitioning Paging Segmentation

  3. 3.1 Memory Management Requirements (p289) • Relocation(重定位) • Memory Protection(保护) • Memory Sharing(共享) • Logical Organization(逻辑组织) • Physical Organization(物理组织)

  4. Relocation (重定位p290) • The processor and OS translate the memory references found in the code of the program into actual physical memory addresses, which reflecting the current location of the program in main memory.(程序代码中地址引用翻译为主存中当前地址的过程)

  5. Relocation (p290) • Static relocation(静态,一次性重定位) • Relocate when compile program or load in program. • Dynamic relocation(动态,可多次重定位) • Relocate when running program. • Contents for relocation(定位内容) • Branch instruction(分支指令) • Reference to data (数据引用)

  6. Memory Protection (p291) • Each process should be protected against unwanted interference(访问) by other processes. • All memory references generated by a process must be checked(检查) at run time. • The memory protection requirement is satisfied(完成) by the processor (hardware) rather than the OS (software).

  7. Memory Sharing(共享p291) • Share data and code for save(节省) the memory. • The memory-management system must allow controlled access to shared areas of memory without compromising(影响) essential protection.

  8. Logical Organization(p291) • OS should deal with programs in the form of modules(模块) • Modules can be written and compiled independently. • Different degrees of protection can be given to different modules. • It is easy to implement share. • E.g. segmentation(分段管理)

  9. Physical Organization(p292) • Computer memory is organized(组织) into at least two levels, referred to as main memory and secondary memory. • Swapping the modules in and out as needed. • The programmer does not know how much space will be available or where that space will be.

  10. Loading\ Linking (P311) • Create a process image(f-7.13) • A loading scenario(f-7.14)

  11. A loading Scenario (Fig 7.14) Library Module#1 Load Module Loader Linker RAM Module#2 Module#n

  12. LoadingType(p313) • Absolute loading • Relocatable loading • Dynamic run-time loading

  13. Absolute Loading • Absolute address(F7.15b). • Always be loaded into the same location. • The assignment of specific address values to memory reference(内存引用的地址变换) be done by programming or compile time. • Not transparent to programmer. • All code in a program must be recompiled after modified.

  14. Relocatable Loading • Relative address(引用相对地址)(F7.15c) • No need always load into same location. • Need a relocation dictionary(重定位表) in loading modules (generated at compile time).

  15. Dynamic Run-Time Loading • Can support swap the process. • Done by processor hardware for not degrade performance.(F7.8)

  16. Loading (table 7.2a p314) • Address Binding(绑定) Time • Programming time • Compile time • Load time • Run time

  17. Linking(F7.16) • Linking time(table 7.2b) • Programming time • Compile or assembly time • Load module creation • Load time • Run time

  18. Type of Link • Static linking • Compile time • Link to a executable modules • Dynamic linking • Loading time • Easy to upgrade modules and need not source code of modules to upgrade.(模块升级不需要联编)

  19. Type of Link • Easy to share. • High efficient to use main memory. • Running time • Can move process when it running. • Can defer the loading time of a module to the time that must run it.

  20. Memory Management Techniques(p292) • Fixed Partitioning(固定分区) • Dynamic Partitioning(动态分区) • Simple Paging(简单分页) • Simple Segmentation(简单分段) • Virtual-Memory Paging(虚拟分页) • Virtual-Memory Segmentation(虚拟分段)

  21. 3.2 Memory Partitioning(p292) • Fixed Partitioning • Dynamic Partitioning • Buddy System(伙伴系统)

  22. Fixed Partitioning(p294) • Main memory is divided into a number of static partitions at system generation(装入) time. A process may be loaded into a partition of equal or greater size. • The partitions can be equal size or not.

  23. Fixed Partitioning • Equal size partitions(固定等大小) • Inefficient to use main memory, generating internal fragmentation. • Big program can not be loaded into partition. • The size of partition not equal(固定不等大小) • Can alleviate(缓解)the disadvantage.

  24. Placement (放置) Algorithm(p295) • If the partitions is equal size. Just choose a free partitions to place a process. • If the partitions is not equal size, using the following tow methods: • To guarantee the choosing partition can be the best suitable size one(最佳). • To guarantee the choosing partition can contain the correspond process.

  25. Adv. of fixed partition • Simple to implement • System spending(开销) is small.

  26. Disadv. of Fixed Partition(p296) • Having internal fragment(内碎片), inefficient to use main memory. • Can not run big size program. • The number of process is fixed by the number of partition.

  27. Dynamic Partitioning(动态分区p296) • The number and size(数目和大小) of partition is change while the processes are in and out from main memory.

  28. External Fragment(外碎片p298) • When a process is loaded in, system may choose a suitable partition, and no internal fragment appear. But external fragment will appear.

  29. External/Internal fragmentation • Internal: There is wasted space internal to a partition due to the data loaded is smaller than it.(由于数据和分区大小不完全匹配引起的) • External: The small partition that can not allocate to any process.(不能分配给任何进程的小分区)

  30. Compaction(紧凑p298) • OS shifts(移动) the processes so that they are contiguous(相邻) and all of the free memory is together in one block. • To implement compaction, the dynamic reallocate(动态重定位) technology must be used.

  31. Placement Algorithm(p298) • Best-Fit Algorithm(最优) • First-Fit Algorithm(首次) • Next-Fit Algorithm(下次/循环首次)

  32. Replacement Algorithm(p299) • Swapping process(以进程为单位交换) to avoid wasting processor time waiting for an active process to become unblocked. • Active process is in RAM.

  33. Buddy System(伙伴系统) • A dynamic partition algorithm which need not use compaction(紧凑). • 2U is the size of the entire memory(全部内存) available for allocation. To begin, the entire space available for allocation is treated as a single block size of 2U .

  34. Buddy System • If a request of size k such that 2i-1<k ≤ 2i is made, a block size of 2i will be allocated as follows: 1、if i >U, the request is larger than the whole main memory, return fail; 2、if the list of 2i is null, that means there is no free partition size of 2i,so:

  35. Buddy System ⑴ Find a free partition size of 2i+1, if not find, change i to i+1 and call the algorithm again; ⑵ Split(分裂) the partition size of 2i+1 into two buddy partitions of size 2i; ⑶ Insert the two buddy partitions of size 2i into the free list size of 2i; 3、Get the first free partition in the free list size of 2i,return.

  36. Buddy System Void * get_hole(i) { if (i > U) return null; if (i _list==null) { tmp=get_hole(i+1); split_hole(tmp,tmp1,tmp2); insert_hole(i,tmp1,tmp2); } return first hole on i_list; }

  37. Buddy System:Partition Release(释放分区) • When release a partition size of 2i, if its buddy is not free, then insert it into free list size of 2i. • Otherwise • Delete the buddy from the free list size of 2i; • Merge(融合) the release partition and the buddy partition to a partition size of 2i+1; • Call the release algorithm again.

  38. Buddy System • Internal fragmentation existing • No external fragmentation

  39. Data Structure of Partition Management(补充) • Partition table(分区表) • Table entry(表项) • Size、start address、allocate id • Single list • Multi-list • Free list • Allocate list

  40. Data Structure of Partition Management • Operation(操作) of partition table • Insert • Modify • Merge and split

  41. Relocation(重定位) of Partition Management(p302) • Physical Address(物理地址) • Absolute address(绝对地址). An actual location in main memory. • If a process does not move during its lifeline(进程不移动), the physical address can be used as the command or data location to be accessed.

  42. Relocation of Partition Management • If using swapping or compaction technology (virtual memory or dynamic partition management), a process may be assigned to a different partition in its lifeline(生存期). • In the cases, logical address (relative address) may be used.

More Related