Presentation on theme: "Operating System Support Focus on Architecture"— Presentation transcript:
1 Operating System Support Focus on Architecture Chapter 8Operating System SupportFocus on Architecture
2 Functions of Operating System Managing ResourcesAccess to System UtilitiesAccess to filesAccess to I/O devicesManaging Interrupts & Bus Control (DMA)Error detection and responseAccountingScheduling Processes (or tasks)Program creationProgram executionI/O ProcessingManaging Memory UtilizationPartitioning,Paging,Virtual memory,Segmentation
3 Types of Operating Systems What do we want to Optimize in each?InteractiveBatchUni-taskingMulti-taskingReal-Time
4 Batch Operating System Resident Monitor Jobs are batched in queueMonitor handles schedulingMonitor controls sequence ofevents to process batchWhen one job is finished,control returns to Monitorwhich loads next job
5 Desirable Hardware Support for OS Memory protectionTo protect the Monitor & UtilitiesTimerTo prevent a job monopolizing the systemPrivileged instructionsOnly executed by Monitore.g. I/O, filesInterruptsAllows for relinquishing and regaining controlDMAAllows for optimizing bus usage
6 The Case for Multi-programmed Batch Systems I/O devices are very slow Waiting is inefficient use of computerWhen one program is waiting for I/O, another can use the CPU
10 Scheduling What are the challenges of scheduling ? When do we start a new program ?When a program is blocked, what program is executed next?When several programs are blocked, which gets first dibs at the resource needed?How long can one process monopolize a resource?
11 How can we model Processing? A Five State Process Model
17 Process Scheduling:What happened to the Medium-term Queue ?
18 Memory Management What are the Memory Management Issues? How can we keep the optimum “portions” of programs in memory to optimize the use of the resources ?How can we protect one program from corrupting other programs ?What do we do when all programs in memory and stalled and memory is full ?
19 Memory Management Uni-programming Multi-programming Memory split into twoOne for Operating System (monitor)One for currently executing programMulti-programming“User” part is sub-divided and shared among active processesNote: Memory size implications- 16 bits 64K memory addresses- 24 bits 16M memory addresses- 32 bits 4G memory addresses- 64 bits ? memory addresses
20 SwappingProblem: I/O is so slow compared with CPU that even in multi-programming system, CPU can be idle most of the timeSolutions:Increase amount of main memoryExpensiveSwapping
21 How Does Swapping Work? Long term queue of “processes stored on disk” Processes moved in as space becomes availableAs a process completes it is moved out of main memory to make room for other process(es)If none of the processes in memory are ready (i.e. all I/O blocked)Swap out a blocked process (intermediate queue)Swap in a ready process or a new processBut swapping is an I/O process…Isn’t I/O slow?So why does swapping make sense ?
23 Other Structures to help with Memory Management PartitioningPaging
24 Partitioning Partitioning: Fixed Size Partitions: Splitting memory into sections to allocate to processes(including Operating System!)Fixed Size Partitions:Equal-sized partitionsPotentially a lot of wasted memoryVariable-sized partitionsProcess is stored into smallest reasonable “hole”Dynamic partitionsmemory leakneed periodic compaction
27 What about Relocation Challenges? Can’t expect that process will load into the same place in memory as last time, butInstructions contain addressesFor Locations of dataFor Addresses for instructions (branching)How about having logical address and physical addresses ?Logical address - relative to beginning of programPhysical address - actual location in memory (this time)Mechanisms:Use Base AddressAutomatic (hardware) Conversion
28 Paging Then: Split memory into equal sized, “small” chunks - Page framesOperating System maintains list of free framesThen:Allocate the required number page frames to a processA process does not require contiguous page framesEach process has its own page table
31 Paging Implementation Issues Demand pagingDo not require all pages of a process in memoryBring in pages as requiredPage faultRequired page is not in memoryOperating System must swap in required pageMay need to swap out a page to make spacePerhaps select page to throw out based on recent history
32 Paging has a Potential for “Thrashing” Too many processes in too little memoryOperating System spends all its time swappingLittle or no real work is doneSolutionsGood page replacement algorithmsReduce number of processes runningAdd more memory
33 Virtual Memory Differentiation “memory models”: Implications: We do not need all pages of a process in memory for it to run - We can swap in pages only as requiredSo - we can now run processes that are bigger than total memory available!Differentiation “memory models”:Main memory is called real memoryphysical memoryUser/programmer can see much bigger memory spacevirtual memoryImplications:Page Tables can become huge and can’t fit into memoryneed multiple level tables, orinverted tables (Why inverted tables ?)
35 Problem with Inverted Page Table Every virtual memory reference causes two physical memory accessesFetch page table entryFetch dataUse Translation Lookaside Bufferspecial cache for page table(s)
36 TLB and Cache Operation (special Cache for tables)
37 SegmentationSegmentation is “partitioning” memory that is visible to the programmer- Note: Paging is not visible to the programmerUsually different segments are allocated to program and dataThere may be a number of program and data segments per process (program)e.g. to support protection levels, priority levels, organization, flexibility, etc.
38 Advantages of Segmentation Simplifies handling of growing data structuresAllows programs to be altered and recompiled independently, without re-linking and re-loadingLends itself to sharing among processesLends itself to protectionCan paging and segmentation be combined?
39 Example: Pentium II Address Translation Mechanism “Segment” uses 2 bits to provide 4 levels of protection, typically:0: OS kernel, 1: OS, 2: apps needing special security, 3: general apps
40 Pentium II (Uses hardware for segmentation & paging) Unsegmented, unpagedvirtual address = physical addressUsed in Low complexity, High performance systemsUnsegmented, pagedMemory viewed as paged linear address spaceProtection and management via paging (Ex: Berkeley UNIX)Segmented, unpagedCollection of local address spacesProtection to single byte level, Translation table needed is on chip when segment is in memory, provide predictable access timesSegmented, pagedSegmentation used to define logical memory partitions subject to access controlPaging manages allocation of memory within partitions (Ex: Unix System V)
41 Scheduling: OS Review uni-programming multi-programming time-sharing long-term scheduler (queue of all jobs potentially schedulable)short-term scheduler (queue of processes that are ready to execute)medium-term scheduling (queue of jobs that can reside in memory)blocked monitoring (queue of processes blocked for resources)new – ready – running – blocked – exit state machineMemory management:partitioningpaging – frames, pages, page fault, page table, logical/physical addrvirtual memory – inverted page table, Translation Lookaside Buffersegmentation