understanding operating systems sixth edition

47
Understanding Operating Systems Sixth Edition Chapter 2 Memory Management: Early Systems

Upload: bsit3it116

Post on 26-Nov-2015

144 views

Category:

Documents


2 download

DESCRIPTION

Chapter 2

TRANSCRIPT

  • Understanding Operating SystemsSixth EditionChapter 2Memory Management: Early Systems

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth Edition*Learning ObjectivesAfter 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 partitionsBest-fit memory allocation as well as first-fit memory allocation schemesHow a memory list keeps track of available memory*

    Understanding Operating Systems, Sixth Edition

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

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth Edition*IntroductionManagement of main memory is criticalEntire system performance dependent on two itemsHow much memory is availableOptimization of memory during job processingThis chapter introduces:Memory managerFour types of memory allocation schemesSingle-user systemsFixed partitionsDynamic partitionsRelocatable dynamic partitions*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionSingle-User Contiguous SchemeCommercially available in 1940s and 1950sEntire program loaded into memoryContiguous memory space allocated as neededJobs processed sequentiallyMemory manager performs minimal work Register to store the base address Accumulator to track program size*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionSingle-User Contiguous Scheme (cont'd.)Disadvantages No support for multiprogramming or networkingNot cost effectiveProgram size must be less than memory size to execute*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionFixed PartitionsCommercially available in 1950s and 1960sMain memory is partitionedAt system startupOne contiguous partition per jobPermits multiprogrammingPartition sizes remain staticMust shut down computer system to reconfigureRequires: Protection of the jobs memory spaceMatching job size with partition size*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionFixed Partitions (cont'd.)Memory manager allocates memory space to jobsUses a table*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionFixed Partitions (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionFixed Partitions (cont'd.)DisadvantagesRequires contiguous loading of entire program Job allocation methodFirst available partition with required sizeTo work well:All jobs must be same size and memory size known ahead of timeArbitrary partition size leads to undesired resultsPartition too smallLarge jobs have longer turnaround timePartition too largeMemory waste: internal fragmentation*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionDynamic PartitionsMain memory is partitioned Jobs given memory requested when loadedOne contiguous partition per jobJob allocation methodFirst come, first serve allocation methodMemory waste: comparatively smallDisadvantagesFull memory utilization only during loading of first jobsSubsequent allocation: memory wasteExternal fragmentation: fragments between blocks*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionDynamic Partitions (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit AllocationTwo methods for free space allocationFirst-fit memory allocation: first partition fitting the requirementsLeads to fast allocation of memory spaceBest-fit memory allocation: smallest partition fitting the requirementsResults in least wasted spaceInternal fragmentation reduced, but not eliminatedFixed and dynamic memory allocation schemes use both methods*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)First-fit memory allocationAdvantage: faster in making allocationDisadvantage: leads to memory wasteBest-fit memory allocationAdvantage: makes the best use of memory spaceDisadvantage: slower in making allocation*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)Algorithm for first-fitAssumes memory manager keeps two listsOne for free memory One for busy memory blocksLoop compares the size of each job to the size of each memory blockUntil a block is found that is large enough to fit the jobJob stored into that block of memoryMemory Manager moves out of the loop Fetches next job from the entry queue*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)Algorithm for first-fit (cont'd.):If entire list searched in vainThen job is placed into waiting queueOtherwise, Memory Manager fetches next jobProcess repeats*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)Algorithm for best-fitGoalFind the smallest memory block into which the job will fitEntire table searched before allocation

    *

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionBest-Fit Versus First-Fit Allocation (cont'd.)Hypothetical allocation schemesNext-fit: starts searching from last allocated block, for next available block when a new job arrivesWorst-fit: allocates largest free available block to new jobOpposite of best-fitGood way to explore theory of memory allocationNot best choice for an actual system*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionDeallocationDeallocation: freeing allocated memory spaceFor fixed-partition system:Straightforward processMemory Manager resets the status of jobs memory block to free upon job completion Any code may be usedExample code: binary values with zero indicating free and one indicating busy*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionDeallocation (cont'd.)For dynamic-partition system: Algorithm tries to combine free areas of memoryMore complexThree dynamic partition system casesCase 1: When the block to be deallocated is adjacent to another free blockCase 2: When the block to be deallocated is between two free blocksCase 3: When the block to be deallocated is isolated from other free blocks*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 1: Joining Two Free BlocksBlocks are adjacentList changes to reflect starting address of the new free blockExample: 7600 - the address of the first instruction of the job that just released this blockMemory block size changes to show its new size for the new free spaceCombined total of the two free partitionsExample: (200 + 5)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 1: Joining Two Free Blocks (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 1: Joining Two Free Blocks (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 2: Joining Three Free BlocksDeallocated memory spaceBetween two free memory blocksList changes to reflect starting address of new free blockExample: 7560 was smallest beginning addressSizes of the three free partitions must be combinedExample: (20 + 20 + 205) Combined entry (last of the three) given status of nullExample: 7600*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 2: Joining Three Free Blocks (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 2: Joining Three Free Blocks (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 3: Deallocating an Isolated BlockDeallocated memory spaceIsolated from other free areasSystem determines released memory block statusNot adjacent to any free blocks of memoryBetween two other busy areasSystem searches table for a null entryOccurs when memory block between two other busy memory blocks is returned to the free list*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 3: Deallocating an Isolated Block (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 3: Deallocating an Isolated Block (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 3: Deallocating an Isolated Block (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionCase 3: Deallocating an Isolated Block (cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic PartitionsMemory Manager relocates programsGathers together all empty blocks Compact the empty blocksMake one block of memory large enough to accommodate some or all of the jobs waiting to get in

    *

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)Compaction: reclaiming fragmented sections of memory spaceEvery program in memory must be relocatedPrograms become contiguousOperating system must distinguish between addresses and data values Every address adjusted to account for the programs new location in memoryData values left alone*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)Compaction issues:What goes on behind the scenes when relocation and compaction take place?What keeps track of how far each job has moved from its original storage area?What lists have to be updated?*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)What lists have to be updated?Free list Must show the partition for the new block of free memoryBusy list Must show the new locations for all of the jobs already in process that were relocatedEach job will have a new addressException: those already at the lowest memory locations*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)Special-purpose registers used for relocation:Bounds register Stores highest location accessible by each programRelocation registerContains the value that must be added to each address referenced in the programMust be able to access the correct memory addresses after relocationIf the program is not relocated, zero value stored in the programs relocation register*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionRelocatable Dynamic Partitions(cont'd.)Compacting and relocating optimizes use of memoryImproves throughputOptions for timing of compaction:When a certain percentage of memory is busyWhen there are jobs waiting to get inAfter a prescribed amount of time has elapsedCompaction entails more overheadGoal: optimize processing time and memory use while keeping overhead as low as possible*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionSummaryFour memory management techniquesSingle-user systems, fixed partitions, dynamic partitions, and relocatable dynamic partitionsCommon requirements of four memory management techniquesEntire program loaded into memoryContiguous storageMemory residency until job completedEach places severe restrictions on job sizeSufficient for first three generations of computers*

    Understanding Operating Systems, Sixth Edition

  • Understanding Operating Systems, Sixth EditionSummary (cont'd.)New modern memory management trends in late 1960s and early 1970sDiscussed in next chapterCommon characteristics of memory schemesPrograms are not stored in contiguous memoryNot all segments reside in memory during job execution*

    Understanding Operating Systems, Sixth Edition