 Professor from WD Solakor. In this lecture I am going to discuss about the segmentation in operating system. Now these are learning objectives of this lecture. At the end of this video the student should be able to describe drawbacks of page then the segmentation mechanism and he should be able to convert logical addresses into the physical address. Now as you all know paging is a memory management scheme by which a computer stores or returns data from secondary storage to the main memory. Because during process execution the CPU is getting data from this main memory and data is now coming from the secondary memory. Now in the paging we are dividing this entire secondary memory into equal size partitions. And each partition is normally called as a page. After that the memory manager or we also call this as a MMU is dividing the physical address space into the equal pieces that is called the frame here. Paging we are finding this kind of drawbacks here. If you choose the large size page during the paging mechanism. So it is normally is going to carry the problem of internal fragmentation. That is lot of space is remaining unused here and we are going to lose the memory size. Secondly if I make a page size very small here it is found that the words in this page handling is very high and so that this mechanism become inefficient. Then this one more drawback is coming here. Suppose you are having a process divided into different pages. And suppose the CPU finishes a process on first page and is going to find out the second page now. But suppose the page 2 is not available in the RAM. Then at that time the process is not completed or it is called as a segment. Now segmentation is very important here. And suppose if we keep users point of view into mind here. So it is found that it is beneficial to split the program into small pieces. And it is found that a program normally carries different types of requirements here. So I am listing some of the requirements here. So we have got a main program. Then we handle some procedures or some functions. We handle some objects. We handle variables locally and globally. We also handle stack. We also handle some data blocks here which are common to number of codes there. So from users point of perspective if we see that the process of chloride split into these different requirements here. I got stack. I got data. I got function. We find subroutines and we get symbol table set. If we handle all these blocks separately it is beneficial. So in segmentation as we know programs are stored in the secondary memory. So segmentation is a mechanism through which I am going to divide the secondary memory in different pieces here. We normally call them as as we seen in the previous diagram here. The different segments are having different sizes here. So that in the segmentation we are going to make partition of the secondary memory of different sizes here. Which mean that we are going to find out the different segments in secondary memory at different locations having different sizes there. Now when we bring this segment here for the processing in the main memory then you have to make sure that there should be continuous memory allocation for this segment into the main memory. Suppose if you don't find enough memory size in the main memory to accommodate this segment here. In that case it is not possible to transfer a segment from secondary memory back into the main memory. Process I am dividing that in five different segments here namely S1 to S5 and I am storing that segment in the hard disk here that is a secondary memory in this given way here. S5 is stored in the beginning the address is starting from this 1000 here then S2 is stored from 1300 here S4 is stored from 1600 and so on here. Now these process segments are stored at different locations. Now the numbers on this left hand side is normally called as a logical address because that is pointing to the secondary memory here. This also can be called as the base address here. So during segmentation we require the location of this segment here in the secondary memory. Now how to use this segment here? So when I want to use the segmentation here so we can name this segment here with the help of a logical address here. For example I want to suppose call a segment number 5. So we know that the segment 5 is starting from 1000 here and we know here also the segment number 2 is starting from 1300 which means that the segment 5 has a length of 300 here. So we can see here I can call the segment here by a logical address here that is a combination of the base address and the length of the segment here. So in the case of segment number 5 we get the base address 1000 here and the length is coming as 300 here. Now when you want to execute a process so we use a segment for that process definition here. So in the RAM we are going to find out different segments here. So operating system is going to manage one table is normally called as a segment table here which are having these kind of entries. It is having two columns here. In one column we store the base address of the segment here and the second column carries the length of the given segment here. Whereas we also are going to have one more column and we are going to store this block here or this segment in the RAM and we name these segments as either S1, S2, S3 and so on here. So in my example the S1 is stored from in the memory here that is in the RAM whose base address in the secondary memory is starting from 7700 and it is having the length of 300 here. Now actually how to make sure that the address because we know here whenever CP is generating the address for access of data here is in secondary memory and we have to bring that data from the secondary memory back into the main memory here. Now we know here logic address having two components that is base address and second we call this as an offset here. So for example CP want to read some instruction in suppose segment number one. So we have to confirm that I must first pointing to the the base address of the given segment S1 and after that the offset address should be such that it should be lying in the permissible range of the segment area here that is the offset address should not be more than the length of the given segment here. So this diagram is showing me that kind of mechanism that is whenever CP want to access some instruction here he generates logic address here. So first I will point out the base address that is in the secondary memory and we are going to have some offset here. Now we are going to compare this offset with the length of the given segment here. Suppose offset is less than the given length of segment then it is called to be a legal reading from the given main memory here. Suppose the offset is greater than the length of the segment here it is going to create the error it is normally called a trap. So we have to avoid this condition so when I get a trap so CP is prevented to read that location in the given segmentation here. Now in this segmentation the problems we find in the paging mechanism is not at all available in this one here. That is we know here we are not going to get the problems such as the page fault here because the page may not be there in memory sometimes here as we store this entire segment together so we never get such difficulties here. Then sequination makes a possible use of separate memory areas for stack code and data so it becomes modular. So because of this modularity of this handling here the object oriented programming is quite possible here and moreover the segmentation is providing me a protection here. Now again question come how we are going to provide protection with the help of this segmentation here. Now the example I am giving a simple example here so we get segment table as mentioned here we store two segments here the first column shows the base address here the second shows you the length here and currently CP generates some addresses that is called logical address here that is 110 and 2550. Suppose in this example the first digit in the LA suppose that indicates the page the segment number here that is in the first example LA is 110 means one indicates the segment number and remaining part 10 indicates the offset here in this example it is 2550 here so the two number indicates the segment number and 550 is going to indicate the offset here. So we know here in the segment here CP generates the address suppose 110 here so we are going to first look after the segment one and we are going to compare the offset and the length of segment here. Like this example the offset is 10 and the length of segment is 14 here so 14 is more than 10 so it is a legal reading here so CP can read a location that is sum of this base address plus the offset here that becomes 2310 in second example LA is 2550 here that is we are going to access the second segment here and the offset is 550 which is more than the length of segment here which means that you are trying to read a location which is not a part of current segment here so at that moment the system create one alert here that is called the track and we prevent the CPU to read that location which is not a part of current segment here in this way we are going to provide segment protections in the given segmentation there friends I use these books to provide this information to you thank you thank you very much