1 / 24

Memory

Memory . Memory Management (General Principles). Memory Management. Objectives User believes he is the unique user of the all space. User’s address space is infinite. Realities Many users share the memory. A program consists of modules written by many. Primary memory has limited size.

donoma
Download Presentation

Memory

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. Memory Memory Management (General Principles)

  2. Memory Management • Objectives • User believes he is the unique user of the all space. • User’s address space is infinite. • Realities • Many users share the memory. • A program consists of modules written by many. • Primary memory has limited size. • Second memory is 1 to 2 order cheaper than p.m. Operating Systems Memory Management

  3. Multi-step Processing of a User Program • Linking : unifying addresses from different modules • Binding : changing addresses in user’s program to real ones logical address ---> physical address • Loading: putting the program into memory • Executing the program Should linking, binding, and loading be always done in this order Operating Systems Memory Management

  4. When to Bind ? • During compile time • Need to know the precise memory allocation • Only work for small simple programs • During load time • The program cannot be moved around during execution • Simple but inconvenient • During execution time • The program can be moved around during execution • Run-time overhead => hardware assistance Operating Systems Memory Management

  5. Overlays • Enhancing memory availability • Better having dynamic loading and binding Overlay driver Frequently used routines Main Memory Overlay driver Routine A Frequently used routines Routine B Application Operating Systems Memory Management

  6. Swap • Why ? • Who should be swapped? • When ? • Need of dynamic binding (and dynamic loading) Operating Systems Memory Management

  7. Single-Partition Allocation • Basic idea: allocate the entire memory to ONE process • Simple, minimum cost • User has maximum flexibility • No service from OS • No multiprogramming Operating Systems Memory Management

  8. A better Idea • Allocate the memory to O.S and one process • Some service from OS • Still no multi-programming • An issue : where to put O.S ? O.S Answer : Put O.S in lower end : Reasons: - Interrupt vector - memory expansions User Program & Data Operating Systems Memory Management

  9. Dynamic Binding Using Relocation Register Main Memory 14000 Base register Physical address Logical address CPU + 14346 346 Operating Systems Memory Management

  10. Multiple-Partition Allocation • Basic Idea: allocating memory to multiple processes • Two ways : • Fixed-size partition • Memory is divided into several parts of fixed size • Each process takes one part • No longer in use • Variable-size partition • Memory is partitioned dynamically • O.S. keeps a table of parts of memory available • When a process arrives, OS searches for a part of memory large enough for the process Operating Systems Memory Management

  11. Example OS Job Queue 400K process mem. req. finish time P1 600K 10 P2 1000K 5 P3 300K 20 2160K P4 700K 8 P5 500K 15 2560K Operating Systems Memory Management

  12. OS OS OS OS 400K 400K 400K 400K P1 P1 P1 1000K P4 P4 P2 2000K P3 P3 P3 P3 2300K P1 600K 10 P2 1000K 5 P3 300K 20 P4 700K 8 P5 500K 15 Example (cont’d) OS 400K P5 P2 terminates Allocate P4 P1 terminates Allocate P5 P4 P3 Job Queue process mem. req. finish time Operating Systems Memory Management

  13. Dynamic Allocation Problem • Basic strategies: • First-fit : allocate the first hole that is big enough. • Best-fit: allocate the smallest hole that is big enough. • Worst-fit: allocate the largest hole that is big enough • Usually, first-fit is fastest and both first-fit and best fit perform better than worst-fit. • Any other problems? (To be discussed) • Protection • Fragmentation Operating Systems Memory Management

  14. Protectionin Multiple-Partition (Variable Size) Limit register Base register Main Memory 4096 14000 Physical address Logical address CPU < + 346 14346 Operating Systems Memory Management

  15. FragmentationThe free memory space is broken into little pieces • Internal fragmentation • Definition : difference between required memory and allocated memory. • Cause:estimation error, management overhead. • External fragmentation • Definition : scattered small pieces not allocated • Solution: compaction • Compaction strategy Operating Systems Memory Management

  16. P1 P1 P1 P2 P2 P2 P3 P3 P3 900K 900K P4 P4 P4 #t Ways to Compact Memory OS OS OS OS 300K P1 500K P2 600K 400K 800K 1000K 1000K P3 1200K 300K 1500K 900K P4 1900K 200K 2100K Moved 600K Moved 400K Moved 200K Original Operating Systems Memory Management

  17. Paging • A compactingless memory management • No external fragmentation • A compromise between fixed-size partition and variable-size partition: less internal fragmentation than fixed-size partition Operating Systems Memory Management

  18. Paging (How) • Memory is divided into frames of fixed small size • A process is allocated a number of frames as it needs • Implementation • Divide logical memory into pages. • A dynamic mapping (binding/relocation) between pages and frames Operating Systems Memory Management

  19. Page # Frame# 0 1 2 3 4 5 6 0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 I 9 j 10 k 11 l 12 m 13 n 14 o 15 p Frame# Page# 0 0 5 1 6 2 1 3 2 i j k l 1 m n o p 2 Page table 3 Logical Memory a b c d e f g h Operating Systems Memory Management

  20. Paging Hardware Physical Memory Physical address Logical address CPU p d f d Page table f Operating Systems Memory Management

  21. Paged Segmentation User’s view of memory Subroutines Main Program Stack Data Operating Systems Memory Management

  22. Memory Management with Segmentation • Memory allocation • Fixed-size partition • Variable-size partition • The problem still exists • Paging: paged segmentation system Operating Systems Memory Management

  23. Paged Segmentation System • Aim:taking the advantages of both paging and segmentation system • Implementation : treat each segment independently, each segment has a page table • Logical address consists of three parts: • Segment# • Page # • Offset • Dynamic address translation, Operating Systems Memory Management

  24. Summary of Chapter • We mainly are concerned with these issues : • Time • Utilization of memory:fragmentation • User convenience:sharing, segmentation • Protection. Operating Systems Memory Management

More Related