1 / 69

Understanding Operating Systems Sixth Edition

Understanding Operating Systems Sixth Edition. Chapter 2 ***** Memory Management: Early Systems. Learning Objectives. After completing this chapter, you should be able to describe:

wenda
Download Presentation

Understanding Operating Systems Sixth Edition

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. Understanding Operating SystemsSixth Edition Chapter 2 ***** Memory Management: Early Systems

  2. Learning Objectives After completing this chapter, you should be able to describe: • The basic functionality of the three memory allocation schemes presented in this chapter: fixed partitions, dynamic partitions, relocatable dynamic partitions • Best-fit memory allocation as well as first-fit memory allocation schemes • How a memory list keeps track of available memory 2 Understanding Operating Systems, Sixth Edition

  3. Learning Objectives (cont'd.) The importance of deallocation of memory in a dynamic partition system The importance of the bounds register in memory allocation schemes The role of compaction and how it improves memory allocation efficiency 3 Understanding Operating Systems, Sixth Edition

  4. Introduction • Management of main memory is critical. • The performance of the entiresystem has been directly dependent on two things: • How much memory is available • How it is optimization while jobs are being processed. • This chapter introduces: • The memory manager (RAM) • Core memory (primary storage) 4 Understanding Operating Systems, Sixth Edition

  5. Introduction • This chapter introduces: • Four types of memory allocation schemes • Single-user systems • Fixed partitions • Dynamic partitions • Relocatable dynamic partitions • These early memory management schemes are seldom used by today’s OSs but are important to study because each one introduced fundamental concepts that helped memory management evolve. 5 Understanding Operating Systems, Sixth Edition

  6. Single-User Contiguous Scheme • Commercially available in 1940s and 1950s • Each program was loaded in its entirety into memory and allocated as much contiguous memory space allocated as it needed. • If the program was too large and didn’t fit the available memory space, it couldn’t be executed, • Although early computers were physically large, they had very little memory. • Computers have only a finite amount of memory. Understanding Operating Systems, Sixth Edition

  7. Single-User Contiguous Scheme • If a program doesn’t fit, then either the size of the main memory must be increased or the program must be modified. • Making it smaller • Using methods that allow program segments (partitions made to the program) to be overlaid. • Transfer segments of a program from secondary storage into main memory for execution • Two or more segments take turns occupying the same memory locations. Understanding Operating Systems, Sixth Edition

  8. Single-User Contiguous Scheme • Program Segmentation Slides Understanding Operating Systems, Sixth Edition

  9. Memory ManagementPartitions and Regions

  10. Overlay Structures • Developed when the amount of available memory was limited. • Divide the program into logically independent modules. • Module 1 holds the main control logic and key data common to the entire program. • Module 2 processes valid input data. • Module 3 processes errors. • Module 4 generates end-of-program statistics.

  11. Fig. 6.9a: Overlay structures. The complete program consists of four modules.

  12. Fig. 6.9b: Normally, only modules 1 and 2 are in memory.

  13. Fig. 6.9c: When an error occurs, module 3 overlays module 2.

  14. Fig. 6.9d: At end-of-job, only modules 1 and 4 are needed.

  15. Memory Management Concurrency • A program cannot process data it does not have. • A program spends more time waiting for I/O than processing data.

  16. Single-User Contiguous Scheme • The amount of work performed by the Memory Manager is minimal. • Only two hardware items are needed: • A register to store the base address • An accumulator to keep track of the size of the program as it’s being read into memory. • Once the program is entirely loaded into memory, it remains there until execution is complete, either through normal termination or by intervention of the OS. Understanding Operating Systems, Sixth Edition

  17. Single-User Contiguous Scheme (cont'd.) • Disadvantages • There is no support for multiprogramming or networking • It can handle only one job at a time. • This configuration was first used in research institutions but proved unacceptable for the business community. • It was not cost effective to spend almost $200,000 for equipment that could be used by only one person ay a time. Understanding Operating Systems, Sixth Edition

  18. Fixed Partitions • The first attempt to follow multiprogramming used fixed partitions (static partitions) within main memory. • One partition for each job. • The size of each partition was designated when the system was powered on. • Each partition could only be reconfigured when the system was shut down. • Once the system was in operation, the partition sizes remained static. Understanding Operating Systems, Sixth Edition

  19. Fixed Partitions • Introduced protection of the job’s memory space • Once a partition was assigned to a job, no other job could be allowed to enter its boundaries, either accidentally or intentionally. • Not a problem in single-user contiguous allocation schemes. • Fixed Partitions is more flexible than the Single-User scheme because it allows several programs to be in memory at the same time. • Fixed Partitions still requires that the entire program be stored contiguously and in memory from the beginning to the end of its execution. Understanding Operating Systems, Sixth Edition

  20. Fixed Partitions • In order to allocate memory spaces to jobs, the OS’s Memory Manager must keep a table which shows: • Each memory partition size • Its address • Its access restrictions • Its current status (free or busy) • As each job terminates, the status of its memory partition is changed from busy to free so an incoming job can be assigned to that partition. Understanding Operating Systems, Sixth Edition

  21. Fixed Partitions (cont'd.) • Memory manager allocates memory space to jobs • Uses a table Understanding Operating Systems, Sixth Edition

  22. Fixed Partitions (cont'd.) Understanding Operating Systems, Sixth Edition

  23. Fixed Partitions (cont'd.) • Disadvantages • The Fixed Partition scheme works well if all the jobs run on the system are of the same size or if the sizes are known ahead of time and don’t vary between reconfiguration. • If the partition sizes are too small: • larger jobs will be rejected if they’re too big to fit into the largest partition. • Large jobs will wait if the large partitions are busy. • Large jobs may have a longer turnaround time as they wait for free partitions of sufficient size or may never run. Understanding Operating Systems, Sixth Edition

  24. Fixed Partitions (cont'd.) • Disadvantages • If the partition sizes are too big, memory is wasted. • If a job does not occupy the entire partition, the unused memory in the partition will remain idle. • It can’t be given to another job because each partition is allocated to only one job at a time. • Partial usage of fixed partitions and the coinciding creation of unused spaces within the partition is called internal fragmentation and is a major drawback to the fixed partition memory allocation scheme. Understanding Operating Systems, Sixth Edition

  25. Dynamic Partitions • With Dynamic Partitions available memory is still kept in contiguous blocks but jobs are given only as much memory as they request when they are loaded for processing. • A dynamic partition scheme fully utilizes memory when the first jobs are loaded. • As new jobs enter the system that are not the same size as those that just vacated memory, they are fit into the available spaces on a priority basis. • First Come – First Serve priority Understanding Operating Systems, Sixth Edition

  26. Dynamic Partitions • The subsequent allocation of memory creates fragments of free memory between blocks of allocated memory. • External fragmentation • Lets memory go to waste Understanding Operating Systems, Sixth Edition

  27. Dynamic Partitions (cont'd.) Understanding Operating Systems, Sixth Edition

  28. Best-Fit Versus First-Fit Allocation • For both fixed and dynamic memory allocation schemes, the OS must keep lists of each memory location noting which are free and which are busy. • As new jobs come into the system, the free partitions must be allocated. • These partitions may be allocated on the basis of: • First-fit memory allocation: • First partition fitting the requirements • Best-fit memory allocation: • Smallest partition fitting the requirements • Least wasted space Understanding Operating Systems, Sixth Edition

  29. Best-Fit Versus First-Fit Allocation • For both schemes, the Memory Manager organizes the memory lists of the free and used partitions either by size or by location. • The Best-fit allocation method keeps the free/busy lists in order by size, smallest to largest. • Makes the best use of memory space. • The first-fit method keeps the free/bust list organized by memory locations, low-order memory to high-order memory. • Faster in making the allocation. Understanding Operating Systems, Sixth Edition

  30. Best-Fit Versus First-Fit Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  31. Best-Fit Versus First-Fit Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  32. Best-Fit Versus First-Fit Allocation (cont'd.) • Algorithm for first-fit • Assumes memory manager keeps two lists • One for free memory blocks • One for busy memory blocks • The operation consists of a simple loop that compares the size of each job to the size of each memory block until a block is found that is large enough to fit the job. • The job is stored into that block of memory and the Memory Manager moves out of the loop to fetch the next job from the entry queue Understanding Operating Systems, Sixth Edition

  33. Best-Fit Versus First-Fit Allocation (cont'd.) • Algorithm for first-fit (cont'd.): • If the entire list is searched in vain, then the job is placed into a waiting queue. • The Memory Manager then fetches the next job and repeats the process. Understanding Operating Systems, Sixth Edition

  34. Best-Fit Versus First-Fit Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  35. Best-Fit Versus First-Fit Allocation (cont'd.) • Algorithm for best-fit • The goal is to find thesmallest memory block into which the job will fit • The entire table must be searched before the allocation can be made because the memory blocks are physically stored in sequence according to their location in memory. Understanding Operating Systems, Sixth Edition

  36. Best-Fit Versus First-Fit Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  37. Best-Fit Versus First-Fit Allocation (cont'd.) • Hypothetical allocation schemes • Next-fit: • Starts searching from last allocated block, for next available block when a new job arrives • Worst-fit: • Allocates largest free available block to new job • Opposite of best-fit • Good way to explore theory of memory allocation • Not best choice for an actual system Understanding Operating Systems, Sixth Edition

  38. Deallocation • There eventually comes a time when memory space must be released or deallocated. • For a fixed-partition system: • When the job is completed, the Memory Manager resets the status of the memory block where the job was stored to “free”. • Any code may be used. • Example code: binary values with zero indicating free and oneindicating busy. Understanding Operating Systems, Sixth Edition

  39. Deallocation (cont'd.) • For dynamic-partition system: • A more complex Algorithm is used because the algorithm tries to combine free areas of memory whenever possible. • The system must be prepared for three alternative solutions: • Case 1:When the block to be deallocated isadjacent to another free block • Case 2:When the block to be deallocated isbetween two free blocks • Case 3:When the block to be deallocated isisolated from other free blocks Understanding Operating Systems, Sixth Edition

  40. Case 1: Joining Two Free Blocks • Using the deallocation algorithm, the system sees that the memory to be released is next to a free memory block (Location 7800). • The List must be changed changes to reflect the starting address of the new free block (7600) which was the addressof the first instruction of the job that just released this block. • In addition, the memory block size for this new free space must be changed to show its new size, which is the combined total of the two free partitions (200 + 5). Understanding Operating Systems, Sixth Edition

  41. Case 1: Joining Two Free Blocks(cont'd.) Understanding Operating Systems, Sixth Edition

  42. Case 1: Joining Two Free Blocks(cont'd.) Understanding Operating Systems, Sixth Edition

  43. Case 2: Joining Three Free Blocks • When the deallocated memory space is between two free memory blocks: • Using the deallocation algorithm, the system learns that the memory to be deallocated is between two free blocks of memory. • The sizes of the three free partitions (20 + 20 +205) must be combined and the total stored with the smallest beginning address, 7560. • Because the entry at location 7600 has been combined with the previous entry, we must empty out this entry. Understanding Operating Systems, Sixth Edition

  44. Case 2: Joining Three Free Blocks • We do that by changing the status to null entry, with no beginning address and no memory block size as indicated by an asterisk. • This negates the need to rearrange the list at the expense of memory. Understanding Operating Systems, Sixth Edition

  45. Case 2: Joining Three Free Blocks(cont'd.) Understanding Operating Systems, Sixth Edition

  46. Case 2: Joining Three Free Blocks (cont'd.) Understanding Operating Systems, Sixth Edition

  47. Case 3: Deallocating an Isolated Block • The third alternative is when the space to be deallocated is isolated from all other free areas. • Using the deallocation algorithm, the system learns that the memory block to be released is not adjacent to any free blocks of memory • It is between two other busyareas • The system must search the table for a null entry. • When the null entry is found: • The beginning memory location of the terminating job is entered in the beginning address column. Understanding Operating Systems, Sixth Edition

  48. Case 3: Deallocating an Isolated Block • The job size is entered under the memory block size column • The status is changed from a null entry to free to indicate that a new block of memory is available. Understanding Operating Systems, Sixth Edition

  49. Case 3: Deallocating an Isolated Block (cont'd.) Understanding Operating Systems, Sixth Edition

  50. Case 3: Deallocating an Isolated Block (cont'd.) Understanding Operating Systems, Sixth Edition

More Related