2 Operating SystemA operating system is a set of master programs which is desired to control entire operations of computer. Operating System is a general purpose software which is involved in each and every activity of the computer. The various functions of operating system areInterface between user and hardwarePeripheral ManagementMemory ManagementProcess Management
3 MemoryMemory refers to the physical devices used to store the data temporary or permanent. There are two types of memories that are1. Primary Memory:- These are internal memory of computer. They are very fast. The two types of primary memory are RAM and ROM.2. Secondary Memory:- These are physical devices to store program and data. They are slow to access with higher memory capacity. The various types of secondary memories are tape, magnetic disks and optical discs.
4 Principals of Memory Management The various aim and principals of memory management areTo provide the memory space to enable many processes to be executed at same time.To protect the processes from each other.To provide satisfactory level as performance to users.To make addressing of memory space transparent for an programmer.
5 Address BindingEach program resides on a disk but it must be brought to memory for execution. The process has to be moved between disk and memory. Thus different memory address are used at different location. The process of changing the addresses during storage is called binding. The various types of binding areCompile Time BindingLoad Time BindingExecution Time Binding
6 Physical and Logical Address 1. Physical Address:- The actual addresses that refer to actual physical location of the main memory are called physical addresses.2. Logical Address:- The addresses generated by CPU are called Logical addresses.The logical and physical addresses are same at compile time and load time binding. But it differs at Execution time binding. The mapping of logical address to physical addresses is done by hardware device called Memory Management Unit.
7 RelocationThe logical addresses are converted into physical addresses by the help of relocation register present in Memory Management Unit or by relocating linkers and loader. The ability to load and execute a given program to arbitrary place in memory is called relocation. The user program supplies logical address must be mapped to physical addresses before they are used. The types of Relocation areStatic RelocationDynamic Relocation
8 RelocationThe types of Relocation areStatic Relocation :- The Static Relocation is performed before or during the loading of program into memory. This is done by relocating linkers and relocating loaders.Dynamic Relocation :- The Dynamic relocation is performed during the execution of the program. This is done by the help of the hardware support called Memory management Unit (MMU).
10 PartitioningThe Operating System manages the main memory by dividing the memory into regions of fixed or variable size is called Partitioning. It manages the main memory efficiently. The two types of partitions areStatic Partition:- The whole memory is divided into fixed sized frame is called static partition.Dynamic Partition:- The memory is divided into variable sized frame according to page size is called dynamic partition.
12 FragmentationFragmentation is a process in which storage space is used inefficiently, reducing capacity and often performance. Fragmentation leads to storage space being wasted, and the term also refers to the wasted space itself. The two types of fragmentation are1. External fragmentation2. Internal fragmentationThis problem is overcome by using Disk defragmentation.
13 Contiguous Memory Allocation Each logical object is placed in physical memory at consecutive addresses is called contiguous memory allocation. Generally memory is partitioned and any process requesting memory is allocated a partition. On termination, process release memory partition to a free pool of memory. There are number of scheme which can be used for a system but we can rate efficiency of a particular memory management scheme like wasted memory, time complexity, memory access overheads.
14 Static Partitioned Memory Allocation The memory partition are created sometime before the execution of user programs these partitions remain fixed. This approach is known as Static Partitioned Memory Allocation. The number and size of partitions is fixed during system generation process by considering1. Capacity of memory,2. Degree of multiprogramming,3. Size of program.
15 Dynamic Partitioned Memory Allocation The memory partition are created dynamically in response to process requests. This approach is known as Dynamic Partitioned Memory Allocation. The partition creation process goes on till the whole memory has been utilized. Whenever a process requests for memory partition, memory management of operating system creates a suitable partition to allocate to the process. It selects the greater or equal size to process, allocate the memory and keeps the record in PDT.
16 AlgorithmsFirst Fit:- OS searches the first partition large enough to store process.Next Fit:- The memory manager keep a pointer on the free list to store process.Best Fit:- Memory manager searches free list from beginning to end and selects the smallest possible portion to hold process.Worst Fit:- The memory manager scans the free list and allocate the largest memory block to create partition to store process.
17 SwappingThe process of a suspended or preempted process in main memory with a new process is called swapping. When all memory partitions have been allocated and there is need to allocate a partition to a process, a suspended or preempted processes is taken out from the memory in order to bring new process. Swapping is used to implement the multi programming in the system which have less hardware support for memory management. Swapping is done by module called Swapper
18 Swapping Process P1 Process P2 Operating System User Space Swap out Swap inOperating SystemUser SpaceProcess P1Process P2
19 CompactionThe process of relocating all partitions into one end of memory and to combine holes into large free area is called compaction. When the memory becomes fragmented, solution is to relocate all partition into one end using compaction. All the effected processes are suspended and they are copied from one to another area of memory. It can be performed whenever possible or only when needed. System compacts memory when large free area is return or there is failure to allocate memory.
20 PagingPaging is a memory management scheme that permits the physical address space of a process to be non contiguous. In paging physical memory is divided into fixed sized partitions called frames. Virtual address space is also divided into blocks of same size called pages. A page map table is used for address translation. The virtual address of a process is divided into two parts that arePage number (p)Page offset (d)
22 SegmentationSegmentation is memory management scheme in which the address space of single process is divided into blocks that may be placed into non contiguous area of memory. Due to external fragmentation the waste memory increases which should be reduced in system by using the segmentation to utilize the memory in proper manner. Segment descriptor table is use to record the details of different segment belonging to different process area in memory. It is flexible and easy to use.
23 SegmentationThe translation from virtual to physical address in main memory is done as follows.The segment number of virtual address is used to access the segment descriptor table.It is checked that whether the offset of segment is within bound of segment.The base address of segment is obtained from SDT.The offset of the virtual address is added to physical base address to get actual physical address.
25 Virtual MemoryThe secondary memory that is used to keep the portions of address spaces of currently executing process is called virtual memory. The portions are shifted to and fro between main memory and virtual memory. Virtual memory is a technique that allows the execution of processes that may not be completely in memory. By this method CPU can execute the program as large as physical memory.
26 Virtual MemoryThe various issue that are specific to virtual memory concept areAllocation Policy:- decides how much real memory to be allocated to each process.Fetch Policy :- decides when and which items are to be brought to main memory.Replacement Policy:- decides which item should replaced with new memory.Placement policy:-decides about placement of an incoming item in physical memory.
27 Demand PagingA demand paging system is similar to a paging system with swapping. Processes reside on secondary memory. When we want to execute a process, we swap it into memory. A swapper swaps the page into memory only when it needed. It avoids reading into memory pages that will not be used anyway thus decreasing the swap time and amount of physical memory needed. The hardware support for demand paging is page table and secondary memory which is same as in paging and swapping.
28 Page ReplacementTo reduce the page faults occurrence, we used the technique of page replacement. In this if no frame is free, the OS finds the one that is not in used and make it free. Then this freed frame is used to hold the page which is faulted. The routine for page replacement areFind the location of desired page on disk.Find a free framea. if there is a free frame, use it.b. if there is no free frame, use a page
29 Page Replacementreplacement algorithm to select the victim frame and write victim page to disk change the page and frame table accordingly.3. Read the page to free frame, change the page and frame tables.4 . Restart the user process.The algorithm used for page replacement area. FIFO Page Replacement,b. LRU page Replacement,c. Optimal Page Replacement
30 First In First OutFIFO replacement algorithm is the simplest replacement algorithm. In this page which is the oldest one is replaced with the new page. It use the page queue in which the page at the head is replaced with the page inserted at the tail. It is implement by using the FIFO queue. There is Belady anomaly problem with FIFO replacement algorithm. The number of page faults are increases with increase in number of frames in main memory.
31 First In First OutExample:- Consider the main memory consists of 3 frames for FIFO Page Replacement algorithm and input pattern of memory pages.7771212123123434242323
32 Optimal Page Replacement The Optimal Page Replacement algorithm replace the page that will not be used for longest period of time. The page which might not be used for longer time is replaced with the new page. This replacement algorithm has lowest page fault rate. This algorithm is difficult to implement as it requires future knowledge of the reference string. It overcome the belady’s anomaly.
33 Optimal Page Replacement Example:- Consider the main memory consists of 3 frames for Optimal Page Replacement algorithm and input pattern of memory pages.77712121232324324324323
34 Least Recently UsedThe least recently used algorithm will replace the page that has not been used for longest period of time. LRU replacement. LRU chooses that page which has not been used for the longest period of time. This algorithm is looking backward in time, rather than forward that is used in Optimal page replacement. The two implementation for LRU are Counters and Stack.
35 Least Recently UsedExample:- Consider the main memory consists of 3 frames for LRU Page Replacement algorithm and input pattern of memory pages777121212323434243232
36 SummaryMemory refers to the physical devices used to store the data temporary or permanent.The process of changing the addresses during storage is called binding.The binding is of three types are Compile Time, Load Time, Execution Time Binding.The actual addresses that refer to actual physical location of main memory are called physical addresses.The addresses generated by CPU are called Logical addresses.
37 SummaryThe OS manages the main memory by dividing the memory into regions of fixed or variable size is called Partitioning.The secondary memory that is used to keep the portions of address spaces of currently executing process is called virtual memory.A demand paging system is similar to a paging system with swappingThe algorithm used for page replacement are FIFO Page Replacement, LRU page Replacement, Optimal Page Replacement.