1 / 25

Memory Management

Memory Management. Fred Kuhns (fredk@arl.wustl.edu, http://www.arl.wustl.edu/~fredk) Department of Computer Science and Engineering Washington University in St. Louis. Overview. Memory Partitioning schemes Fixed partitions Dynamic partitions Simple paging simple segmentation Relocation.

morrison
Download Presentation

Memory Management

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 Management Fred Kuhns (fredk@arl.wustl.edu, http://www.arl.wustl.edu/~fredk) Department of Computer Science and Engineering Washington University in St. Louis

  2. Overview • Memory Partitioning schemes • Fixed partitions • Dynamic partitions • Simple paging • simple segmentation • Relocation Cs422 – Operating Systems Organization

  3. Memory Management: Requirements • Relocation • Why/What: • programmer does not know where the program will be placed in memory when it is executed • while the program is executing, it may be swapped to disk and returned to main memory at a different location • Consequences/Constraints: • memory references must be translated in the code to actual physical memory address Cs422 – Operating Systems Organization

  4. Memory Management: Requirements • Protection • Protection and Relocation are interrelated • Why/What: • Protect process from interference by other processes • processes require permission to access memory in another processes address space. • Consequences/Constraints: • impossible to check addresses in programs since the program could be relocated • must be checked at run time Cs422 – Operating Systems Organization

  5. Memory Management: Requirements • Sharing • Sharing and Relocation are interrelated • allow several processes to access the same data • allow multiple programs to share the same program text Cs422 – Operating Systems Organization

  6. Fixed Partitioning • Partition available memory into regions with fixed boundaries • Equal-size partitions • process size <= partition size can be loaded into available partition • if all partitions are full, the operating system can swap a process out of a partition • If program size > partition size, then programmer must use overlays • Unequal-size partitions Cs422 – Operating Systems Organization

  7. Operating System 8 M Operating System 8 M 8 M 2 M 4 M 8 M Unused 6 M process 1 process 1 8 M 8 M 8 M 8 M 12 M Fixed Partitions • Main memory use is inefficient, suffers from Internal Fragmentation - Part of partition unused Equal Sized Partitions Unequal Sized Partitions Cs422 – Operating Systems Organization

  8. Placement Algorithm with Partitions • Equal-size partitions • because all partitions are of equal size, it does not matter which partition is used • Unequal-size partitions • can assign each process to the smallest partition within which it will fit • queue for each partition • processes are assigned in such a way as to minimize wasted memory within a partition Cs422 – Operating Systems Organization

  9. One Process Queue per Partition • Wait for “best” partition Operating System New Processes Cs422 – Operating Systems Organization

  10. One Process Queue for All • smallest available partition that will hold the process is selected Operating System New Processes Cs422 – Operating Systems Organization

  11. Variable Partitioning • External Fragmentation - small holes in memory between allocated partitions. • Partitions are of variable length and number • Process is allocated exactly as much memory as required • Must use compaction to shift processes so they are contiguous and all free memory is in one block Cs422 – Operating Systems Organization

  12. Example Dynamic Partitioning Operating System Operating System Operating System 128 K 320 K 320 K Process 1 Process 1 Process 2 224 K 896 K 576 K 352 K Cs422 – Operating Systems Organization

  13. Example Variable Partitioning Operating System Operating System Operating System 320 K 320 K 320 K Process 1 Process 1 Process 1 128 K 224 K 224 K Process 4 Process 2 96 K Process 3 288 K Process 3 288 K Process 3 288 K 64 K 64 K 64 K Cs422 – Operating Systems Organization

  14. Example Variable Partitioning Operating System Operating System 320 K Process 2 224 k 96 K 128 K 128 K Process 4 Process 4 96 K 96 K Process 3 288 K Process 3 288 K 64 K 64 K Cs422 – Operating Systems Organization

  15. Variable Partition Placement Algorithm • Best-fit : generally worst performer overall • place in smallest unused block (that process fits in) • results in minimally sized fragments requiring compaction • Worst-fit • place in largest unused block • First-fit : simple and fast • scanning from beginning and choose first that is large enough. • may have many process loaded in the front end of memory that must be scanned • Next-fit : tends to perform worse than first-fit • scan memory from the location of the last allocation and chooses the next available block that is large enough • more often allocate a block of memory at the end of memory where the largest block is found • compaction is required to obtain a large block at the end of memory Cs422 – Operating Systems Organization

  16. Variable Partition Placement Algorithm alloc 16K block 8K 8K 12K First Fit 12K 22K 6K Last allocated block (14K) Best Fit 18K 2K 8K 8K 6K 6K Allocated block Free block 14K 14K Next Fit 36K 20K Before After Cs422 – Operating Systems Organization

  17. Addresses • Logical Address • reference to a memory location independent of the current assignment of data to memory • translation from logical physical address • Relative Address (type of logical address) • address expressed as a location relative to some known point • Physical Address • the absolute address or actual location Cs422 – Operating Systems Organization

  18. Relocation • Fixed partitions: When program loaded absolute memory locations assigned • In general a process may occupy different partitions over time • swapping • Compaction causes a program to occupy a different partition which means different absolute memory locations • relative address can be used with HW support – Dynamic Address Relocation Cs422 – Operating Systems Organization

  19. Hardware Support for Relocation Relative address Process Control Block Base Register Adder Program Absolute address Bounds Register Comparator Data Interrupt to operating system Stack Process image in main memory Cs422 – Operating Systems Organization

  20. Registers Used during Execution • Register values are set when the process is loaded and when the process is swapped in • Base register: starting address for the process • The value of the base register is added to a relative address to produce an absolute address • Bounds register: ending location of the process • The resulting address is compared with the value in the bounds register • If the address is not within bounds, an interrupt is generated to the operating system Cs422 – Operating Systems Organization

  21. Paging • Partition memory into small equal-size chunks • Chunks of memory are called frames • Divide each process into the same size chunks • Chunks of a process are called pages • Operating system maintains a page table for each process • contains the frame location for each process page • memory address = page number + offset Cs422 – Operating Systems Organization

  22. Frame Number 0 0 A.0 0 A.0 1 1 1 A.1 A.1 2 2 A.2 2 A.2 3 3 A.3 3 A.3 4 4 4 B.0 5 5 5 B.1 6 6 6 B.2 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 Paging physical memory Process A & B loaded Process A loaded Cs422 – Operating Systems Organization

  23. A.0 A.1 0 A.0 0 0 A.2 1 1 1 A.1 A.3 2 A.2 2 2 D.0 3 A.3 3 3 D.1 4 B.0 4 4 D.2 5 B.1 5 5 C.0 6 B.2 6 6 7 C.0 7 7 C.1 8 C.1 8 8 C.2 9 C.2 9 9 C.3 10 C.3 10 10 D.3 11 11 11 D.4 12 12 12 13 13 13 14 14 14 Paging A.0 A.1 A.2 A.3 C.0 C.1 C.2 C.3 Cs422 – Operating Systems Organization

  24. 0 0 A.0 0 --- A.1 1 1 1 --- 0 2 2 2 --- A.2 1 Process B 3 3 A.3 2 0 Process A D.0 3 1 D.1 4 2 D.2 0 5 3 7 4 C.0 6 4 1 8 5 2 9 6 7 C.1 3 10 11 8 C.2 Process C 12 9 C.3 Process D 10 D.3 11 13 D.4 12 14 13 Free Frame List 14 Page Tables : Example Cs422 – Operating Systems Organization

  25. Segmentation • All segments of all programs do not have to be of the same length • There is a maximum segment length • Addressing consist of two parts - a segment number and an offset • Since segments are not equal, segmentation is similar to dynamic partitioning Cs422 – Operating Systems Organization

More Related