 Hello, today we are going to speak on the topic memory management policies. Now we will see learning outcome. At the end of this session, students will be able to describe different approaches to memory management policies including swapping. First we will see memory management in the Unix. Memory management is the functionality of an operating system which handles or manages primary memory and moves process back and forth between main memory and the disk during execution. Memory management keeps track of each and every memory location regardless of either it is allocated to some process or it is free. It checks how much memory is to be allocated to processes. It decides which process will get memory at what time. It tracks whenever some memory gets freed or unallocated and correspondingly it updates the status. Here we can say memories are important resource in computer. Memory management is the process to managing the computer memory which consists of primary memory and secondary memory and the goal of primary memory management is to keep track of which parts of memory are in use and which parts are not in use. To allocate memory to processes when they need it and deallocate it when they are done. Unix memory management scheme includes swapping process. When we talk about the overlays to enable a process to be larger than the amount of memory allocated to it we can use overlays. The idea of overlays is to keep in memory only those instructions and data that are needed at any given time. When other instructions are needed they are loaded into spaces occupied previously by instructions that are no longer needed. Here first program will be placed into memory during execution however a large program will divide into small pieces and loading the pieces as they needed. Overlays will replace the new pieces with the program which is unused. Unix is using this technique to run a new program by fork the running process which is also known as fork execution. Here we will see the concept of overlays with example of a 2 pass compiler. Here 2 pass compiler assembler has having available memory 150k and our code size is 200k. So how it does? Pass1 occupies 70k memory, pass2 occupies 80k memory, common routine driver occupies 30k, symbol table occupies 20k memory. Here common routine symbol table, overlays driver and pass1 code are loaded into the main memory for program execution to start. When pass1 has finished its work pass2 code is loaded onto top of the pass1 code because this code is not needed anymore. This way we can execute 200k processes in a 150k memory. The problem with overlays are that you may not be able to partition all problems into overlays and for that program is responsible for writing the overlays driver. Now we go for important part is swapping. First we will see the definition, the process of moving some pages out of main memory and moving others in is called swapping. Others stand for in the other disk is called swapping. Swapping consists of bringing each process in physical memory entirely and running it. When the process is no longer in use the process will be terminated or is swapped out to the disk. Now we will see swapping of two processes using disk as a backing store. First of all we have operating system. Then we created user space both are in the main memory. Then we have a process p1 always in the main memory. Then we have a backing store. Backing store is having a processes and we have a sapped out processes from main memory. Process p2 is contained in backing store. Then we want to swap in process to the main memory. Now we will see how process p1 is moved from main memory to backing store and process p2 is moved from backing store to main memory. This is a small introduction about a swapping of two processes using a disk as a backing store. Now we go for very important thing swapping algorithm. There are three types of swapping algorithm managing space on the swap device, swapping process out of main memory, swapping process into main memory. First we will see allocation of swap space. The swap device is a block device in a configurable section of a disk whereas the Kerner allocates space for files one block at a time. It allocates space on the swap device in a group of contiguous blocks. Space allocated for files is used statically. The allocation of swap space on the swap device is transitory depending on the pattern of process scheduling. A process that resides on the swap device will eventually migrate back to the main memory. Freeing the space it had occupied on the swap device since the speed is critical and the system can do IO operation faster in one multi block operation than in several single block operation. It maintains the free space for the swap device in an encode table called a map. Maps used for other resources besides the swap device. Some device drivers for example allow first in first feed allocation of contiguous blocks of resource. A map is an array where each entry consists of an address of an allocable resource and number of resource units available there. The Kerner interprets that indicates the addresses and unique units according to the type of the map. Here in the diagram we have shown the initially starting address at one and the number of units allocated for the Kerner in on the swap device. The freed resources completely fill a hole in the map. They are contiguous to the entries whose address would immediately proceed them and follow them in the map. In this case Kerner combines a newly freed resources and the existing entries on into one entry in the map. The freed resources partially fill a hole in the map. Here the address of the freed resources are contiguous with the map entry that would immediately precede them or with the entry that would immediately follow them. The Kerner adjusts the address and units fields of the appropriate entry to account for the resources just filled. The number of entries in the map remains the same. The freed resources partially fill a hole but are not contiguous to any resources in the map that is shown in the figure. Now we go for the algorithm for the memory allocation which is important for allocating a space from the maps. Here the Kerner searches the map for the first entry that contains the enough space to accommodate the request. Here we provide the input as the map number and the logical units. If the request consumes all the resources of the map entry the Kerner removes the entry from the array and compresses the map that is the map has one fewer entries. Otherwise it adjusts the address and unit fields of the entry according to the amount of resources allocated. In this figure shows the sequence of the map configuration after allocating the 100 units, 50 units and 100 units. Now we will see how the free swap space will occur by the Kerner. Kerner first will assign the physical address and then logical unit which is resets on the map. Here first the address is 251 and logic units are available 9750 units. Then Kerner frees 50 units at the particular address that is a 101 and 50 and the existing address fill a hole by the Kerner that is on 251 and 9750 but it is not contiguous to any resources in the map. Next the same addresses are available on the map device where Kerner frees a 50 unit at the same address and again Kerner frees 100 units at the same address. So the new address will be occupied on this web device is 1 at 251 and 150 at 9750. Here freeze resources fill a hole and immediately precedes an entry in the map. This is we are talking about case 2 and then we talk about case 3 is here free resources fill a hole and completely fills the gap between entries in the map that we will see in the figure. First map contains 251 address and units are 9750. Here Kerner frees 50 units again 101, 50 and Kerner frees 100 units again 150 and Kerner allocates 200 more units on the free available map device. So again it will come 451 and 9550 and Kerner allocates more 300 units free at 151 so it will become as 1 and 10000. So these are the free resources fill hole and it is happened by the Kerner. Now we go for second algorithm swapping process out. Here the Kerner swaps process out if it needs space in memory which may result any of the following. The folk system call must allocate space for a child process. The BRK system call increases size of a process. A process becomes larger by the natural growth of its stack and the Kerner wants to free space in memory for processes it had previously swapped out and should now swap in. When the Kerner decides that a process is eligible for swapping from main memory it decrements the reference count for each region in the address and swaps the region out of its reference count drops to 0. In the figure gives the example of mapping in core image of process onto swap device. The process contains free region for text data and stack region ends at, text data and stack region ends at virtual address 2k. The data region starts at virtual address 64k leaving a gap of 64k bytes in the virtual address space. When the Kerner swaps the process out it swaps the preges for virtual address 0, 1k, 64k, 65k, 66k and 120k. It does not allocate swap space for the empty 16k bytes between the text and data region or the empty 61k bytes between the data and stack region but fills the swap space continuously. When the Kerner swaps the process back in it knows that the process has 16k byte whole by consulting the process memory map and it assigns the physical memory accordingly. Now we have a question based on the previous contents. What is a swap space? Here the answer is swap space is a certain amount of space used by Linux to temporarily hold some programs that are running concurrently. This happens when RAM does not have enough memory to hold all programs that are executing. These are the references. Thank you.