 Friends, myself Rohit Kumar R. Vaktharikar, working as assistant professor in computer science and engineering department, Valchin stock technology, Solapur. Now today we are going to discuss on buffer pool and its structure in Unix operating system. At the end of this lecture or we can say the session, the students will understand the concept of buffer pool and its structure. Today we have seen what is mean by the buffer in our previous video. Now today we will start from the buffer pool. The buffer pool is nothing but the set of buffers arranged in a queue. Kernel catches the data in the buffer according to the least recently used algorithm. Means when any process wants to access some buffer at that time that request is sent to the kernel to access that buffer. At that time our kernel will use the least recently used algorithm. Kernel also maintains the free list. Basically free list is a doubly circular linked list. It has dummy buffer header to denote start and end of the list. Let us look at the figure one buffer pool. In this figure one the first node is free list head that is the dummy head node and in that we will have buffer 1, buffer 2, buffer 3 up to buffer n. Each buffer in this diagram will have the two pointers forward pointer and backward pointer. Now here it is a doubly circular linked list. Since the first pointer, the forward pointer points to its next buffer and previous pointer points to its previous buffer. Now here the last buffer points to the forward pointer points to the free list head and free list heads previous pointer points to the last buffer. In this way this buffer pool will create it. Now kernel takes the buffer from the head of the free list when it wants a free buffer but it can also take the buffer from middle of the list only if it identifies the data block in the buffer. We will see this thing in the next PPT's. When kernel returns a buffer to the buffer pool it attach to the tail of the free list. Now let's look at the example. In this diagram free list buffer will have the two diagrams before and after. In the diagram what we are going to do is that we are going to allocate buffer 1 to the process. So now how we are going to deal with this we will see here. Now before in this diagram in the free list head the next buffer next node is buffer 1 and the next one is buffer 2. In that way we will have the n number of buffers as we have seen in the previous slide. Now here one process wants to access the data block and that data block is not present in the hash queue. At that time what it will do? It will requesting for the buffer to get the data block. So at that time kernel will first of all find out the free buffer in the free list. So now here the free list head the next will have the buffer 1 that is the list recently used buffer in this diagram is nothing but the buffer 1. So here we will remove the buffer 1 and give that assign that buffer to the process. So now we have done this in this diagram. So now after when we will allocate this buffer 1 to the next at that time we will get the after diagram. Now here we will have seen the buffer list head next pointer forward pointer is pointed to the buffer 2 and buffer 2's previous pointer is points to the head. So now in that way if fill delete the nth buffer otherwise we can say if kernel returns the buffer at that time here we are need to attach that buffer at the tail of the buffer as we have seen in the previous slide statement means that after buffer n will attach the empty buffer. So now here we will go for the next. Now if we will have the n number of buffers or we can say in our system we will have the thousands of buffer then at that time how we are going to manage this. At that time here if we will create one queue and we are going to maintain the buffer 1, 2, 3 up to 1000. So now I want to access the thousand number buffer at that time we need to compare that data block with each buffers. So it will take the thousand times comparisons. So it's a complexity is too high. So how we are going to deal with it then to optimize the searching we have used the hash queue. So here we are going to use the hashing techniques. Now when kernel access the disk block it serves for the appropriate device block number combination to maintain this hash is used. A hash table is a data structure that is used to store the key value pair it uses a hash function to compute an index into the array in which an element will be inserted or searched. Hashed is a function of device and block. Another links the buffer on the hash queue into the circular W linked list. It is similar to the free list which one we have already seen in the previous slides. Now just we will see how we are going to manage these things. Now in this diagram the buffers on hash queue diagram if we look at the left hand side we will have the hash queue headers the block number 0, 1, 2, 3. These are the four blocks we will have and on the right hand side we will have the different buffers with some data blocks. These buffer 1, 2, 3 have some data blocks like 28, 4 and 64. Now we will see how we are going to allocate these disk blocks to the buffer. Now here we will see how we are going to manage. We will try to explain you by some diagrams. Let us look at these diagrams. Now here if we will have this block 0 in that way if we will have the total number of 1, block 2, block 3. So now here total will have 4 hashed queues. Now here we are going to use the hashing function as block number mod n. This n is nothing but our, sorry this is the data block, n is nothing but the size of hash queue. Now we will see. Now if I want to store the 28 data block so how we will attach this data block into the queue? So now here what we will do, we will find out the total size of the queue is 4. Now and we will have the data block as a 28. So now how we are going to process it? 28 mod 4 will get the 0 means we are going to attach this 28 at 0 block. Now if I will take the next one 17th data block. Now how I will do that? Then again here we need to use 17th mod 4. Here we will get the 1 means we are going to attach 17 here. So in that way we will create the free list. Now we will look at the diagram. Now here in this diagram we will have the 28, 4, 16, 17. All these we have done it means how we are going to attach these nodes we have already explained. So now here as shown in figure 2, headers of the hash queue are on the left side and square on each row are buffered on the hash queue. Thus 28, 4 and 64 represents the buffers on the hash queue for the block number 4. Now in the previous slide we have seen that diagram the dotted lines represents the forward and backward pointer of the hash queue. The number 2 it means sorry the node 2 buffers may have contain the same block means on the hash queue we do not have the same data blocks. Therefore every disk block in the buffer pool exists on one and only one hash queue and only once on that queue it means we do not have the duplicate data on the hash queue. Now think and write. Can we have the same data block on multiple buffers in the hash queue? Pause this video and write your answer. No. System cannot have the multiple copies of the same data block on the hash queue. It creates the data consistency problem. Now the references we got these references from the details from the design of Unix Operating System book by the Morris J. Badge. Thank you.