 Working as an assistant professor in computer science and engineering department at Walton Institute of Technology, Solapur. Today, we are going to discuss on buffer cache and buffer header in UNIX operating system. Learning outcomes. At the end of this lecture or session, students will understand the concepts of buffer cache and buffer header. Before going to understand the buffer cache and buffer header, we need to just overview at the architecture of our kernel. Basically, in this kernel architecture, we will have the three different levels. In the first level, it is a user level. Second one is a kernel level and third one is a hardware level. In user level, user will perform or write some programs which are going to be executed on the operating system. So, now here we have made the three levels. Now, in the first level, there are some user programs and there will be some libraries. In the kernel level, again, it is divided into the two parts, the file subsystem and process control subsystems. User can interact with this file subsystem and process control subsystem with the help of system call interface. Now, after this file subsystem will come to the buffer cache that is in between the file subsystem and the blocks. Now, this blocks is again connected to the device driver and then that device driver is connected to the hardware control. That hardware control is going to interact with the hardware level, that is the third level of the unisopering system. If you look into this architecture, first of all, user will write a program and he will execute some functions. He wants to access some resources of the hardware and kernel. At that time, he needs to execute the system calls. That system calls first will be interact with the file subsystem means here each and everything will be treated as a file in unisopering system. Now, when that kernel wants to read or write some data from the hardware or the disk, at that time, there is an important concept we will use as a buffer cache. Means before going to write any data onto the file subsystem from the hardware or disk, we need to get it into the buffer cache. And after that, again if we want to write some data onto the buffer, then again we need to use this buffer cache. Now, how we are going to use all these things, we will look into the next slides. As I explained, there will be three levels of unisopering system, user level, kernel level and hardware level. We have already seen an overview of these things. Now, file system layout, basically in the file system layout, we will have the boot block, super block, inode list and data blocks. Boot blocks. Boot blocks is nothing but the first sector contained the bootstrap code to initialize the operating system. Means from here, our operating system is going to be start. Next one is a super block. Means how many files it can store and where to find the free space. All these things will be done with the help of this super block. Inode list. The inode list is the file in the file system. Each inode may represent a file or a directory. The last one is the data blocks. The list of data blocks to carry out the information in the files means whenever we are going to save any data on the disk, at that time we need to go through these layouts. Means we will actually store the data on the blocks and that blocks is represented, that blocks will represent the information in the files. And these files will be accessed with the help of the inode. And this inode or this part of this again super block. In this way, this layout will use. Now, here will come the what is mean by a buffer. A buffer is also called a buffer memory, is a portion of a computer memory that is set aside as a temporary holding place for data. That is being sent or received from an external device such as a hard disk, keyboard or printer. A buffer in a computer system is usually located in between the two devices that have the different speeds for handling the data or used when there is a difference in timing of events. For example, central processing unit have far higher speed than the hard disk and thus the data that is to be used by the CPU is first copied from the hard disk to the buffer while the CPU is performing the other task so that it will be available for the CPU to use at high speed. That is without wasting the CPU time waiting for the data. Means here we can say to make a proper synchronization between the CPU and hard disk. This buffer will perform a very major and important role. Now we will come for the next one what is mean by the buffer cache. The kernel could read and write the directly to and from the disk for all file system access but systems response time and throughput would be poor because of the slow disk transfer. The kernel therefore attempts to minimize the frequency of the disk access by keeping a pool of internal data buffers that is called the buffer cache. Means what? In this buffer cache our kernel will store the list recently used data. Means when user will request for some data from the hard disk directly going to visit or directly accessing the hard disk before that kernel will first look into the data into the buffer cache. If the data is available in the cache at that time directly it will utilize it. It means it will perform the fastest operations with the help of this buffer. Now just look into this diagram in the disk will have the 1, 2, 3, 4 these are the different data blocks and in the memory will have the 1 and 2 means what the user wants to read the file block. At that time that kernel first bring that block into the memory and again when user wants to write some data on the file block at that time again we need to bring that block into the memory and we will need to perform some operations. We need to perform some write operations on that block and again it will copy back into the disk. This will happen in the buffer cache. Now we will go for the buffer header. Each buffer header is a data structure just like the inode which is used to store the information for the physical buffer it represents. Now just we look into the buffer header. Now in this buffer header we will have the device number, block number, status, pointer to the data area, pointer to the previous buffer on a hash queue, pointer to the next buffer on the hash queue, pointer to the previous buffer on the free list, pointer to the next buffer on the free list means these are the different attributes the buffer header is going to be stored. Now here basically the device number is nothing but the data and block is nothing but the buffer block. Now we will look into the here. The device number field and the block number field that specify the file system and the block number of the data on the disk and uniquely identify the buffer. Basically the status of the buffer is combination of the following conditions. The buffer is currently locked means the term locked and busy will be used interchangeably as will free and unlocked means the buffer is currently locked or unlocked free or unlocked busy we can identify with the help of the status and again the buffer contains the valid data. This status will indicate whether the buffer is going to store the valid data or not. The kernel must write the buffer content to the disk before reassigning the buffer. This condition is known as the delayed write. The kernel is currently reading or writing the contents of the buffer to the disk. That will indicate the status and the last one is a process is currently waiting for the buffer to become free. So now these are the different status of the buffer headers. Now again the buffer header also contains the two set of pointers that we have already elaborated in the previous slides. This pointer is used by the buffer allocation and some algorithm to maintain the overall structure of the buffer pool. We will explain these things into the next videos. Now think and write is buffer cache will affect on the overall performance of the CPU. Can buffer is an important thing which affect on the performance of the CPU while reading or writing in the data on to the disk here. Yes, buffer is usually located between the two devices that have different speeds for handling the data are used when there is a difference in the timing of events. With the help of buffer the system will performs the proper synchronization of process means what? When any process wants to access some data from the disk at that time what it will do it will first of all execute the read system call it means it will give the details which data block is going to be access and now after that it will send the request to the kernel then what kernel will do? The kernel will go to the buffer block and check whether that data is available in the buffer. If the data is available in the buffer at that time it will just read the data and give the response back to the user and now if the data is not available in the buffer at that time what you need to do? You need to access the data block on the disk and again you need to read that data again come back to the buffer cache make the entry of that data block into the data cache and give that data block to the process. Now this is the things means what? If the data is available in the buffer at that time it will stop going forward it means stop accessing the disk. It means directly process will execute the system call look into the data into the cache if data is available then directly give you the response to the process and it will start its execution. So in that way it will improve the performance so that is why buffer is a very important task important part of the architecture. Now references we got this data from the design of Unix operating system by Moorish batch and we have referred some websites like slideshares.com and all.