Welcome to this course on Operating System Concepts
2 3 4 6 11 12 13 Operating System is a set of system programs which provides an environment to help the user to execute the programs. The OS is a resource manager which allocates and manages various resources like processor(s), main memory, input/output devices and information (files) on secondary memory devices. The primary goal of Operating System is to provide the execution environment for the system programs and application programs. Secondary Goal of Operating System is to manage and allocate the system resources efficiently to various applications running in the system. Resource Examples Managers Memory Primary, Secondary Memory Management Processors CPU, I/O Process Management Peripherals Terminal, Printer, Tape Device Management Information Files, Data File Management Examples: WINDOWS XP WINDOWS VISTA LINUX UNIX OS/ 2 System Software which acts as an interface between the user and the computer. It provides an environment to execute different types of applications It is viewed as a Resource Allocator or Resource Manager Memory Processors Peripherals Information 14 15 Operating System is a set of system programs which provides an environment to help the user to execute the programs. 16 17 Introduction to Operating Systems Introduction to the Concepts of Memory Management In sequential program execution/ Uniprogramming , only one program/job at a time can reside in main memory. CPU execute this program. When program is busy in I/O CPU sits idle for that time. 18 19 20 21 Introduction to Operating Systems Introduction to the Concepts of Memory Management 22 The computer must keep several processes in memory at the same time to improve the CPU utilization and the speed of the response of the computer to its users. Memory management discusses various ways to manage memory. 23 There are various memory management schemes as mentioned in the slide above. Each scheme has its own advantage and disadvantage. Selection of a particular technique depends on various factors such as hardware support, extent of memory available etc. Logical address is the address generated by the CPU and the range of these addresses is called Address Space/ User Dddress Space. Where as physical address is the actual address of the process in the main memory and the range of these addresses is called Memory Space /Physical Address Space . 24 Simple paged allocation is a solution to fragmentation. Advantage: As each page is separately allocated, the users job need not be contiguous. Disadvantages: Extra memory required for storing page tables Considerable amount of hardware support is required for address transformations etc. All pages of entire job must be in memory 25 The example in the slide above shows a page map table for 2 jobs viz., page number and frame number which essentially shows the mapping between page number and block number. JOBA has 3 pages viz., 0,1,2. Page 0 maps to frame 5 in the OS, page 1 to frame 3 and page 2 to frame 1 in the OS. JOB 2 has page 0 in frame 2 and page1 in frame7. Thus, we can see that pages of a job need not be located contiguously in the memory. 26 An address in jobs address space is considered to be of the form(p,d) where p is the page number containing the memory location and d is the displacement (offset) of the memory location from the start of the page. This page number acts as index to a page table which is created for every job. This page table gives the corresponding frame number in the main memory for the particular page. This frame number with the displacement would give the physical address. The Page table has two purposes: It has got entries which map each page number in the program (in the secondary memory) and the corresponding page frame number (or block number present in the primary memory). Since there is one to one mapping between the page number and the frame number , even if the pages are not contiguous in the primary memory, there exists a link between all the pages of a job through this mapping in the page table. 27 Fragmentation is wastage of memory, it occurs when memory is divided in to many small chunks/free blocks and these free blocks are not able to satisfy any request. Fragmentation is of two type: 1. Internal fragmentation 2. External fragmentation Internal Fragmentation: As shown in the diagram in this slide, internal fragmentation is wastage of the space inside the allocated memory blocks. Because page size / memory block is of fixed size. Job may need less space but minimum 1 memory block is allocated(space allocated to a job is always multiple of frame) , so the wastage of memory happens is internal fragmentation. Limitation because of fixed size memory block. External Fragmentation: Memory that is not allocated to any job but still unusable because it is divided in to small chunks. These chunks are too small to satisfy the request of any job. 28 29 The diagram in the slide above shows the page map table for demand paging. The page map table (PMT) has two additional columns viz., status and modify or judgment. Initially, all the pages have status field as NA (Not Available) implying that all the pages are in the secondary device (disk). As and when a page is loaded from the secondary to primary, the status is updated to A (Available) from NA. Now, if the same page is required again in the main memory, the status bit will indicate the presence of it in the primary memory. The judgment field decides if a page has to be moved back to the secondary memory or not. 1000, 2000, 3000 are the frame starting addresses 30 31 Page Fault: If a user job accesses a page and the page is not available in the main memory, a page fault is said to occur Page Replacement: If the memory is full then the inactive pages which are not needed currently for execution are removed and are replaced by those pages from the secondary device which are to be executed. This is called Page Replacement. FIFO: If the algorithm decides that the page has been first moved to the memory should be moved out to secondary memory first, then it is using FIFO. LRU: If the algorithm decides to move a page from main memory and store it in secondary memory based on the fact that it is not used often in the recent times, then it is called LRU. For every page a timestamp is maintained in the judgment field. LFU: If the algorithm decides to move a page from main memory and store it in secondary memory based on the fact that it is not used often, then it is called LFU. For every page a reference counter is maintained in the judgment field. NRU: If the algorithm decides to move a page from main memory and store it in secondary memory based on the fact that it is not used at all in the recent times, then it is called NRU. A reference bit is associated with each page. MRU: If the page which has been used recently will be replaced by the incoming page. MFU: This technique replaces the page which is used most frequently Demand Paging technique could lead to a scenario where in a job might try to access a particular page which is not available in main memory. This would lead to a fault called page fault. Consider the figure discussed in slide 34 (All frames are already occupied), suppose that the page 2 of job A, which is currently in memory, tries to access page 1 of job A then a page fault would occur because page 1 is not loaded in memory. Once this page fault is caused the OS would replace one of the existing pages in physical memory with page 1 of job A . the process of removing some pages from physical memory to accommodate new pages is called Page Replacement. 32 Number of page faults=10 Number of page replacement = 7 33 Number of Page faults=9 34 Number of Page faults=9 Ask the participants to solve the problem using LFU with LRU technique instead of FIFO. Another variation could be not to reset the counter even as a page is swapped out. Refer to the examples in the course material for more examples on different types of page replacement algorithms. 35 In paging , job is divided into fixed length pages , it does not provide support to user view of memory. User view of memory means , user like to see job is divided into variable length segments. For example, a program consist of main program , one or more then functions/ subroutines etc. Each of these modules are referred to by a name and each of these segments may be of different length. The length of each segment is calculated from the code written in the segment or from the logical structure of the program. Thus segmentation supports the user view of memory. A programmer has a say on the number of segments in a process and this division is dependent on the logical structure of the process. 36 37 38 Suppose a process references a virtual/logical address V=(S, P, d) ,then a search will be performed to locate (S,P). There are three possibilities for it (i) If (S,P) found in associative storage then , we fine page frame and then move as per offset to get real memory address. (ii) If (S,P) is not found in associative storage then we should follow these steps (i) Find base address b of segment map table ( in primary memory) (ii) Add b to segment number S ( Say we set S1) (iii) Then we add S1 to P to get frame number (iv) Finally we add offset d to get real memory address. (iii) If segment map table indicates that segment S is not in primary memory, a segment fault is generated 39 40 41 The computer system today allows multiple programs to be loaded into memory and to be executed concurrently but at one point of time only one program is in execution or rather at most one instruction is executed on behalf of the process. A source program stored on disk is called passive because it will not demand any resource. A process is an active entity i.e. program in execution is called process during execution process demand resource like CPU , memory , I/O etc. for the execution. 42 User feels that all of them run simultaneously, however operating system allocates one process at a time. 43 Here, the instructor must draw the state diagram in a piecemeal fashion slowly adding the complexity and inviting more questions. New Here the operating system recognizes the process but does not assign resources to it. Ready The process is ready/waiting to be assigned to a processor. Run When a process is selected by the CPU for execution, it moves to the run state. Blocked When a process is waiting for some event to occur, say for e.g I/O completion or reception of a signal then it is in the blocked state i.e. when a running process does not have immediate access to a resource it is said to be in the blocked state. Terminated This is the state reached when the process finishes execution. 44 44 Here, the instructor must draw the state diagram in a piecemeal fashion slowly adding the complexity and inviting more questions. New Here the operating system recognizes the process but does not assign resources to it. Ready The process is ready and waiting for the processor for execution. Run When a process is selected by the CPU for execution, it moves to the run state. Blocked When a running process does not have immediate access to a resource it is said to be in the blocked state. Terminated This is the state reached when the process finishes execution. 45 46 Context switching is a overhead as the system does not do any useful work while switching from one process to another. switching speed varies from machine to machine depends upon the memory speed, the no. of registers to be copied etc. Since at any point of time there could be more than one process waiting to be serviced by the CPU, these have to be put in hold at some place. A queue is a place where the IN and OUT of the process is controlled. There are different queues for different purposes. Example: I/O Queue If the process is waiting for an I/O operation to complete, then it goes to the I/O queue. Job queue A process entering the system for the first time goes into the Job queue. 47 51 52 53 54 55 56 57 58 59