Operating System Operating System Concepts Concepts Ku-Yaw Chang Ku-Yaw Chang [email protected][email protected]Assistant Professor, Department of Assistant Professor, Department of Computer Science and Information Engineering Computer Science and Information Engineering Da-Yeh University Da-Yeh University
Operating System Concepts. Ku-Yaw Chang [email protected] Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University. Chapter 9 Memory Management. Keep several processes in memory to increase CPU utilization Memory management algorithms - PowerPoint PPT Presentation
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Operating System Operating System ConceptsConcepts
Assistant Professor, Department of Assistant Professor, Department of Computer Science and Information EngineeringComputer Science and Information Engineering
Program must be brought (loaded) into memory and Program must be brought (loaded) into memory and placed within a process for it to be run.placed within a process for it to be run.
Address bindingAddress binding A mapping from one address space to anotherA mapping from one address space to another
A typical instruction-execution cycleA typical instruction-execution cycle FetchFetch an instruction from memory an instruction from memory DecodeDecode the instruction the instruction
May cause operands to be fetched from memoryMay cause operands to be fetched from memory ExecuteExecute the instruction the instruction StoreStore results back into memory results back into memory
Input queueInput queue A collection of processes on the disk that are waiting A collection of processes on the disk that are waiting
to be brought into memory to run the program.to be brought into memory to run the program.
A user program will go through several steps A user program will go through several steps before being executedbefore being executed Addresses in source program are Addresses in source program are symbolicsymbolic A compiler binds these symbolic addresses to A compiler binds these symbolic addresses to
relocatable addressesrelocatable addresses A loader binds these relocatable addresses to A loader binds these relocatable addresses to
Load timeLoad time Relocatable code Relocatable code
can be generatedcan be generatedNot known at Not known at compile time where compile time where the process will the process will reside in memoryreside in memory
Final binding is Final binding is delayed until load delayed until load timetime
9.1.2 Logical- Versus Physical-9.1.2 Logical- Versus Physical-Address SpaceAddress Space
LogicalLogical address address An address generated by the CPUAn address generated by the CPU Compile-time and load-timeCompile-time and load-time Also called Also called virtual addressvirtual address Logical-address spaceLogical-address space
The set of all logical addressesThe set of all logical addresses
PhysicalPhysical address address An address seen by the memory unitAn address seen by the memory unit
The one loaded into the memory-address unitThe one loaded into the memory-address unit Execution timeExecution time
Logical and physical address spaces differLogical and physical address spaces differ Physical-address spacePhysical-address space
9.1.2 Logical- Versus Physical-9.1.2 Logical- Versus Physical-Address SpaceAddress Space
MMemory-emory-MManagement anagement UUnit (nit (MMUMMU)) A hardware deviceA hardware device
Run-time mapping from virtual to physical addressesRun-time mapping from virtual to physical addresses Different methods to accomplish such a mappingDifferent methods to accomplish such a mapping
Logical addressesLogical addresses 00 to to maxmax
Physical addressesPhysical addresses RR + + 00 to to RR + + maxmax
The entire program and data must be in memory The entire program and data must be in memory for its executionfor its execution The size of a process is limited to the size pf physical The size of a process is limited to the size pf physical
memory.memory.
Dynamic LoadingDynamic Loading All routines are kept on disk in a relocatable load All routines are kept on disk in a relocatable load
formatformatThe main program is loaded into memory and is executedThe main program is loaded into memory and is executed
A routine is not loaded until it is calledA routine is not loaded until it is called
AdvantageAdvantage An unused routine is never loadedAn unused routine is never loaded
Dynamic LinkingDynamic Linking Linking is postponed until execution timeLinking is postponed until execution time
Small piece of code, called Small piece of code, called stubstub, used to locate the , used to locate the appropriate memory-resident library routineappropriate memory-resident library routine
OS checks if routine is in processes’ memory addressOS checks if routine is in processes’ memory addressIf yes, load the routine into memoryIf yes, load the routine into memory
Stub replaces itself with the address of the routine, and Stub replaces itself with the address of the routine, and executes the routine.executes the routine.
Dynamic linking is particularly useful for libraries.Dynamic linking is particularly useful for libraries.
Keep in memory only those instructions and data Keep in memory only those instructions and data that are needed at any given timethat are needed at any given time
Needed when process is larger than amount of Needed when process is larger than amount of memory allocated to itmemory allocated to it
FeaturesFeatures Implemented by userImplemented by user No special support needed from operating systemNo special support needed from operating system Programming design is complexProgramming design is complex
Context-switch time is fairly highContext-switch time is fairly high User process size: 1MBUser process size: 1MB Transfer rate: 5MB per secondTransfer rate: 5MB per second Actual transfer:Actual transfer:
1000KB / 5000 KB per second = 200 milliseconds1000KB / 5000 KB per second = 200 milliseconds An average latency: 8 msAn average latency: 8 ms Total swap timeTotal swap time
208 + 208 = 416 ms208 + 208 = 416 ms Time quantum should be substantially larger than Time quantum should be substantially larger than
Major part of the swap time is transfer timeMajor part of the swap time is transfer time Directly proportional to the amount of memory Directly proportional to the amount of memory
swappedswapped
FactorsFactors How much memory is actually usedHow much memory is actually used
To reduce swap timeTo reduce swap time Be sure the process is completely idleBe sure the process is completely idle
MemoryMemory One for the resident operating systemOne for the resident operating system
In either low or high memoryIn either low or high memory Location of the interrupt vectorLocation of the interrupt vector
One for the user processesOne for the user processes
Contiguous memory allocationContiguous memory allocation Each process is contained in a single contiguous Each process is contained in a single contiguous
Possible solutions to the external fragmentationPossible solutions to the external fragmentation CompactionCompaction Permit the logical address space of a process to be Permit the logical address space of a process to be
A memory-management scheme that permits A memory-management scheme that permits the physical-address space of a process to be the physical-address space of a process to be noncontiguousnoncontiguous FramesFrames (physical memory) (physical memory)