TK 6123 COMPUTER ORGANISATION & ARCHITECTURE

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Memory Design Example. Selecting Memory Chip Selecting SRAM Memory Chip.
Operating System Support Focus on Architecture
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
CS 104 Introduction to Computer Science and Graphics Problems
Chapter 15 – Part 1 The Internal Operating System
Memory Management 2010.
Virtual Memory Chapter 8.
Chapter 8 Operating System Support
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory Management Chapter 5.
Computer Organization and Architecture
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Computer Organization and Architecture Operating System Support Chapter 8.
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
Review of Memory Management, Virtual Memory CS448.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Chapter 9 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Subject: Operating System.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
Memory Management – Page 1CSCI 4717 – Computer Architecture CSCI 4717/5717 Computer Architecture Topic: Memory Management *** Modified – look for Reading:
Computer Architecture Chapter (8): Operating System Support
Chapter 7 Memory Management
Memory Management Chapter 7.
Memory Management.
CPU SCHEDULING.
Chapter 2 Memory and process management
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
ITEC 202 Operating Systems
Chapter 5a: CPU Scheduling
Chapter 8 Operating System Support
William Stallings Computer Organization and Architecture
Uniprocessor Scheduling
Uniprocessor Scheduling
Chapter 8 Virtual Memory
Chapter 2.2 : Process Scheduling
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
Main Memory Management
Process management Information maintained by OS for process management
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 15 – Part 1 The Internal Operating System
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Operating System Concepts
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Operating Systems.
Chapter5: CPU Scheduling
Operating System 9 UNIPROCESSOR SCHEDULING
Chapter 5: CPU Scheduling
Computer Architecture
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Uniprocessor Scheduling
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
CPU Scheduling: Basic Concepts
CSE 542: Operating Systems
Presentation transcript:

TK 6123 COMPUTER ORGANISATION & ARCHITECTURE Lecture 12: The Internal Operating Systems

FUNDAMENTAL OS REQUIREMENTS The OS must divide up the space in memory, load one or more programs into that space, and then execute those programs, giving each program sufficient time to complete. It also provides file, I/O, and other services to each of the programs. When not providing services, it sits idle. May 18, 2018

FUNDAMENTAL OS REQUIREMENTS The challenge is that multiple programs are each sharing resources: memory, I/O, and CPU time Thus, the OS must provide additional support functions that allocate each program its fair share of memory, CPU time, and I/O resource time when it is needed. It must also isolate and protect each program, yet allow the programs to share data and communicate, when required. May 18, 2018

Processes and Threads A process is defined as a program, together with all the resources that are associated with that program as it is executed. Jobs, tasks, and processes. When the job is admitted to the system, a process is created for the job. Each of the tasks within the job also represent processes, that will be created as each step in the job is executed. May 18, 2018

PROCESSES AND THREADS Processes that do not need to interact with any other processes are known as independent processes. In modern systems, many processes will work together. They will share information and files. Processes that work together are known as cooperating processes. The OS provides mechanisms for synchronizing and communicating between processes that are related in some way: E.g. semaphore - nonnegative integers variable. May 18, 2018

PROCESSES AND THREADS To keep track of each of the different processes that are executing concurrently in memory, the OS creates and maintains a block of data for each process in the system - a process control block (PCB). The PCB contains all relevant information about the process. May 18, 2018

Process Creation Since any executing program is a process, almost any command that you type into a multitasking interactive system normally creates a process. Creating a new process from an older one is commonly called forking or spawning. The spawning process is called a parent. The spawned process is known as a child. May 18, 2018

Process Creation Removing a parent process usually kills all the child processes associated with it. When the process is created, the OS gives it a unique ID, creates a PCB for it, allocates the memory and other initial resources. When the process exits, its resources are returned to the system pool, and its PCB is removed from the process table. May 18, 2018

Process States Three primary operating states for a process. ready state, Once a process has been created and admitted to the system for execution. A process is capable of execution if given access to the CPU. running state, When the process is given time for execution. Moving from the ready state to the running state is called dispatching the process. Only one process can be in the running state at a time for a uniprocessor system. May 18, 2018

Process States blocked state. Some OS will suspend the program when I/O or other services are required for the continuation of program execution; This state transition is known as blocking. When the I/O operation is complete, the OS moves the process from the blocked state back to the ready state. This state transition is frequently called wake-up. May 18, 2018

Five State Process Model May 18, 2018

Process States Nonpreemptive systems will allow a running process to continue running until it is completed or blocked. Preemptive systems will limit the time that the program remains in the running state to a fixed length of time corresponding to one or more quanta. If the process remains in the running state when its time limit has occurred, the OS will return the process to the ready state to await further time for processing. The transition from the running state to the ready state is known as time-out. When the process completes execution, control returns to the OS, and the process is destroyed or killed or terminated. May 18, 2018

Threads A thread represents a piece of a process that can be executed independently of other parts of the process. Each thread has its own context, consisting of a PC value, register set, and stack space, but shares program code, and data, and other system resources such as open files with the other member threads in the process. Threads can operate concurrently. Like processes, threads can be created and destroyed and can be in ready, running, and blocked states. May 18, 2018

CPU Scheduling Provides mechanisms for the acceptance of processes into the system and for the actual allocation of CPU time to execute those processes. Separated into two different phases: The high-level, or long-term, scheduler is responsible for admitting processes to the system. The dispatcher provides short-term scheduling, specifically, the instant-by-instant decision as to which one of the processes that are ready should be given CPU execution time. May 18, 2018

High-level Scheduler Determines which processes are to be admitted to the system. Once submitted, a job becomes a process for the short term scheduler. The criteria for admission of processes to a batch system are usually based on: priorities the balancing of resources, Although some systems use a first-come, first-served algorithm. May 18, 2018

Short Term Scheduler: Dispatching Dispatcher Fine grained decisions of which job to execute next i.e. which job actually gets to use the processor in the next time slot May 18, 2018

Dispatching Some conditions that might cause a process to give up the CPU: voluntary involuntary. Dispatcher aims to select the next candidate in such a way as to optimize system use. Processes vary in their requirements. Long/short CPU execution time, Require many/few resources, Vary in their ratio of CPU to I/O execution time. Different scheduling algorithms favor different types of processes or threads and meet different optimization criteria. May 18, 2018

Dispatching The choice of scheduling algorithm depends on the optimization objective(s) and expected mix of process types. Some of the objectives are: Ensure fairness Maximize throughout Maximize CPU utilization Maximize resource allocation Minimize response time Provide consistent response time Prevent starvation Starvation (indefinite postponement) is a situation that occurs when a process is never given the CPU time that it needs to execute. It is important that the algorithm selected not permit starvation to occur. May 18, 2018

Nonpreemptive Dispatch Algorithms FIRST-IN, FIRST-OUT (FIFO) Processes will be executed as they arrive, in order. Starvation cannot occur with this method, and the method is certainly fair in a general sense; however, it fails to meet other objectives. SHORTEST JOB FIRST (SJF) Maximize throughput by selecting jobs that require only a small amount of CPU time. Since short jobs will be pushed ahead of longer jobs, starvation is possible. Turnaround time is particularly inconsistent. May 18, 2018

Nonpreemptive Dispatch Algorithms PRIORITY SCHEDULING The dispatcher will assign the CPU to the job with the highest priority. If there are multiple jobs with the same priority, the dispatcher will select among them on a FIFO basis. May 18, 2018

Preemptive Dispatch Algorithms ROUND ROBIN Gives each process a quantum of CPU time. The uncompleted process is returned to the back of the ready queue after each quantum. It is simple and inherently fair. Shorter jobs get processed quickly: Reasonably good on maximizing throughput. Does not attempt to balance the system resources,: penalizes processes when they use I/O resources, by forcing them to reenter the ready queue. May 18, 2018

Preemptive Dispatch Algorithms MULTILEVEL FEEDBACK QUEUES Attempts to combine some of the best features of several different algorithms. This algorithm favors short jobs and I/O-bound jobs (resulting in good resource utilization). It provides high throughput, with reasonably consistent response time. May 18, 2018

Preemptive Dispatch Algorithms MULTILEVEL FEEDBACK QUEUES The dispatcher provides a number of queues. A process initially enters the queue at the top level (top priority). Short processes will complete at this point. Many I/O-bound processes will be quickly initialized and sent off for I/0. Processes that are not completed are sent to a second-level queue. Processes in the second-level queue receive time only when the first-level queue is empty. Although starvation is possible, it is unlikely, because new processes pass through the first queue so quickly. May 18, 2018

Preemptive Dispatch Algorithms DYNAMIC PRIORITY SCHEDULING Windows 2000 and Linux use a dynamic priority algorithm as their primary criterion for dispatch selection. The algorithms on both systems adjust priority based on their use of resources. May 18, 2018

Memory Management The goal is : to make it as simple as possible for programs to find space, so that they maybe loaded and executed. to maximize the use of memory, that is, to waste as little memory as possible. There may be more programs than can possibly fit into the given amount of physical memory space. Even a single program may be too large to fit the amount of memory provided. May 18, 2018

Memory Management Uni-program Multi-program Memory split into two One for Operating System (monitor) One for currently executing program Multi-program “User” part is sub-divided and shared among active processes May 18, 2018

Memory Management Traditional memory management: Virtual storage: Memory Partitioning. Overlays Virtual storage: Paging Page replacement algorithms Trashing Segmentation May 18, 2018

Memory Management : Partitioning Splitting memory into sections to allocate to processes (including Operating System) Fixed-sized partitions May not be equal size Process is fitted into smallest hole that will take it (best fit) Some wasted memory Leads to variable sized partitions May 18, 2018

Fixed Partitioning May 18, 2018

Variable Sized Partitions (1) Allocate exactly the required memory to a process This leads to a hole at the end of memory, too small to use Only one small hole - less waste When all processes are blocked, swap out a process and bring in another New process may be smaller than swapped out process Another hole May 18, 2018

Variable Sized Partitions (2) Eventually have lots of holes (fragmentation) Solutions: Coalesce - Join adjacent holes into one large hole Compaction - From time to time go through memory and move all hole into one free block (c.f. disk de-fragmentation) May 18, 2018

Effect of Dynamic Partitioning May 18, 2018

Internal and External Fragmentation May 18, 2018

Memory Management : Overlays If a program does not fit into any available partition, it must be divided into small logical pieces for execution-overlay. Each piece must be smaller than the allocated memory space. May 18, 2018

Memory Management : Overlays Most systems do not allow the use of multiple partitions by a single program: An alternative is to load individual pieces as they are actually needed for execution. Disadvantage: It cannot take advantage of more memory if it is available, since the overlays are designed to fit into a specific, given amount of memory. May 18, 2018

Virtual Storage Virtual storage can be used to store a large number of programs in a small amount of physical memory makes it appear that the computer has more memory than is physically present. So - we can now run processes that are bigger than total memory available! MMU (Memory Management Unit)- is a device for mapping virtual-to-physical address. May 18, 2018

Virtual Storage Is an important technique for the effective use of memory in a multitasking system. To translate a virtual/logical address to a physical address with paging: the virtual address is separated into a page number and an offset; a lookup in a page table translates, or maps, the virtual memory reference into a physical memory location consisting of a corresponding frame number and the same offset. Logical address - relative to beginning of program. Physical address - actual location in memory Automatic conversion using base address May 18, 2018

Virtual Storage Every memory reference in a fetch- execute cycle goes through the same translation process, which is known as dynamic address translation (DAT). The address that would normally be sent to the memory address register (MAR) is mapped through the page table and then sent to the MAR. May 18, 2018

Virtual Storage May 18, 2018

Virtual Storage Each process in a multitasking system has its own virtual memory, and its own page table. Physical memory is shared among the different processes. Since all the pages are the same size, any frame may be placed anywhere in memory. The pages selected do not have to be contiguous. Therefore, virtual memory eliminates the need for: overlay techniques contiguous program loading (partitioning) May 18, 2018

Virtual Storage : Paging Split memory into equal sized, small chunks -page frames Split programs (processes) into equal sized small chunks - pages Allocate the required number page frames to a process Operating System maintains list of free frames A process does not require contiguous page frames Use page table to keep track May 18, 2018

Implementation of Paging (1) The first 64 KB of virtual address space divided into 16 pages, with each page being 4K. The virtual address space is broken up into a number of equal-sized pages. Page sizes ranging from 512 to 64KB per page (always a power of 2). May 18, 2018

Implementation of Paging(2) A 32 KB main memory divided up into eight page frames of 4 KB each. The physical address space is broken up into pieces in a similar way (each being the same size as a page). May 18, 2018

Allocation of Free Frames May 18, 2018

Logical and Physical Addresses - Paging May 18, 2018

Virtual Storage : Paging To execute a program instruction or access data, two requirements must be met: The instruction or data must be in memory. The page table for that program must contain an entry that maps the virtual address to the physical location. If a page table entry is missing when the memory management hardware attempts to access it, the CPU hardware causes a special type of interrupt called a page fault or a page fault trap. May 18, 2018

Virtual Storage : Paging Page fault Required page is not in memory Operating System must swap in required page May need to swap out a page to make space Select page to throw out based on recent history May 18, 2018

Virtual Storage : Paging Demand paging Do not require all pages of a process in memory Bring in pages as required i.e. swapping the page as a result of a page fault. Most systems perform use demand paging. May 18, 2018

Virtual Storage : Paging A few systems attempt to anticipate page needs before they occur, so that a page is swapped in before it is needed. Prepaging. Have not been very successful at predicting accurately the future page needs of programs. May 18, 2018

Virtual Storage : Page Replacement Algorithms FIFO The oldest page remaining in the page table is selected for replacement. LEAST RECENTLY USED (LRU) Replaces the page that has not been used for the longest time. LEAST FREQUENTLY USED Replace the page that has been used the least frequently. NOT USED RECENTLY (NUR) Is a simplification of the LRU algorithm. Replace page that has not been used for a while. May 18, 2018

Virtual Storage : Page Replacement Algorithms SECOND CHANCE A variation of FIFO, using a referenced bit similar to that of NUR. When the oldest page is selected for replacement, its referenced bit is checked. If the referenced bit is set, the bit is reset, and the time is upgraded, as though the page had just entered memory. This gives the page a second pass through the list of pages. If the referenced bit is not set, then the page is replaced, since it is safe to assume that it has not been referenced in some time. May 18, 2018

Thrashing Too many processes in too little memory OS spends all its time swapping: Page fault is passed around from program to program. No program is able to execute, and the system as a whole slows to a crawl or crashes. Little or no real work is done. Disk light is on all the time. Solutions Good page replacement algorithms Reduce number of processes running Fit more memory May 18, 2018

Virtual Storage : Segmentation Paging is not (usually) visible to the programmer. Segmentation is visible to the programmer. Usually different segments allocated to program and data. May be a number of program and data segments. Segments are of variable and dynamic size. May 18, 2018

Segmentation In a one-dimensional address space with growing tables, one table may bump into another. May 18, 2018

Segmentation A segmented memory allows each table to grow or shrink independently of the other tables. May 18, 2018

Comparison of paging and segmentation. May 18, 2018

Implementation of Segmentation (a)-(d) Development of external fragmentation. (e) Removal of the external fragmentation by compaction. May 18, 2018

Advantages of Segmentation Simplifies handling of growing data structures. Allows programs to be altered and recompiled independently, without re-linking and re-loading. Lends itself to sharing among processes. Lends itself to protection. Some systems combine segmentation with paging. May 18, 2018

Secondary Storage Scheduling First-come, first-served (FCFS): As requests arrive, they are placed in a queue and are satisfied in order. The problem is that seek time on a disk is long and somewhat proportional to the distance that the head has to move. With FCFS, the head need to move all over the disk to satisfy requests. It would be preferable to use an algorithm that minimizes seek distances. This would suggest processing requests that are on nearby tracks first. May 18, 2018

Secondary Storage Scheduling Shortest distance first (SDF): Looks at all the requests in the queue and processes the one nearest to the current location of the head. This algorithm suffers from the possibility of indefinite postponement. May 18, 2018

Secondary Storage Scheduling Scan scheduling: Attempts to satisfy the limitation of SDF scheduling. The head scans back and forth across the disk surface, processing requests as it goes. May 18, 2018

Secondary Storage Scheduling N-step C-scan: One is to cycle in only one direction, then return to the other end before accessing blocks again. Maintain two separate queues. Once the head has started to traverse the disk, it will read only blocks that were already waiting when the traverse started. Prevents block requests that are just ahead of the head from jumping into the queue. Such a block would be placed in the alternate queue to wait for the next pass. May 18, 2018

Other Operating System Issues Deadlock: When one process has a resource that another process needs to proceed, and the other process has a resource that the first process needs, then both are waiting for an event that can never occur. May 18, 2018

Deadlock Solution: deadlock prevention. eliminating any condition that could create a deadlock. the safest method. deadlock avoidance. continually monitoring the resource requirements, looking for situations in which a deadlock potential exists and then not allowing that situation to occur. deadlock detection and recover. Simplest method to implement, but the most costly when things go wrong. Allows deadlocks to occur. Recovery techniques include terminating processes and preempting resources. May 18, 2018

OTHER OPERATING SYSTEM ISSUES May 18, 2018

Thank you Q & A May 18, 2018