 Hello everyone, today we are going to learn about layout of kernel in Unix operating system. The learning outcome of this session are at the end of this session student will be able to demonstrate how process changes mode from user to kernel and explain memory map of U area in kernel. Let us see layout of kernel. Though kernel executes in the context of a process, virtual memory mapping associated with the kernel is independent of all processes means multiple processes executes simultaneously in the system that we already know. So, virtual memory mapping for each and every process is independent of kernel. Kernel is not aware of the virtual memory mapping associated with the processes that virtual memory mapping which is associated with the kernel is independent of all the processes. Now the code and data for the kernel reside in the system permanently. Whenever system boot the system boot process load the kernel code into memory and set up the necessary tables and registers to map its virtual addresses into physical memory address. The virtual address is the address which is created by the CPU. So, it is necessary to convert that virtual address into the physical memory address. So, whenever system boots at that time the whole kernel code is loaded into the memory and it also initialize all the kernel data structures and register map which is required for this conversion. Now let us see how there is a changing mode from user to kernel. Now as we know we have two levels in Unix operating system user level and kernel level. So, whenever process executes in the system it moves between user mode and kernel mode. Now as shown in this figure we have register triple. First three register triples are for kernel mode and the next three register triples are user mode. Now this diagram shows the virtual address of the kernel mode where the kernel register triples start at virtual address 0 and it range up to 4M minus 1 while the user register triples start onwards from 4M, 4M onwards, ok. So, these are the virtual addresses for kernel mode and 4M onwards are the virtual address for the user mode. Now as shown here the kernel register triple points to the kernel page tables. These page tables are for user data, text and three regions of the kernel data text and stack regions, ok. So, these are the page tables which is associated with kernel register triple while these are the page table which is associated with the user register triple, ok. So, whenever there is a change in mode from user to kernel then it is mandatory to have an access to kernel addresses, kernel virtual address. So, whenever process will change its mode from user to kernel then kernel has to access the kernel addresses. But it is not mandatory whenever there is a change from kernel to user. As I already told that many processes executes in the system simultaneously. So, many processes are executing in kernel mode. So, the virtual memory mapping is independent of all the processes, ok, in kernel mode and that is why it is necessary to track the virtual address of the processes whenever there is a change from user to kernel mode, ok. So, this is how processes change its mode from user to kernel or kernel to user. Every time they have to refer the page table where the page table contains the physical address for that particular pages which is converted which is located as a virtual address in the kernel register triples. So, this contains the frame numbers of the physical memory, all page tables. So, this is how the changing mode from user to kernel or kernel to user happens. Now, let us pause the video and why write down the answer for this that when changing mode from user to kernel system permits access to kernel addresses. But it prohibits such access when executing in user mode. Why? This is so. Just pause the video and write down your answer, ok. Now, as I already told the virtual memory mapping which is associated with the kernel is independent of all the processes which are executing in kernel mode, which are executing in the system. So, as we know kernel contains highly privileged instructions, user processes cannot have access to kernel process or user mode cannot have access to kernel mode. So, but the kernel mode can have access to the user mode. And as all highly privileged instructions are executed in kernel mode, whenever there is a change in mode from user to kernel, it is necessary to check the kernel virtual addresses for converting that virtual address into the physical addresses. Because the virtual memory mapping which is associated with the kernel is independent of all the processes. Now, let us see about you area. Now, as I told you that there is a virtual memory mapping, virtual address to physical address. Some system creates the virtual address same as physical address. So, both addresses are identical. So, conversion function for virtual address to physical address for such system is called as a identical function. Now, next is you area. This you area is one of the kernel data structures. Every process has its private you area. Kernel access it as if there were only one you area in the system that of the running process. Kernel changes its virtual address translation map according to the executing process to access the correct area. Now, what is the written here that kernel access you area as if there were only one you area in the system which is of running process. So, kernel changes the virtual address translation map according to the executing process to access the correct you area. When compiling the operating system loader assigns the variable you the name of the you area which has a fixed virtual address. Now, the value of the you area virtual address is used at the time of the context which by the kernel you area is probably used whenever there is a context which by the kernel by the kernel means by kernel whenever there is a context which between the kernel processes. Now, kernel is aware of address translation from virtual address to physical address of you area. So, kernel dynamically change the address mapping of you area to another physical address to physical address represent you area of two process, but kernel access them via the same virtual address means virtual address for two processes are same, but whenever they are converted into the physical address there will be two physical address for two different processes. So, two physical address represent the you area of two processes, but kernel access them via the same virtual address. The process can access its you area only when it is executing in kernel mode. Kernel can access only one you area at a time by its virtual address. So, you area partially define the context of the process. Now, this is what about the you area. Now, let us see how kernel accesses the you area of the processes which are running in kernel mode. Now, let us see the memory map of you area in the system. Now, as shown here, we have total four processes process a, b, c and d in the system and this is the kernel register triple the first register triple contents text second register triple contents information about data while the third register triple contents information about the you area. Here only we have shown the virtual address of the you area and the number of pages in the page table. Text and data is not shown here. Now, let us see that currently process d is executing in kernel mode and that is why the you area points to the page table of the process d whose virtual address is 2 m and the number of pages present in these tables are four. Now, suppose kernel wants to access you area of process a then it is necessary to change the virtual address of the process. It will load the virtual address of the process in you area and the total number of pages present in the page table for that process a. So, virtual address for process a is 1 m and the number of pages present are four. So, in this way the you area virtual address changes dynamically and while the text and data do not change because processes share kernel text and data. So, in this way the you area can be accessed only one at a time in kernel mode and whenever there is a context which from one process to another process it is necessary to change this virtual address in you area in kernel register triple. So, this third field which is present in kernel register triple changes dynamically whenever there is a context which from one process to another process. So, this is all about the how the kernel how there is a change from user to kernel mode and how kernel has to access the kernel addresses whenever there is a change in mode from user to kernel and how kernel register triple changes its virtual address whenever there is a context which from one process to another process in kernel mode. This is all about the you area and change in mode from user to kernel. These are the differences. Thank you.