[00:00:00] Why can a processor execute billions of operations per second yet still spend time waiting? [00:00:18] If we try to understand this question, then we can understand that computation is only [00:00:27] one part of performance. Operants and instructions must arise from a memory system. The session [00:00:39] connects two mechanisms. Caches exploit locality to reduce average access time, while memory [00:00:51] gives each process a protected, flexible address space. For example, if we are opening a large [00:01:01] spreadsheet, Excel sheet. Frequently used instructions and data may remain cached, while the process [00:01:12] sees virtual addresses rather than the raw RAM locations. Now, why does the memory hierarchy [00:01:26] exists? Basically, the speed, capacity, cost. That is the trade-off. Registers are the fastest. [00:01:40] CPU registers are the fastest, but the smallest. RAM, for example, DRAM is larger, but slower. [00:01:54] The hard disks, whether it is HDD or SSD, it also adds persistency. RAM do not have persistency. [00:02:04] If you reboot the system or if you close the program, the data that is available in the memory [00:02:11] will be erased. So hard disks adds another property, that is storage. It adds another property called [00:02:20] persistence. And from the speed perspective, storage is comparatively slower than any of these in this storage mechanism. [00:02:32] So why not build the entire memory system from RAM? Now, if you are having a laptop, you can have terabytes of hard disk [00:02:46] disk in your laptop, but only tens of gigabytes of RAM, because the technologies serve different roles. [00:02:56] You may have 32 GB RAM, but you may have a terabyte of hard disk. So here if the volume is high, here the volume is low, [00:03:08] but here the speed is high, here the speed is slower. I won't say low, but it is slower compared to the memory. [00:03:19] So these two has two different roles within the system. Now, if you look at the overall hierarchy, [00:03:32] the registers, cache within cache, L1 is the lowest in terms of the capacity, but fastest in terms of the speed. [00:03:47] And L3 has comparatively higher capacity, but slower in speed. Then comes memory. [00:03:56] Memory is higher than cache in terms of the capacity. But again, in terms of the speed, [00:04:03] it is slower than cache. And memory, the next stage is the hard disk, which is higher in terms of [00:04:13] the volume, the capacity that it has, it can store, and also adds the quality of persistency. [00:04:22] So higher the hierarchy, lower the latency, smaller the capacity and higher cost per bit. [00:04:30] How the cost is compared? If you have lower volume and paying higher money, then the rupee that you are [00:04:41] spending to store one byte is comparatively higher in L1 cache compared to the hard disk. So lower in the hierarchy, [00:04:52] latency is high. The time it takes to reach the processing, that is high. Capacity is larger. [00:05:01] The cost is also comparatively lower per bit. Okay, cool. So now, locality. It is a tendency in [00:05:13] real workloads. Not a promise. It is statistical. Now, temporal. Temporal is nothing but temporary. [00:05:24] Temporal and spatial locality. How are they different? Temporal will reuse the same location [00:05:37] pretty soon compared to the spatial locality where access nearby locations very soon. That is the [00:05:45] difference between temporal and spatial locality. And finally, the cache feature block, not just one byte. [00:05:56] It is not going to retrieve byte by byte. It will retrieve a block which we refer as a cache line [00:06:05] to exploit spatial locality advantage. Because spatial locality gives faster access to the nearby locations. [00:06:13] So if you are taking advantage of the spatial locality, then we can retrieve the cache line [00:06:23] at a faster pace. So now, for example, if a program repeatedly calls the same function [00:06:33] function and it accesses the same array again and again, the function, the data and the nearby array elements [00:06:45] are likely to be reused. If it is likely to be reused, then definitely what we will be expecting is, [00:06:58] access is faster so that the process is also faster. So the reuse capacity, if you are going to use a temporal, [00:07:10] it will use the same location at a faster pace. So either way, if it is a huge data line by line, [00:07:19] then spatial locality is going to help you, then spatial locality is going to help you. If it is like, [00:07:24] for example, one variable is getting repeatedly accessed by the program, it could be a global variable [00:07:33] being accessed by different functions. So that variable will be stored in the temporal locality [00:07:42] until the program completion is executed, completed. It will reuse the same location. [00:07:49] So temporal locality for the global variable, but in case if it is an array that is getting stored, [00:07:58] it will get stored in the spatial locality because you can access it faster and you can access it [00:08:05] it as a total cache line. So now in case, if you are going to, if you are going to write a loop [00:08:18] for i in range of n, we say values of i. So we are increasing the i one by one. So the ranges [00:08:32] we have, we are telling total plus. Let us assume that this for i loop, we are doing it 0, 1, 2, 3, 4. [00:08:42] So range of 0, value of i added to the total. So what is getting reused again and again here? [00:08:53] The total is getting repeatedly read and updated, not just only reading. It also need to be written [00:09:02] because we are adding, using this plus, we are adding the total. So whatever data available for the variable [00:09:10] total, until this for loop ends with n, this total has to be accessed again and again, updated again and again. [00:09:20] The values, for example, 0, 1, 2, 3, 4. If n is equal to 5, 0, 1, 2, 3, 4. [00:09:28] Now then, value of 0, value of 1, value of 2 for every increase in the loop. [00:09:42] Here the values are changing, but total remains [00:09:46] the same. When I say the same, the variable total remains the same. The data is getting updated. [00:09:52] That is the value is getting updated for the total. So the variable total is read and updated [00:10:00] successfully again and again. What happens if a program repeatedly accesses a small lookup table? [00:10:09] After initial misses, after initial misses, later accesses may hit. It may have initial miss, [00:10:19] but it will hit again and again successfully. So now, even the mentioned loop counter frequently [00:10:32] accesses can be accessed object fields and not hot functions. So the temporal locality also appears in [00:10:42] frequently called functions and hot data structures. In this example, it is the total, [00:10:50] which is getting accessed again and again, repeatedly, and also [00:10:55] written, written when it has to be updated is 0 plus 1, 1. So initially, the value of total is 0, [00:11:04] now it has to be 1. So it has to be overwritten with the value. So this has to be available for this [00:11:15] loop all the time, otherwise the function is going to fail. So this is where exactly the temporal [00:11:22] locality comes in handy to store the repeatedly used objects. And as we saw before, it can be accessed [00:11:33] fastly because it is going to use the same location. And since it is pretty soon, obviously it will use the [00:11:41] same location and update the data. So when it has to access the total again, it knows where exactly to [00:11:47] access and the value only it has to read before it goes and adds 1 is the current total value. Now we have [00:11:55] increased the value of i. So values of 1, which is like 2. So 1 plus 2 is 3. Now this total has to be [00:12:05] updated with 3 instead of 1. So the temporal locality will store all the repeatedly used objects [00:12:14] and it ensures that it is available by making sure that it stores in the same location. [00:12:23] Now spatial locality. In the same example, if you look at it, values of 0, values of 1, values of 2, [00:12:34] values of 3. The second part of the loop is basically to fetch the value and add it to the total. [00:12:39] So here the value in values of 0, that is the first element in the array. There is the second element [00:12:47] in the array, third element and the fourth element and it goes on. So the values are also different. [00:12:57] The variable also is different. The variable is the, here in this case, it is the first element of the [00:13:03] array called values. So like this, values might have 10 elements in the array or 100 elements in the array. [00:13:12] So values is only one variable, but it is of type array, but it can store multiple values. So now [00:13:23] if I have access to values of 0, physically if you look at it where it should be, it should be in a [00:13:29] memory. Now from the memory, it has to go to the processor for it to get processed so that the output [00:13:39] can be written back into the memory. Unless the program writes the data from memory to a disk, [00:13:47] that operation will not happen. It depends on the program. In case if you are accessing the values, [00:13:54] calculating the total and displaying the total on the screen and you are coming out. [00:14:00] So now you are not writing anything in the hard disk. So where are these values are stored? [00:14:08] It is stored in the memory, but this array will be storing in a special locality. Now, [00:14:24] you can take a whole lot of the data, you've heard the data. You can read the data. [00:14:37] Now, [00:14:38] you know, [00:14:40] it's the same thing as I'm supposed to do, like you said. [00:14:42] So I'm going to, you know, [00:14:46] it's the same thing as a user. [00:14:49] It's the same thing. [00:14:50] Thank you. [00:18:50] Hi, guys. [00:18:52] Sorry, I got disconnected. [00:18:55] I had to choose another internet connection. [00:19:03] It took a couple of minutes. [00:19:04] Can I know if you confirm, am I audible, am I clear? [00:19:13] Hey, guys, thank you so much. [00:19:16] I'm really sorry for that. [00:19:19] Just a minute. [00:19:20] Let me go ahead and share my screen. [00:19:22] Can I know if you confirm, is my screen visible? [00:19:34] Can I know if you confirm, is my screen visible? [00:19:42] Okay, cool. [00:19:55] Okay, thank you so much. [00:19:57] Okay, let us continue. [00:20:00] Sorry for the interruption. [00:20:01] Sorry for the interruption. [00:20:01] Okay, where will be? [00:20:04] We were in special rule. [00:20:08] We are in special locality. [00:20:11] Okay. [00:20:12] So now, we are discussing about if in this for loop, we have a range, we have total, we have values. [00:20:19] Range of n, value to be stored in the total. [00:20:24] And the array will be stored in the array called values. [00:20:27] So total, we saw, it has to be repeatedly accessed for both read and write. [00:20:34] So it will be stored in the temporal locality. [00:20:37] And values is an array. [00:20:39] And that array will have multiple values within that single array. [00:20:43] And each array has to be stored. [00:20:46] Each, sorry, each element in the array has to be stored. [00:20:49] So the adjacent elements often occupy adjacent byte. [00:20:52] It has to be stored in the memory. [00:20:54] In that case, where will it locate? [00:20:59] It will locate in the special memory. [00:21:03] The reason is, it will give you an access. [00:21:07] It will store it in the next location that is accessible faster. [00:21:11] And also, if you want to read the entire array and put it back to the processing, [00:21:21] then it can pick it up as a cache line and adjacent locations it will be stored. [00:21:29] And it is faster and easy access. [00:21:32] So one cache line can supply several future loads. [00:21:36] In this case, suppose if the array has 254 values, then at least if not the whole array, [00:21:44] it will supply for the future, several future loads immediately. [00:21:49] So a row-wise traversal of Python, numpy array, is usually more cache friendly than jumping randomly access memory. [00:22:03] Link list is another example which may show weaker spatial locality than array traversal. [00:22:11] But still, when you look at the values that it needs to be supplied for that for loop, [00:22:16] the moment the first cycle is completed in the loop, automatically value 1 will be supplied. [00:22:23] Once it is completed, value 2 will go. [00:22:25] Immediately, our processing is not getting hit. [00:22:29] So our program performance is also not getting hit. [00:22:35] So if it is an array, then probably the spatial locality, that is what is going to help us to process with a very good response back to the user. [00:22:47] Now, we know the cache is a small store of recently used memory blocks. [00:22:54] Okay. [00:22:55] Now, there is a concept of hit and miss. [00:23:01] What is this hit and miss? [00:23:03] The requested block is already in the cache. [00:23:06] That is hit. [00:23:08] That means hit means the requested block is present at the relevant cache level. [00:23:15] The main difference is that temporal will use the same location in the memory or cache. [00:23:32] Temporal is a type, spatial is a type. [00:23:35] Temporal will use the same location so that immediately reused and recently going to be used will be accessed faster. [00:23:47] And that is what we saw is the total in which it has to be in the entire for loop. [00:23:54] The total will be accessed in every loop. [00:23:58] In case of values, the next loop is going to access the next element in the array. [00:24:04] So, that is the difference between temporal and spatial. [00:24:09] Now, a hit means the requested block is present at the relevant cache level. [00:24:15] Miss means that level must obtain the block from a lower level. [00:24:20] It is not that the program will not get the value or get the variable. [00:24:29] This means not in the actual sense, okay, it is missed, not happened. [00:24:35] Not in that sense. [00:24:38] Here, the hit and miss means it is referring to whether the requested block is available in the cache or not. [00:24:48] If it is not available in the cache, then it will go to the lower level. [00:24:52] And the lower level must supply it. [00:24:55] It will supply it. [00:24:57] So, the definition of cache hit and cache misses basically determines the level of the performance of the program. [00:25:06] It does not mean the program will fail. [00:25:09] It does not mean the operation will fail. [00:25:11] It is just that the data needs to be supplied by the next lower level. [00:25:17] What is the next lower level? [00:25:19] If it is not in L1, L2 will supply. [00:25:22] If it is not in L2, L3 will supply. [00:25:25] If it is not in L3, then SRAM will supply or DERA will supply. [00:25:32] If it is not there in RAM also, then it has to fetch it from the hard disk. [00:25:38] Now, the time taken to get the value. [00:25:42] If it has got the value from the requested block, which was already present in the cache, you hit. [00:25:51] Otherwise, you miss. [00:25:52] It does not mean that you will not get it. [00:25:54] You will get it. [00:25:55] But it will take some time for you to fetch the data that you are looking for. [00:26:00] That is miss. [00:26:03] Now, a cache line is nothing but the transfer for an allocation unit. [00:26:11] That is what the cache line is. [00:26:13] Not necessarily the size of the requested variable. [00:26:17] Cache line is a fixed aligned block transferred between memory levels. [00:26:26] When I say memory level, it is right from L1, L2, L3 and RAM. [00:26:32] All are considered as memory levels. [00:26:35] So, cache line is of a fixed size. [00:26:38] Suppose if you have three elements in your array. [00:26:42] And if all the three elements come within the fixed size, then the whole array is a cache line. [00:26:51] You have 30 elements in your array. [00:26:55] But only 10 elements are fitting the fixed size of the cache line. [00:27:02] 10 elements will be taken. [00:27:06] When will the next 10 comes? [00:27:09] Basically, the first 10 is completed for processing. [00:27:13] Then when it is looking for the 11th element, at that time, the next 10 elements will be loaded. [00:27:21] So, why it will load the entire 10 elements? [00:27:26] Because that's the cached line size. [00:27:30] It can also happen. [00:27:31] You have 30 elements in your cache. [00:27:33] Sorry, in your array. [00:27:35] And in the first cache line, 10 elements has fit. [00:27:40] So, it will get loaded. [00:27:42] Now, when the 11th element is being accessed, then the entire next cache line will get loaded. [00:27:50] It may be so happen that element 11 to element 19 will get loaded instead of 11 to 20. [00:27:58] It does not mean that, okay, in the first cycle, we got 10 elements of the array. [00:28:04] In the next cycle also, we will get 10 elements. [00:28:07] It is not so. [00:28:08] It depends on the size of the elements. [00:28:11] Even if it is numerical, 0, 1, 2, 3, up to 10. [00:28:17] Then 11, 12, 13, 14, 15, up to 20. [00:28:22] Then it may fit. [00:28:24] Because the representation in terms of bits and also size being fixed, the content is not having a variable length. [00:28:37] In case if your array is not numerical, but it is a string, it contains the sentence, Taj Mahal is a beautiful monument located at Agra. [00:28:53] If these sentences bifurcated into elements and stored in an array, obviously located is of a different size. [00:29:03] Agra only four characters. [00:29:06] Is is only two characters. [00:29:09] Mahal is five characters. [00:29:11] So now you can see each and every value is of different size. [00:29:18] So when you are loading this, Taj Mahal is a beautiful monument located at Agra into your array. [00:29:26] And suppose if it is able to fit only Taj Mahal is a, then greatest monument location, Agra, everything will come as part of the second cash line. [00:29:44] In the size of the cash line is not going to change. [00:29:47] It is fixed. [00:29:48] So initially it could be Taj Mahal is air is something that would have come in the first cycle. [00:29:56] And the second cycle might have great monument. [00:29:59] If you are trying to add something else, probably it would exceed the size of the cash line. [00:30:10] The size of the cash line is fixed irrespective of what you are getting loaded and what type of data you are getting loaded. [00:30:17] So in that case, probably great monument could be taken up and pushed to the lower levels and made it available for the program. [00:30:32] Because if it is available in the lower level, it is easy to fetch compared to the higher level, which is going to take some time to fetch. [00:30:43] So what is the major concern here is the time factor. [00:30:48] Nothing to do with the content. [00:30:50] It has nothing to do with the application. [00:30:52] It has nothing to do with the end user expectation. [00:30:55] It all aligns. [00:30:56] But what differs is the size. [00:31:03] So Sundar, if that is the case, then we should have most of the things in memory. [00:31:11] Because it also has ability to store. [00:31:15] It also functions in the way that it needs to function. [00:31:20] But still, you will see somebody who is interacting with the customer will continue to do and will love to continue to do. [00:31:29] Similarly here, any data analyst or any data engineers who are working on these type of data will also become part of them to understand, analyze, estimate the objectives. [00:31:48] So we have two options. [00:31:51] Within that only we have to choose. [00:31:53] But again, whatever we are choosing, it is going to go from the lowest form of latency. [00:31:59] Basically, it could be A, B, C, D or E with the same consideration. [00:32:11] So the objective is very clear. [00:32:16] The objective is to provide uninterrupted connectivity. [00:32:22] Okay, cool. [00:32:25] So now if this is the case, Sundar, then what will happen to, I think that we will not be able to record. [00:32:36] We may be able to refer, but we may not be able to record. [00:32:41] For example, if it is special. [00:32:44] Then we know that, yes, it will be available, because we only have tried it. [00:32:50] So we are good. [00:32:51] But what will happen to this individual who has come to work, probably for the last two, three days. [00:33:01] So now, the question that comes to our mind is, what next? [00:33:08] That I understand different levels of memory. [00:33:11] That includes L1, L2, L3 cache as well. [00:33:14] We are trying to connect the dots in terms of the memory. [00:33:18] We should consider the cache also, because it is a cache, but it's a cache memory. [00:33:24] We will be, or we can probably use that. [00:33:31] Okay. [00:33:34] Yes, Sundar, we tried it, but we didn't get the desired result. [00:33:41] What is it we are expecting after this? [00:33:44] Okay, cool. [00:33:55] Now, we have seen how L1, L2, L3, and memory, basically as DRAM, and also the hard disk compared [00:34:06] it within terms of other data transfers, and where exactly it resides, for what purpose, [00:34:11] and how long. [00:34:13] How long is something that we can define, if it is not defined, it is infinite. [00:34:17] So it can be present in the system forever, if we do not action. [00:34:22] So what next? [00:34:25] And that is what we are going to understand. [00:34:31] Now, fully, we are on the same page. [00:34:37] As far as cache line is concerned, understanding about cache line, understanding about cache [00:34:42] miss, and understanding about cache hit. [00:34:46] So I would like to pause here and check if there are any queries, questions, from anyone [00:34:52] about what we have seen until now, let me stop sharing and share it again. [00:34:57] If spatial locality improves cache performance by loading nearby memory locations together, [00:35:04] what happens when a program accesses memory locations randomly? [00:35:09] Okay. [00:35:10] Does the CPU still load the entire cache line? [00:35:16] Okay. [00:35:17] First of all, why it has to access randomly? [00:35:23] If you are going to make the program to access the memory random, then obviously you are not [00:35:30] storing or you are not looking for an error. [00:35:33] You might be looking for a single value. [00:35:36] If it is repeated, then it will be in the locality, obviously it will have faster. [00:35:43] So, yes, I know there is a concept that you can access the locations remotely and as well [00:35:52] as randomly, but it does not change the performance of the program. [00:35:59] Will CPU cache still load the entire cache line? [00:36:06] The answer is yes. [00:36:08] Whenever a cache line is getting loaded, it will load fully. [00:36:12] If it is not available, then it is a miss. [00:36:15] That means we need to get that rest part or the new one from the lower level cache. [00:36:22] If it is not available in lower level cache, it has to obviously get it from the memory. [00:36:29] If not in memory, we have to get it from. [00:36:31] So this is how we approach. [00:36:34] But as far as the design is concerned, you will definitely hit it back at L3 or something. [00:36:44] It is very rare that it goes beyond that. [00:36:47] It is not that it is going to tell us something that we do not know. [00:36:53] It is going to indicate us what we already know. [00:37:00] So this way, definitely the behavior of the CPU is going to be properly in terms of the cache line, not randomly. [00:37:16] It won't do random. [00:37:17] In case of cache, it will know where it is stored. [00:37:20] It will hit the first and then it will fetch the overall slide. [00:37:27] That is how it works. [00:37:29] If it is not able to identify the first element value or the first element of the value in that cycle, then it will put words to the next line. [00:37:43] Explain what it is going to say. [00:37:45] It is again going to say the starting and the ending of it. [00:37:48] Then what we will achieve. [00:37:51] That's normally the message that comes. [00:37:54] But our focus should be more on the practice that we do rather than just understanding the concept. [00:38:08] I would like to pass here and check if there are any queries, questions before we move ahead. [00:38:21] Okay, cool. [00:38:23] Let me share my window again. [00:38:27] Hope my window is visible. [00:38:29] So we have seen cache hit, cache miss and cache line. [00:38:34] Now the cache address anatomy. [00:38:38] So let us take an example of three fields. [00:38:47] One is add, second is index and the third is type. [00:38:54] This is for a set associative cache. [00:38:58] The addresses are generally divided into fields. [00:39:02] The field is tag, which is basically which block. [00:39:07] Index, basically which set. [00:39:11] And basically the byte offset. [00:39:21] Byte offset is nothing but which byte it has to start and which byte it has to end. [00:39:28] Even within the byte, it needs to know which byte. [00:39:32] So the offset selects a byte within a line, sets index and selects a set. [00:39:46] Tag distinguishes the memory block. [00:39:50] Tag is nothing but the memory block. [00:39:53] Now, suppose let us see the line size is 16 bytes. [00:40:00] So addresses 0 to 15 is what we will use. [00:40:05] Which are in the block 0. [00:40:08] Block 0 is going to have 0 to 15. [00:40:12] And block 1 will have 16 to 31. [00:40:16] Block 2 will have 32 to 45. [00:40:24] So this is how the blocks are going to be made available. [00:40:28] The number of sets is 2. [00:40:30] Let us restrict ourselves to 2 sets. [00:40:33] That means 2 blocks. [00:40:35] And it will occupy right from 0 to 16 is 1. [00:40:45] And 17 to 36 is another. [00:40:50] And this is how we look at the cache address. [00:40:56] And this is what exactly the anatomy speaks about. [00:41:03] So now, the next thing is, where can a block go? [00:41:10] Okay, block 0, block 1. [00:41:12] Block 0 is used. [00:41:13] Where can it go? [00:41:15] Block 1 is currently being used. [00:41:18] So where is it? [00:41:19] The next block, block 2 is going to come. [00:41:22] It will come from the cache or wire memory or even database. [00:41:28] But, [00:41:33] how? [00:41:34] And the process is basically called as mapping. [00:41:43] Where can a block go? [00:41:46] Which area it will get stored? [00:41:50] So there are actually three common placement strategies. [00:42:00] And basically you can think this as three different designs. [00:42:05] So directly mapped. [00:42:09] Exactly one possible cache line. [00:42:13] Very simple. [00:42:14] But conflict misses can occur. [00:42:18] Miss again, I just wanted to reiterate. [00:42:22] Miss doesn't mean a negative that we have missed it and we will not get it further. [00:42:28] Miss means only that it is not available in the highest cache, which is L1. [00:42:34] So Sundar, if we assume that we have two different arrays, both the arrays are getting split because of the size of the block into two. [00:42:52] But within the two, it will supply all the values of the array. [00:42:57] 0 to 29. [00:43:02] So now 0 to 12 is one break. [00:43:07] And another is another break. [00:43:10] So this break actually leads to the different blocks. [00:43:14] And each block has its own address and it will have its own content. [00:43:22] And that is how it is going to store and as well as get searched for the values of this program. [00:43:31] Okay. [00:43:33] Now, let us try to calculate. [00:43:39] Let us try to calculate a number of sets. [00:43:43] Basically, 64 divided by, in the denominator, we have 16 into 2. [00:43:49] 16 into 2 is nothing but 32. [00:43:52] So 64 by 32 is equal to 2. [00:43:55] So basically, two sets. [00:43:58] When you say two sets, it is address 0, block 0, set 0. [00:44:06] So like that, you will have address 0, block 0 and set 1. [00:44:14] Then it will increase the blocks if the sets are over. [00:44:18] And if the block is also getting over, then it will release the address space. [00:44:25] So now addresses 0 and 32 compete for the same set. [00:44:30] But can co-exist in two ways. [00:44:32] One is that address 64, which is block 4, is set to 0. [00:44:38] So now it has to compete again and may cause an eviction. [00:44:43] So now if something is Cushantyana for eviction, [00:44:48] then definitely it is [00:44:55] So now we have understood how the mapping also works. [00:45:08] So basically our focus is now on memory, memory levels, L1 cache up to RAM. [00:45:16] Storage is basically adds up consistency and persistency. [00:45:21] And the other side CPU registers are basically the one which is going to use the values [00:45:26] that is going to be part of the processing at that point of time. [00:45:34] So that leads to blocks and sets. [00:45:40] And sets, if it gets over, then the block gets increased. [00:45:44] And if the blocks are getting over, then [00:45:51] So any queries, any questions until now? [00:45:56] Are we good? [00:45:58] Are we on the same page? [00:46:00] Okay. [00:46:01] Let me stop sharing. [00:46:06] The slides of previous classes I have uploaded. [00:46:11] Are you not able to see it in the model? [00:46:13] Are you not able to see it in the model? [00:46:15] I think I have uploaded until like RISC. [00:46:18] Can one of you confirm? [00:46:21] Are you not able to see the RISC document? [00:46:25] R-I-C-E. [00:46:26] Sorry. [00:46:27] R-I-S-E. [00:46:28] Sorry. [00:46:29] R-I-S-E. [00:46:31] Until then I have already uploaded. [00:46:33] If you are not able to see them, please let me know. [00:46:36] Why is memory address divided into tag, index, and offset [00:46:45] instead of using the complete? [00:46:47] Okay. [00:46:48] I can see that in and the RIS. [00:46:53] Labs. [00:46:54] That is the same month. [00:46:59] FCS lab one, two, three, four. [00:47:07] FCS theory one, two, three, four. [00:47:10] No RIS. [00:47:11] Let me also check. [00:47:12] And if it is not uploaded, definitely I will upload. [00:47:14] Probably I might have uploaded it to the right place. [00:47:18] I'll do that. [00:47:19] I'll check if it is in the right place or not. [00:47:21] If not, I'll just move it. [00:47:23] Not an issue. [00:47:25] Any other curious questions before we move ahead, guys? [00:47:28] Okay. [00:47:29] Cool. [00:47:30] Let me just share my screen again. [00:47:35] So now we have seen how the mapping works. [00:47:43] The next is when a set is full, which line should leave? [00:47:49] So basically the eviction, when the set is full, that's where this replacement policy [00:47:56] comes and plays its role. [00:47:59] It only matters when the target set is full. [00:48:02] Until then, the replacement policy does not even kick off. [00:48:08] LRU evicts the least recently used line. [00:48:17] That is the first one. [00:48:19] If you have a line that is available in the cache, which is not being used in the last 24 hours, for example, that will be evicted from the LRU. [00:48:33] Both fit because there are two ways of doing it. [00:48:39] So address 64 gives block 4, also set 0. [00:48:45] Now three competing blocks cannot all remain. [00:48:50] So this makes actually conflict replacement tangible. [00:48:59] So FIFO evicts the oldest resident line. [00:49:05] Okay. [00:49:06] Now, you have 10 cache lines. [00:49:10] When we see the oldest, the one which has arrived, and been available in that. [00:49:16] Per continuous period of time where others is not able to. [00:49:20] This is not able to. [00:49:21] That's it. [00:49:34] Okay. [00:49:35] Just give me a minute. [00:49:50] Okay. [00:49:51] So now let us look at the replacement policy, LRUs, we have seen, which will remove the least recently used. [00:50:05] Suppose if you have 10 lines available, then probably the eighth one, which is not being used for some time now. [00:50:13] So it will remove the eighth, keep all the lines in order. [00:50:20] So that's exactly it. [00:50:23] Now, someone was asking, so what will happen if it is random? [00:50:30] So it is basically in such a manner that it is just a hardware implementation and hardware resource utilization. [00:50:45] So can we do? [00:50:47] Yes, we can. [00:50:48] But it will lead to more. [00:50:59] More processing and more storage as well. [00:51:03] Now, when there is an implementation specific policy, that do not assume exact LRU. [00:51:19] Then in that case, the CPUs will act on its behalf. [00:51:25] Does it happen very frequently? [00:51:26] If it happens very frequently, then the performance is lower. [00:51:30] But if we identify and rectify that as soon as possible, then it will not impact. [00:51:40] So impact is not there, but it doesn't mean that it can be slight enough. [00:51:45] It's always better if we check the end opinion. [00:51:53] Okay. [00:51:55] Cool. [00:51:56] Now, we understand how the replacement policy also is defined and work to when the memory [00:52:08] is full. [00:52:09] There is no place to, okay, understand. [00:52:23] Okay. [00:52:24] So any other queries, questions before we move ahead? [00:52:28] Let's turn to the next part of this lecture. [00:52:33] So that any queries, any questions from anyone? [00:52:38] Okay. [00:52:40] Cool. [00:52:41] So we have seen the replacement also, how it happens and what policy it follows. [00:52:53] But if you want to keep cache and lower memory consistent. [00:52:58] Now, we understand how the lower memory plays the role. [00:53:03] What is the type and how fast it is, how it impacts the speed and performance. [00:53:08] Now, if you want to keep the cache and the lower memory consistent. [00:53:13] If it is inconsistent, obviously you'll get the data, but it is going to put some stress [00:53:19] on the system and as well as utilization in terms of the resources. [00:53:24] So what can we do? [00:53:29] So we can have the updates lower memory on every store. [00:53:39] And we can use write back. [00:53:42] What is write back? [00:53:45] Write back is nothing but a mark. [00:53:48] It's nothing else. [00:53:49] It's just a mark. [00:53:51] And it will mark what? [00:53:53] It will mark the... [00:53:59] It will mark the line to make available. [00:54:10] So write back actually marks the cache line dirty. [00:54:15] Place the lower level right until eviction or even flush. [00:54:22] Now, you also need to understand traffic versus complexity or consistency. [00:54:33] So, one practical analogy could be, you're updating a shared ledger immediately versus patching [00:54:42] changes and recording, recancelizing it later. [00:54:45] You have two different options. [00:54:47] While the transaction is happening, let it go ahead and update there also. [00:54:51] So, we can basically plan ourselves and then keep it fit. [00:55:06] So, that is what the write back does. [00:55:11] And write through, what is write through? [00:55:16] Write through is nothing but updating the cache and lower memory on each write. [00:55:20] For example of the for loop, where does the write happens? [00:55:25] It happens to the variable called total. [00:55:27] Arrays are getting retrieved. [00:55:29] So, we have understood the write through, we have understood the write back. [00:55:36] And we also have something called write allocate. [00:55:43] All these are related to the write operations and update. [00:55:45] Best example is the total in our for loop. [00:55:49] It commonly allocates or fetches a line on a write miss. [00:55:56] So, that means we are allocating, write allocate, commonly fetches a line on the write miss. [00:56:05] When you are going to write the element. [00:56:06] When you are going to write the element, you are going to update the element in your row. [00:56:12] And obviously, it needs to accept the test to be made available. [00:56:17] So, that way, like it is not going to be very nice. [00:56:21] But can happen in a day or two as well. [00:56:51] So, now, let us also look at the cache miss. [00:57:10] It actually helps us to diagnose the performance. [00:57:14] It's not about only counting the misses. [00:57:18] If you are just going to merely count the misses and not look beyond that. [00:57:25] Then, we will not be able to identify or diagnose the back to the performance. [00:57:32] So, first access to a block that is compulsory. [00:57:39] And the definition of a compulsory is as first ever access. [00:57:49] That means it is not available in the cache. [00:57:51] If you are going to available. [00:57:53] If you are going to access the available, then it is fine. [00:57:58] But, when the capacity of the working set is too large and also conflicting. [00:58:07] Can I have more than one as a value compared to any other offerings? [00:58:14] That would not be. [00:58:15] That would not be. [00:58:17] So, you really need to put across something that what you need to put across. [00:58:24] Then, you need to face them against the. [00:58:39] Okay. [00:58:40] Anything else from anyone before we move ahead? [00:58:43] Cash misses. [00:58:44] It's very useful. [00:58:45] Especially, first block. [00:58:48] First access to the block is compulsory. [00:58:50] The working set does not fit in the cache. [00:58:53] In that case, we have more than what a cache line can hold. [00:58:59] And there could be conflicts. [00:59:02] Blocks compete for the same set, even when other sets have room. [00:59:08] There are room. [00:59:09] But, if it is a competition of the same set, then how are we? [00:59:16] It's a conflict. [00:59:17] Two things trying to get bordered into a single thing. [00:59:22] So, that means, when you are trying to retrieve, whether it is the first element or the second element that is stored in that particular memory address, [00:59:31] just from there only the data will be accessed. [00:59:34] So, that way, when there is a competition for the same location for two different sets of variables, then we call it as a conflict. [00:59:48] Not just, not only in terms of the storage, but in terms of other fields as well. [00:59:55] This clarity we should. [01:00:03] So now, cache misses. [01:00:07] It's basically a useful classification that leads to identifying the gaps. [01:00:14] Let me, let me. [01:00:32] Okay, cool. [01:00:34] So, hopefully I think we are good with the understanding of the cache miss as well. [01:00:40] Let me stop sharing. [01:00:43] So, what we have seen is basically why memory hierarchy exists. [01:00:51] The reason we understood. [01:00:53] What is the memory hierarchy and how it is laid down? [01:00:58] Right from registers to persistent storage. [01:01:03] We also understood the locality. [01:01:06] There are two types. [01:01:07] One is temporal and another one is spatial locality. [01:01:12] Temporal will store repeated values or repeated variable. [01:01:28] So, I understand that. [01:01:29] Ignore assignment one. [01:01:31] I think I will delete it. [01:01:34] Okay, coming back. [01:01:37] So, we understood the difference between the temporal and the spatial locality. [01:01:41] We also understood the concept of hit, miss and line for the cache. [01:01:47] And what is the anatomy of the cache address? [01:01:50] And what is the role of the mapping and the replacement policy? [01:01:55] And if you want to retain how the write-through and write-back helps us to retain the value in the same cache itself. [01:02:04] And where exactly the cache misses helps us as a useful classification. [01:02:13] And the checkpoint. [01:02:15] Checkpoint. [01:02:16] Basically, array work, spatial locality, repeated accumulator, temporal locality. [01:02:27] So, two blocks competing for one directly map the line. [01:02:32] Then it is a conflict or miss. [01:02:35] Write-back may reduce lower-level write when multiple writes to a line are combined. [01:02:45] Can I combine? [01:02:46] Yes, we can. [01:02:47] It's data as usual and we can definitely. [01:02:50] Now, the real traces can contain overlapping cases. [01:03:01] And this classification is diagnostic framework. [01:03:06] So, which category a cold was feeling belongs to? [01:03:13] I believe that we should be able to identify and understand. [01:03:19] What we have seen. [01:03:21] We will take a quick break of five minutes. [01:03:24] Once we are back, we will start about virtual memory. [01:03:29] Now you have memory, physical memory, SRAM, DRAM. [01:03:35] But we also have the concept of a virtual memory. [01:03:38] Like we have a virtual server, virtual memory. [01:03:41] How it works and what is the relationship between and correct memory. [01:03:47] So, any questions before we go after a break? [01:03:54] Are we good? [01:03:56] Yes, no, maybe. [01:04:00] Okay. [01:04:01] Where are the replacement policies used? [01:04:15] Okay. [01:04:16] Whenever it wants to reconcile, retain in the same location. [01:04:21] So, the write back policy, modify the data remains in the cache and RAM contains an ultra value. [01:04:28] Okay. [01:04:29] This, let me clarify. [01:04:32] The data will be stored in one of these. [01:04:37] The moment it is moved from memory, that is RAM, to a cache block, it will be evicted. [01:04:47] Unless your program writes back. [01:04:48] Unless your program writes back. [01:04:51] Unless your programming logic writes back over for a particular date. [01:05:01] Okay. [01:05:02] Cool. [01:05:03] Similarly, it's the same thing. [01:05:06] So, the write back policy will retain the data in the same location, irrespective of whether [01:05:12] it has to go or it has to wait. [01:05:15] If a doctor has told the theory, it definitely will be. [01:05:20] So, something like that, even in the write back policy, it actually confirms the availability [01:05:31] of the data in the similar location, spatial location, not at this space. [01:05:38] Anything that they have been offered is not available at this space. [01:05:50] Okay. [01:05:51] Cool. [01:05:52] So, let us take a quick five-minute break. [01:05:56] I just stopped sharing with this. [01:05:58] So, what is write-around? [01:06:03] We will start with that when we come back. [01:06:07] So, just for the convenience purpose, what I am going to do is, I am just going to run [01:06:16] a five-minute break. [01:06:17] So, that if you are going to see the recording later, you should be able to move the recording [01:06:23] for the next topic. [01:06:25] For that reason, I am just going to run a five-minute break. [01:06:37] Yes. [01:06:46] Thank You, guys. [01:06:47] Thank you. [01:06:48] Thank you, guys. [01:06:49] Thank you. [01:06:50] Please come back. [01:06:51] I have one extra minute. [01:06:52] Please come back soon. [01:07:16] Thank you. [01:22:16] So, [01:22:46] Okay. [01:23:16] Thank you. [01:26:16] So, [01:26:46] Thank you. [01:27:46] It is, [01:28:16] So, [01:28:46] Thank you. [01:33:17] So, [01:33:46] Thank you. [01:41:55] You, [01:41:57] Thank you, [01:42:08] on common 64-bit systems. [01:42:12] So, [01:42:15] now [01:42:18] can we understand [01:42:22] the address translation? [01:42:25] So basically, we know that a page table [01:42:28] stores virtual page mapping information. [01:42:33] So now the page size is 256. [01:42:36] Let us assume. [01:42:38] That is 256 GB. [01:42:42] Now virtual address [01:42:44] 270. [01:42:47] So, [01:42:49] VPN that is the offset [01:42:51] is [01:42:53] 270 divided by 256 which is [01:42:56] 14. [01:43:00] 276 minus 256 which is [01:43:04] 14. [01:43:06] So, if VPN 1 maps to frame 2, [01:43:11] then the physical address is equal to 2 into 1, 256 plus 14. [01:43:18] That is 526. [01:43:20] The often [01:43:24] does not change. [01:43:29] What does not change? [01:43:30] The offset. [01:43:32] And in case if you are going to compute a virtual [01:43:36] virtual [01:43:46] Okay. [01:43:48] So, [01:43:49] the address translation offset is 250 by 250, 270 minus 256. [01:43:53] offset is 250 by 250, 270 minus 256 in case if we take the example of 256 and 270 KB. [01:44:04] So, if VPN 1 maps to frame 2, [01:44:07] 2, [01:44:08] then the physical address is 2 into 256 plus 14, that is 526. [01:44:17] So, [01:44:19] stress that offset does not change. [01:44:23] Offset is not changing. [01:44:26] So, [01:44:29] basically, if you have virtual address 530, [01:44:33] and VPN is mapping to frame 2, [01:44:37] offset is 80. [01:44:39] How are you going to compute? [01:44:41] You can try with this formula. [01:44:43] with this formula, [01:44:44] it will, [01:44:46] the page size, [01:44:47] the frame number, [01:44:49] page size plus offset. [01:44:52] So, this is how the address is translated. [01:44:56] Once the address is translated, [01:44:58] then, [01:44:59] easy for us to look around and bring the data up, [01:45:03] information that is required. [01:45:08] Now, [01:45:10] page table [01:45:11] are nothing but memory addresses too. [01:45:16] So, [01:45:18] CPUs cache recent transactions [01:45:22] in a TLB. [01:45:24] A TLB hit returns the frame [01:45:28] very quickly [01:45:30] and a TLB miss [01:45:33] because a page table, [01:45:35] table block. [01:45:37] If the PTE is present, [01:45:38] then, [01:45:40] this is not a page fault. [01:45:44] This, [01:45:45] basically, [01:45:46] even if you are trying for your examinations [01:45:49] or something like that, [01:45:51] this is going to help you. [01:45:53] This understanding, [01:45:54] especially this topic, [01:45:56] a cache for translations, [01:45:57] well, [01:45:58] I have questions in case if you are appearing for any [01:46:02] certain patients. [01:46:04] So, [01:46:06] the best example is again, [01:46:08] repeatedly accessing pages [01:46:11] in a loop, [01:46:12] tends to reuse TLB. [01:46:14] the entries. [01:46:19] So, [01:46:20] that's what the role of the TLB. [01:46:22] And again, [01:46:24] TLB has its own hits and miss. [01:46:27] It does not mean [01:46:29] that we did not get the data [01:46:32] in case if we are telling TLB miss. [01:46:33] where it is basically the operating system performing the [01:46:38] required page table walk. [01:46:40] Then, [01:46:42] we cache the result. [01:46:46] Like how we have cache it, cache miss. [01:46:49] TLB also had hit and miss. [01:46:51] Miss, again, [01:46:53] is going to increase the time for processing [01:46:56] other than that it has no impact. [01:46:59] That is what the miss. [01:47:00] Miss means here we are missing the [01:47:01] latency. [01:47:06] Yet, TLB miss is not automatically a page fault. [01:47:10] A page fault means the mapping needs operating system [01:47:13] handling. [01:47:19] So, sometime, [01:47:21] your mission crashes, [01:47:22] or sometime your application crashes, [01:47:24] then you might see this type of page fault information [01:47:28] which will help us to diagnose what went wrong. [01:47:31] in this entire process. [01:47:35] So, [01:47:37] now, [01:47:40] TPU traps. [01:47:44] Where is it? [01:47:45] Where is it going to trap? [01:47:46] It is going to trap the operating system. [01:47:47] the operating system. [01:47:57] The operating system checks whether the access is valid or not. [01:48:01] If page is not resident, [01:48:04] operating system obtains or constructs it. [01:48:09] And retries the instruction. [01:48:13] So, instruction also is not going to fail. [01:48:16] It will retry. [01:48:18] So, what is the impact? [01:48:19] Impact is, again, the time it takes to process. [01:48:23] Demand paging means load on first use. [01:48:28] When the first time it is going to load for the first use, [01:48:33] then it is called as demand paging. [01:48:36] And a page fault can be resolved without this case. [01:48:39] any input-output is required. [01:48:43] Without that, we will be able to, [01:48:46] for example, [01:48:47] zero fill on demand [01:48:49] or even copy on write. [01:48:52] valid access [01:48:55] to terminate the process. [01:48:57] process. [01:48:59] So, [01:49:03] this is the demand paging and the page fault. [01:49:06] The demand paging is nothing but loading on first use. [01:49:13] It is the first time that it is going to access it and bring it up. [01:49:17] And it is going to refer it. [01:49:20] But since [01:49:22] it has not been tested, [01:49:25] we are going to, [01:49:27] our objective is basically to bring them up and see if our [01:49:30] outcome is [01:49:32] secured. [01:49:38] So, [01:49:40] this page fault [01:49:43] is basically a process fault [01:49:46] or could be a termination also. [01:49:47] How does it happen? [01:49:48] Invalid addresses that are being referred by the MMC. [01:50:04] Or it might be referring to any of the disallowed. [01:50:07] So, these are all the reasons that it can [01:50:10] bring out a page fault, [01:50:11] but the happening of the page fault is very, very rare. [01:50:14] unless there has been some conflict, [01:50:18] it led to the same operation within the system. [01:50:23] Until then, there is no overlap. [01:50:26] Even though if the page faults, [01:50:30] we don't need to think that [01:50:32] we need immediate attention. [01:50:34] we should not be thinking so. [01:50:40] So, [01:50:43] that is about the demand paging. [01:50:53] Now, [01:50:55] protection and permissions. [01:50:57] we are still in the page table. [01:51:01] It also needs a security boundary. [01:51:04] So, [01:51:06] how can we secure it? [01:51:09] We can secure it with [01:51:12] PTE permissions. [01:51:15] How is it going to help us? [01:51:20] It will help us in restricting [01:51:23] the access [01:51:25] with read, write and execute access. [01:51:29] A write to a read-only page [01:51:32] triggers a protection fault. [01:51:34] It is not a page fault. [01:51:36] It will lead to the protection fault. [01:51:38] Because we are protected and it is writing, [01:51:41] trying to write. [01:51:42] It is supposed to have [01:51:44] that as a read-only. [01:51:47] So now, [01:51:48] in case if you have the user [01:51:50] or kernel privilege levels, [01:51:53] generally we don't do [01:51:55] with any of the individual devices. [01:51:59] So now, [01:52:01] with [01:52:07] page fault, [01:52:08] demand damming, [01:52:09] protection, [01:52:10] with permissions. [01:52:12] Now, [01:52:13] with all these things, [01:52:15] we also have privilege levels [01:52:16] for [01:52:18] the user [01:52:19] or the kernel level. [01:52:21] Actually, [01:52:22] that actually adds in another dimension [01:52:24] of [01:52:26] access control. [01:52:28] So, [01:52:30] that actually adds in another dimension [01:52:32] of [01:52:35] access control. [01:52:38] So, [01:52:39] the shared pages [01:52:40] can only be mapped [01:52:42] read-only or [01:52:43] copy-on-write [01:52:44] to multiple processes. [01:52:46] Suppose, [01:52:47] if you are running [01:52:48] multiple functions [01:52:49] and there are like [01:52:51] end users [01:52:52] logging into the environment [01:52:55] and [01:52:56] the same process is being used [01:52:58] by multiple. [01:53:01] So, [01:53:03] there would probably be a conflict [01:53:04] conflict but [01:53:05] that conflict [01:53:06] could lead to a conflict [01:53:07] maze. [01:53:15] So, [01:53:16] with all these things, [01:53:18] we will try to put [01:53:20] the path [01:53:21] together. [01:53:23] Now, it's a sort of a complete [01:53:26] pipeline. [01:53:28] Now, [01:53:30] from instruction [01:53:32] to memory. [01:53:34] This is a complete pipeline. [01:53:37] Instruction generates [01:53:39] virtual address. [01:53:41] Now, [01:53:43] the TLB is checked. [01:53:45] if it is on [01:53:47] miss, [01:53:49] what will happen? [01:53:51] If TLB [01:53:53] is missing. [01:53:55] So, [01:53:57] page table is [01:53:59] consulted. [01:54:00] When [01:54:01] the [01:54:02] page table is [01:54:03] consulted. [01:54:04] When [01:54:05] the [01:54:06] page table is consulted? [01:54:07] When there is a miss. [01:54:10] So, [01:54:11] absent page [01:54:12] triggers page fault. [01:54:14] So, [01:54:15] you understand that? [01:54:17] So, [01:54:31] the present mapping [01:54:32] plus permissions [01:54:34] yields. [01:54:36] The PA data [01:54:38] is accessed. [01:54:39] accessed. [01:54:44] Especially [01:54:45] VMware. [01:54:47] Guest physical address [01:54:48] is then [01:54:50] led to second level [01:54:51] transition. [01:55:00] Oh. [01:55:02] CPU. [01:55:03] CPU nothing but [01:55:04] registers [01:55:05] L1, L2 [01:55:06] and L3 [01:55:07] to TLB. [01:55:09] From TLB [01:55:10] to page table. [01:55:12] Page table is [01:55:13] going to acquire [01:55:14] the frame of a RAM. [01:55:17] It will do the process. [01:55:19] After processing, [01:55:20] it will return [01:55:21] the outcome data. [01:55:29] Okay. [01:55:31] So, [01:55:32] what if [01:55:33] there is a [01:55:34] page fault? [01:55:35] The operating system [01:55:37] tries to revolve, [01:55:39] resolve. [01:55:40] And if it is able [01:55:41] to resolve, [01:55:42] then the page fault [01:55:43] is resolved. [01:55:45] Then it goes back [01:55:46] to the page strip. [01:55:47] But what if [01:55:48] the operating system [01:55:49] is not able [01:55:50] to resolve? [01:55:51] It will retry. [01:55:53] It is not going [01:55:54] to stop the retry [01:55:55] until we close it. [01:55:57] So, [01:55:59] now you are using [01:56:00] this facility [01:56:01] or protecting [01:56:02] your environment [01:56:03] environment [01:56:04] and when the user [01:56:05] is accessing. [01:56:06] If the user [01:56:07] is not able [01:56:08] to access, [01:56:09] if they see. [01:56:18] Okay. [01:56:20] So, [01:56:21] when the permission [01:56:22] is denied, [01:56:23] then only the protection [01:56:24] fault. [01:56:25] Because we have [01:56:26] protected it, [01:56:27] someone is trying [01:56:28] to access it. [01:56:31] So, [01:56:32] then [01:56:33] we call it [01:56:34] as [01:56:35] protection [01:56:36] fault. [01:56:39] Okay. [01:56:40] Cool. [01:56:42] Now, let us look [01:56:43] at a [01:56:44] Python demonstration. [01:56:47] So, we will see [01:56:48] a configurable [01:56:49] set associate [01:56:50] cache [01:56:51] LRU [01:56:52] replacement [01:56:53] write-through [01:56:54] and write-back [01:56:55] in one part [01:56:56] of it. [01:56:58] And the second part [01:56:59] we will be able [01:57:00] to see the [01:57:01] virtual pages. [01:57:03] And we will be able [01:57:04] to see [01:57:05] DTEs, [01:57:07] not [01:57:08] the [01:57:11] industry [01:57:12] records, [01:57:13] but it will definitely [01:57:14] give you [01:57:15] index records. [01:57:19] Then the output [01:57:20] prints [01:57:22] every hit [01:57:23] and miss [01:57:24] in that program. [01:57:25] and it will also [01:57:27] tell you the translation. [01:57:28] The page [01:57:30] falls [01:57:31] in case [01:57:32] if it happens. [01:57:34] And then eviction [01:57:35] and the protection. [01:57:36] The entire [01:57:37] cycle. [01:57:39] The entire cycle [01:57:40] with the help [01:57:41] of a [01:57:42] patent program. [01:57:44] We are going to [01:57:45] look at it. [01:57:46] it does not impact [01:57:48] the real CPU [01:57:49] caches, [01:57:50] internal pages, [01:57:51] or even [01:57:52] VMware [01:57:53] internal. [01:57:54] It does not impact [01:57:55] irrespective of [01:57:56] having. [01:57:57] So, [01:58:02] let me stop sharing [01:58:03] the screen. [01:58:05] Let me open up [01:58:06] my [01:58:07] VMware [01:58:08] and then I will share [01:58:09] the [01:58:10] Linux box. [01:58:12] Just give me a minute. [01:58:14] And that Linux box [01:58:15] will, [01:58:17] the Linux box [01:58:19] will be using [01:58:20] the Python program. [01:58:23] The Python program. [01:58:27] Please. [01:58:33] Page is used [01:58:34] to translate [01:58:35] virtual address [01:58:36] into physical address. [01:58:37] That's right. [01:58:39] So, [01:58:40] we are getting confused [01:58:41] between virtual memory [01:58:42] and virtual machine. [01:58:45] Okay. [01:58:46] memory is something [01:58:49] that you are having [01:58:51] as [01:58:52] one of the accessories [01:58:53] in your laptop. [01:58:55] Now, [01:58:56] your laptop is a [01:58:57] physical machine. [01:59:00] And [01:59:01] memory is [01:59:03] a card. [01:59:04] It is a [01:59:05] part of your laptop. [01:59:06] It is two different [01:59:07] entities. [01:59:10] Now, [01:59:11] when you are using [01:59:12] VMware [01:59:13] sort of [01:59:15] application, [01:59:17] what it will help you [01:59:18] to [01:59:19] achieve is, [01:59:21] you are [01:59:22] trying to bring up [01:59:23] a machine [01:59:25] which is [01:59:26] not there, [01:59:27] but still functioning. [01:59:30] So, it is not there, [01:59:31] but there. [01:59:33] That is what the [01:59:34] virtualization of software [01:59:35] is like. [01:59:36] VMware is helping [01:59:37] you to achieve. [01:59:40] Now, [01:59:43] when you are [01:59:44] creating that virtual [01:59:46] machine, [01:59:47] that virtual machine [01:59:48] also needs to have [01:59:49] some memory. [01:59:51] Where does that [01:59:52] memory come from? [01:59:53] Because the [01:59:54] machine itself is virtual, [01:59:56] not identifiable, [01:59:57] not healable. [02:00:00] So, [02:00:01] where it is going to get [02:00:02] its memory, [02:00:03] it is going to get it from [02:00:04] the physical RAM. [02:00:06] Now, [02:00:07] not only your lab, [02:00:08] but your memory is also [02:00:11] virtualized. [02:00:13] Like memory, [02:00:14] your processor also is [02:00:15] virtualized. [02:00:17] Your storage also is [02:00:18] virtualized. [02:00:20] So, when you say virtual [02:00:21] machine, [02:00:23] it is a combination of [02:00:26] some part of [02:00:29] your physical memory, [02:00:30] some part of your CPU, [02:00:31] and some part of your [02:00:33] storage along with other components. [02:00:35] these three are the major. [02:00:39] So, that is virtual machine. [02:00:42] Now, [02:00:45] both involves virtualization. [02:00:49] And rather than saying both [02:00:50] involves virtualization, [02:00:53] we can say it that way that [02:00:54] virtualization helps us to bring up [02:00:57] the virtual machine, [02:00:58] where its memory is also virtual. [02:01:00] virtual. [02:01:02] So, that is the right way of [02:01:03] putting across. [02:01:04] If you have understood this, [02:01:06] you should be good. [02:01:15] They are not related. [02:01:16] It is one into the another. [02:01:19] A virtual machine requires a [02:01:21] physical machine. [02:01:22] So, you can run one virtual machine [02:01:23] in a physical machine, [02:01:25] or you can also run three virtual [02:01:27] machines in a single physical [02:01:29] machine. [02:01:31] So, it is related in a manner, [02:01:33] if at all we wanted to relate it. [02:01:35] The resources that are used to [02:01:37] buy the virtual machines is [02:01:40] from the physical machine. [02:01:44] Okay, great. [02:01:46] So, Satya is asking, [02:01:48] if RAM is crowded, [02:01:50] then the operating system moves [02:01:52] some data to the swap. [02:01:54] And that swap space is the [02:01:56] virtual memory. [02:01:57] virtual memory. [02:01:58] Okay. [02:01:59] You are right. [02:02:02] Why we call that also a virtual memory? [02:02:07] Taking a part of memory [02:02:11] to a virtual machine, [02:02:13] that is also referred as virtual [02:02:14] machine. [02:02:16] If you are taking a part of your [02:02:18] hard disk, [02:02:20] when you say the RAM is crowded [02:02:22] and the operating system moves data, [02:02:24] where is it moving? [02:02:25] is moving to the hard disk. [02:02:28] So, you can say swap memory, [02:02:29] you can say paging. [02:02:31] Paging is the name of the process. [02:02:33] Swap memory is the type of the memory. [02:02:36] Called a swap memory because it swaps [02:02:38] the data between memory and the hard disk. [02:02:40] So, [02:02:43] if I don't define a swap memory, [02:02:46] that means I am using the entire hard disk [02:02:50] as a hard disk. [02:02:52] I am not trying to make one part of hard disk as a memory. [02:02:56] Now, [02:02:58] a practical question. [02:03:00] Is swap [02:03:04] accepted in [02:03:08] applications like [02:03:10] Kubernetes? [02:03:12] The answer is no. [02:03:15] That means I can't help paging process [02:03:19] that system. [02:03:21] When Kubernetes is running, [02:03:24] the answer is yes, we can't. [02:03:25] We can't. [02:03:27] Now, [02:03:29] why Kubernetes is not supporting [02:03:34] that memory? [02:03:36] It is nothing but virtual memory. [02:03:40] So, now, [02:03:42] imagine. [02:03:44] Okay. [02:03:45] So, let me share [02:03:47] this. [02:03:49] Let me share [02:03:55] this. [02:04:09] Okay. [02:04:11] Cool. [02:04:25] Just a minute, please. [02:04:26] Just a minute, please. [02:04:55] Let me share it. [02:04:58] Okay. [02:04:59] Oops, why is it not opening? [02:05:12] Okay, let me try paint. [02:05:15] Cool. [02:05:22] Let me share it. [02:05:24] Okay, hopefully this will clarify everyone. [02:05:33] So this is my physical server. [02:05:38] I have two servers. [02:05:42] And two physical servers in this, it's huge. [02:05:48] So what I'm trying to do is I'm just trying to [02:05:50] basically make smaller servers. [02:05:57] So I create virtual servers here. [02:06:01] So I have three virtual machines in both the servers. [02:06:09] So now, each virtual machine is going to have all the components, [02:06:17] like disk, storage, memory, and processor. [02:06:22] So now what I'm trying to do here is I'm just, [02:06:27] this is one, this is two, and this is three. [02:06:30] Let me name this as virtual machine four, five, and [02:06:36] so what I'm going to do is I'm just going to use [02:06:41] virtual machine one as master. [02:06:45] And I'm going to make, [02:06:49] I'm going to make, [02:06:54] I'm going to make all this, [02:07:02] five other virtual machines as nodes. [02:07:08] As my Kubernetes cluster. [02:07:11] These are all my nodes. [02:07:15] So, [02:07:18] now Sundar, [02:07:18] you said that [02:07:20] paging is not allowed in Kubernetes. [02:07:24] Why? [02:07:26] Now, when I'm going to make this Kubernetes cluster, [02:07:30] I will be installing [02:07:32] an application called Kubernetes. [02:07:37] Basically, [02:07:39] three different packages [02:07:40] will help us to create this cluster. [02:07:45] So at the first level, [02:07:46] I have used [02:07:48] VMware [02:07:50] to create [02:07:52] virtual machine. [02:07:53] this is level one. [02:07:56] And at the level two, [02:07:59] what is Kubernetes is doing? [02:08:02] Kubernetes is also [02:08:03] going to [02:08:05] virtualize. [02:08:06] Virtualize the virtual [02:08:08] virtual machines. [02:08:10] How? [02:08:12] It is going to run [02:08:13] components called [02:08:15] pods. [02:08:17] What are pods? [02:08:18] Pods are small units [02:08:20] which is going to run [02:08:22] which is going to run [02:08:22] which is going to run our [02:08:22] application inside [02:08:25] the container. [02:08:27] So, [02:08:28] when you say [02:08:28] I'm using Kubernetes, [02:08:30] obviously, [02:08:31] you have [02:08:31] microservice [02:08:32] to your [02:08:33] application. [02:08:34] And for each [02:08:35] microservice, [02:08:36] you have created an [02:08:37] image and each [02:08:39] image will run [02:08:40] as a container [02:08:41] and each [02:08:42] container [02:08:44] will run [02:08:44] the application [02:08:45] and the container [02:08:45] is going to run [02:08:46] inside the pod. [02:08:49] So, [02:08:49] each [02:08:50] container, [02:08:51] each pod [02:08:52] will have the [02:08:52] applications running. [02:08:54] Now, [02:08:55] what is this pod? [02:08:56] Pod is [02:08:57] containing the [02:08:58] application [02:08:59] inside it. [02:09:00] So, [02:09:01] now, [02:09:01] if the application [02:09:02] has to run, [02:09:04] where is it going [02:09:04] to get the [02:09:05] resources? [02:09:07] It needs [02:09:08] memory, [02:09:08] it needs [02:09:09] processor, [02:09:10] it needs [02:09:10] storage also. [02:09:11] It also [02:09:13] needs [02:09:13] a network [02:09:15] interface so [02:09:16] that it can [02:09:17] communicate [02:09:17] between the [02:09:18] pods. [02:09:20] Where is it [02:09:21] going to get? [02:09:22] Again, [02:09:24] Kubernetes is [02:09:24] going to [02:09:25] virtualize the [02:09:26] virtualized [02:09:27] memory and [02:09:28] provide a [02:09:29] small portion [02:09:30] of it to [02:09:30] the pod. [02:09:32] So, [02:09:33] now, [02:09:34] let us put [02:09:35] numbers and [02:09:36] then we will [02:09:36] understand that. [02:09:38] Assume that [02:09:39] this has [02:09:40] 64 GB [02:09:41] memory. [02:09:43] This also [02:09:44] has 64 GB [02:09:45] memory. [02:09:47] Now, [02:09:47] what we have [02:09:48] done is, [02:09:49] we have made [02:09:50] all these [02:09:50] virtual [02:09:52] missions [02:09:52] as [02:09:54] 8 GB. [02:09:56] Each [02:09:57] virtual [02:09:58] mission has [02:09:59] 8 GB [02:09:59] memory. [02:10:01] So, [02:10:01] that means [02:10:01] this has [02:10:01] 8 GB [02:10:02] memory, [02:10:02] this has [02:10:03] 8 GB [02:10:03] memory, [02:10:04] every virtual [02:10:05] mission, [02:10:05] 4, 5, [02:10:06] 6. [02:10:07] Now, [02:10:08] virtual [02:10:08] machines, [02:10:09] 2, [02:10:09] 3, [02:10:09] 4, [02:10:10] 5, [02:10:10] 6 are [02:10:10] running our [02:10:11] pods. [02:10:12] That means [02:10:13] our applications [02:10:13] are running [02:10:14] inside this [02:10:14] virtual machine [02:10:15] and each [02:10:17] pod, [02:10:19] we will [02:10:19] probably [02:10:20] provide [02:10:21] 2 GB [02:10:23] RAM. [02:10:25] So, [02:10:25] that means [02:10:26] this virtual [02:10:27] machine can [02:10:28] run a [02:10:29] maximum of [02:10:30] 3 pods [02:10:31] because it [02:10:32] also requires [02:10:33] some memory [02:10:34] to run its [02:10:35] own operating [02:10:35] system and [02:10:36] other [02:10:36] depending [02:10:37] software. [02:10:38] So, [02:10:39] allocating [02:10:39] that 2 GB, [02:10:41] rest 6 GB [02:10:43] can be [02:10:45] allocated [02:10:45] maximum to [02:10:46] 3 pods. [02:10:48] Here also, [02:10:49] we can run [02:10:50] 3 pods. [02:10:51] So, [02:10:51] every virtual [02:10:52] machine will [02:10:52] run 3 pods. [02:10:55] Now, [02:10:56] this is our [02:10:57] server [02:10:58] S2 [02:11:00] and this is [02:11:01] our server [02:11:02] S1. [02:11:03] In S1, [02:11:06] how many [02:11:06] pods are [02:11:07] running? [02:11:08] 3 here and [02:11:09] 3 here, [02:11:10] so 6 will [02:11:10] run. [02:11:12] This server [02:11:12] to S2 [02:11:13] is running [02:11:15] 3 virtual [02:11:16] machines [02:11:16] because this [02:11:18] does not [02:11:19] run any [02:11:20] master, [02:11:21] all are [02:11:22] nodes. [02:11:22] so all [02:11:23] the 3 [02:11:24] virtual [02:11:24] machines [02:11:24] are [02:11:25] capable [02:11:26] of running [02:11:26] pods. [02:11:28] So, [02:11:28] this can [02:11:30] run up [02:11:31] to 9 pods, [02:11:32] 3 each [02:11:33] virtual [02:11:34] machine. [02:11:35] So, [02:11:36] at the [02:11:37] system level [02:11:38] you have [02:11:38] 64 GB [02:11:39] RAM. [02:11:41] At the [02:11:41] virtual [02:11:42] machine level [02:11:43] you are [02:11:44] virtualizing [02:11:44] this 64 [02:11:45] to 8 [02:11:46] for each [02:11:50] virtual [02:11:51] machine. [02:11:51] and this [02:11:53] 8 GB [02:11:54] is again [02:11:55] virtualized [02:11:56] as 2 [02:11:57] GB [02:11:58] for each [02:11:58] pods. [02:12:00] Now, [02:12:01] in this [02:12:01] scenario, [02:12:03] if you [02:12:04] are also [02:12:04] going to [02:12:05] use the [02:12:06] hard disk [02:12:06] of this [02:12:07] virtual [02:12:07] machine [02:12:08] and [02:12:10] swap it [02:12:11] as a [02:12:11] memory, [02:12:13] then [02:12:13] Kubernetes [02:12:14] master [02:12:15] will get [02:12:16] confused. [02:12:17] Whether [02:12:18] this is [02:12:19] hard disk [02:12:20] or whether [02:12:21] it is [02:12:22] RAM, [02:12:23] this is [02:12:24] a hard [02:12:24] disk, [02:12:25] now it [02:12:26] is used [02:12:26] as a [02:12:26] RAM, [02:12:28] suddenly [02:12:28] your [02:12:28] application [02:12:29] is [02:12:30] hung, [02:12:33] now the [02:12:33] paging [02:12:35] has stopped, [02:12:38] the virtual [02:12:38] hard disk [02:12:40] which is [02:12:40] nothing but [02:12:41] the memory, [02:12:42] virtual memory, [02:12:43] now became [02:12:44] a hard disk. [02:12:44] so the [02:12:46] Kubernetes [02:12:46] will get [02:12:47] confused [02:12:48] because the [02:12:49] Kubernetes [02:12:49] is providing [02:12:51] resources to [02:12:52] our application [02:12:52] that is [02:12:53] running inside [02:12:54] our pods [02:12:55] from the [02:12:57] virtual [02:12:57] memory only. [02:13:01] So can I [02:13:02] virtualize my [02:13:04] hard disk? [02:13:04] Yes, [02:13:05] it can, [02:13:06] as a [02:13:06] memory, [02:13:07] but if you [02:13:07] do so, [02:13:08] then is it [02:13:09] really a [02:13:10] hard disk [02:13:10] or a [02:13:11] memory? [02:13:11] Kubernetes [02:13:13] will get [02:13:15] confused. [02:13:16] So that's [02:13:17] the reason [02:13:17] Kubernetes [02:13:17] says that [02:13:18] I'm going [02:13:19] to look at [02:13:20] your storage [02:13:20] as a [02:13:21] storage, [02:13:22] I'm going [02:13:22] to look at [02:13:22] your memory [02:13:23] as a [02:13:24] memory, [02:13:24] don't confuse [02:13:26] me by [02:13:26] changing the [02:13:27] identity of [02:13:28] a resource. [02:13:30] Then our [02:13:30] application will [02:13:31] get confused, [02:13:32] it might hang, [02:13:33] it might use [02:13:34] it for a [02:13:34] different purpose [02:13:35] or the [02:13:36] process also [02:13:38] can get [02:13:38] killed because [02:13:40] of these [02:13:41] confusions. [02:13:42] That's the [02:13:43] reason, [02:13:45] to avoid [02:13:45] that risk, [02:13:47] Kubernetes [02:13:47] will not [02:13:48] allow any [02:13:49] paging or [02:13:50] swapping [02:13:50] activity in [02:13:52] that physical [02:13:52] service where [02:13:53] Kubernetes is [02:13:54] running. [02:13:56] That is only [02:13:57] for the [02:13:57] Kubernetes. [02:13:59] Now, [02:14:00] Sundar, [02:14:01] I have [02:14:02] created three [02:14:02] virtual missions. [02:14:05] Now, [02:14:06] I have [02:14:08] used only [02:14:08] two, [02:14:08] three, [02:14:09] four, [02:14:10] five, [02:14:10] six as [02:14:11] a cluster [02:14:12] and I [02:14:13] have made [02:14:13] virtual [02:14:14] machine six [02:14:15] as my [02:14:16] master and [02:14:17] rest, [02:14:17] everything is [02:14:18] a node and [02:14:19] this is a [02:14:20] independent [02:14:21] virtual machine [02:14:22] which is not [02:14:24] running as part [02:14:26] of the [02:14:26] Kubernetes [02:14:26] cluster but [02:14:28] it is running [02:14:28] in S1. [02:14:30] Which one? [02:14:31] This virtual [02:14:32] machine. [02:14:33] This is not [02:14:33] part of the [02:14:34] Kubernetes [02:14:34] cluster which [02:14:35] I have [02:14:36] created. [02:14:36] so can I [02:14:37] use paging [02:14:38] here in [02:14:40] this virtual [02:14:40] machine? [02:14:41] The answer [02:14:42] is yes. [02:14:44] This virtual [02:14:44] machine can [02:14:46] use paging [02:14:47] using the [02:14:49] hard disk of [02:14:50] this server [02:14:50] one. [02:14:52] So, [02:14:54] it depends [02:14:54] for what [02:14:56] purpose you [02:14:57] have deployed [02:14:58] your virtual [02:14:59] machines and [02:15:00] other things. [02:15:00] but generally [02:15:02] when you are [02:15:02] speaking about [02:15:03] virtual memory [02:15:04] it can refer [02:15:05] to two [02:15:06] different things. [02:15:07] One is [02:15:08] the one [02:15:08] what is [02:15:10] referred here [02:15:10] in this [02:15:11] virtual [02:15:11] machine. [02:15:12] Second [02:15:13] is where [02:15:16] you are [02:15:16] using for [02:15:17] paging. [02:15:19] If you are [02:15:19] using for [02:15:19] paging that [02:15:20] means you [02:15:20] are using [02:15:20] hard disk [02:15:22] as a [02:15:22] memory. [02:15:23] That memory [02:15:24] is also [02:15:24] called as [02:15:25] virtual [02:15:25] machine. [02:15:26] Sorry, [02:15:26] virtual [02:15:27] memory. [02:15:28] So, [02:15:28] you need to [02:15:29] identify the [02:15:30] context first [02:15:31] before [02:15:32] understanding [02:15:33] the virtual [02:15:34] memory. [02:15:35] Any queries, [02:15:36] any questions? [02:15:42] Okay. [02:15:44] What is the [02:15:45] main role of [02:15:45] Kubernetes? [02:15:46] Okay. [02:15:49] It is a [02:15:50] container [02:15:50] orchestration [02:15:52] tool. [02:15:53] In short, [02:15:55] it is an [02:15:55] orchestration [02:15:56] tool. [02:15:57] It will run [02:15:58] all your [02:15:58] containers. [02:16:00] That is [02:16:03] something which [02:16:05] can be [02:16:05] understood [02:16:06] immediately. [02:16:07] But why [02:16:08] should I [02:16:09] require [02:16:09] container [02:16:10] orchestration? [02:16:11] Because I [02:16:12] have containers. [02:16:13] So I need [02:16:14] to have a [02:16:14] container [02:16:14] orchestration. [02:16:16] Why do I [02:16:16] need a [02:16:17] container? [02:16:19] Because to [02:16:20] avoid the [02:16:21] limitations of [02:16:22] running in [02:16:23] a single [02:16:24] physical [02:16:25] mission or [02:16:27] a single [02:16:27] virtual [02:16:28] mission? [02:16:28] Because if [02:16:29] you are [02:16:29] running the [02:16:30] application on [02:16:30] a single [02:16:31] physical [02:16:31] mission or [02:16:32] a single [02:16:32] virtual [02:16:32] machine, [02:16:34] then the [02:16:34] resources are [02:16:35] limited to [02:16:36] the resources [02:16:36] available in [02:16:38] that machine [02:16:38] only. [02:16:40] I will not [02:16:40] be able to [02:16:41] use resources [02:16:43] available in [02:16:44] other machines [02:16:45] from the other [02:16:46] regions. [02:16:46] that is the [02:16:48] reason we [02:16:49] create a [02:16:50] group of [02:16:50] servers and [02:16:52] that group of [02:16:53] servers are [02:16:53] called as [02:16:54] cluster. [02:16:56] So we have [02:16:57] containers. [02:16:58] to take the [02:16:59] container and [02:17:00] run the [02:17:00] application, [02:17:02] we need [02:17:03] container [02:17:03] orchestration. [02:17:05] That container [02:17:06] orchestration is [02:17:07] Kubernetes. [02:17:09] Now, what [02:17:11] is the [02:17:11] advantage? [02:17:13] If you are [02:17:13] having five, [02:17:14] as I said, [02:17:15] shown you, [02:17:16] if you have [02:17:16] five virtual [02:17:18] machines, [02:17:19] part of your [02:17:19] cluster, [02:17:22] then Kubernetes [02:17:23] can run that [02:17:24] particular container [02:17:25] in one of the [02:17:26] five virtual [02:17:28] machines. [02:17:29] So that [02:17:29] means whatever [02:17:31] resources available [02:17:32] in those five [02:17:32] virtual machines [02:17:33] or five physical [02:17:34] machines are [02:17:35] available for [02:17:36] your application, [02:17:38] you can run in [02:17:39] any one of [02:17:40] them, wherever [02:17:41] resources are [02:17:42] available at [02:17:43] that point of [02:17:44] time. [02:17:44] So that we [02:17:45] require Kubernetes. [02:17:47] Hope that [02:17:48] helps. [02:17:49] Cool. [02:17:50] Anything else [02:17:51] from anyone? [02:17:54] Cool, I [02:17:55] answered this. [02:17:58] if you run [02:18:00] an AWS or [02:18:00] Azure virtual [02:18:01] machine, [02:18:03] why are [02:18:03] putty on [02:18:04] our machine? [02:18:05] Okay. [02:18:06] Putty is a [02:18:07] small application. [02:18:10] It has nothing [02:18:11] to do with the [02:18:11] virtual machine. [02:18:13] It cannot create [02:18:14] a virtual machine. [02:18:15] It cannot run a [02:18:16] virtual machine. [02:18:17] all it can do [02:18:19] is it will [02:18:19] help you to [02:18:20] access the [02:18:21] virtual machine [02:18:22] that is running [02:18:24] in the AWS [02:18:24] environment. [02:18:26] So it is a [02:18:28] remote access [02:18:30] application. [02:18:31] virtual machine. [02:18:33] So it has [02:18:34] nothing to do [02:18:35] with the [02:18:36] virtual machine. [02:18:37] So it has [02:18:38] nothing to do [02:18:39] with the [02:18:39] resources of [02:18:40] the virtual [02:18:40] machine also. [02:18:42] It is, it [02:18:42] will just [02:18:43] create an [02:18:44] interface in [02:18:45] your laptop [02:18:46] or in your [02:18:47] system [02:18:49] wherein you [02:18:52] will be able [02:18:52] to see [02:18:53] the AWS [02:18:55] virtual machine [02:18:56] in your [02:18:57] laptop. [02:18:58] Apart from [02:18:58] that application [02:19:01] like Putty [02:19:02] has no [02:19:04] role in [02:19:04] running the [02:19:06] virtual machine. [02:19:06] It is only to [02:19:07] access the [02:19:08] virtual machine. [02:19:09] Once you [02:19:09] have accessed [02:19:11] using the [02:19:12] Putty, [02:19:13] then the [02:19:14] resources that [02:19:15] are being [02:19:15] used is of [02:19:17] AWS resources [02:19:18] only, not [02:19:19] your laptop [02:19:20] resources. [02:19:22] The same [02:19:23] question if [02:19:24] you have asked, [02:19:25] if I am [02:19:26] running the [02:19:27] virtual machine [02:19:27] in my [02:19:28] laptop and [02:19:28] I am having [02:19:29] a Putty in [02:19:30] my laptop [02:19:31] and I am [02:19:31] using Putty [02:19:32] to access the [02:19:33] virtual machine [02:19:34] which is [02:19:34] running in [02:19:35] my laptop, [02:19:36] then is it [02:19:38] using my [02:19:38] laptop's [02:19:39] resources? [02:19:40] 100% yes. [02:19:42] So conceptually, [02:19:45] Putty has [02:19:45] no relationship [02:19:46] of which [02:19:47] resources to [02:19:48] be used by [02:19:49] the virtual [02:19:49] machine. [02:19:50] It is only [02:19:50] an interface [02:19:51] to access [02:19:52] the virtual [02:19:53] machine. [02:19:55] Great. [02:19:56] Anything else? [02:19:58] Guys, [02:19:59] before we [02:19:59] move ahead [02:20:00] quickly. [02:20:06] Okay, [02:20:06] cool. [02:20:09] Just give me [02:20:10] a minute. [02:20:10] Let me [02:20:10] open [02:20:12] the virtual [02:20:17] machine. [02:20:18] Has the virtual [02:20:18] machine started? [02:20:19] Yes, [02:20:21] it has [02:20:22] started. [02:20:27] Cool. [02:20:28] 29 is [02:20:30] the address. [02:20:31] So I'm [02:20:32] also going [02:20:33] to access [02:20:34] it using [02:20:35] the [02:20:35] virtual [02:20:36] and I'll [02:20:37] quickly explain [02:20:39] once I [02:20:40] have logged [02:20:41] in. [02:20:49] cool. [02:21:19] All right, [02:21:43] guys. [02:21:44] Responding [02:21:45] a little slowly. [02:21:46] Just give [02:21:47] me a [02:21:47] minute. [02:22:16] one later. [02:22:21] Okay, [02:22:22] I will [02:22:23] go ahead [02:22:25] and [02:22:25] come [02:22:27] Ad [02:22:30] go. [02:22:30] I [02:22:31] know, [02:22:32] it's [02:22:41] Oh, [02:22:41] Let me just share my screen, this time let me share my whole screen so that I can show [02:23:02] you how exactly the virtual memory, just a minute, yeah. [02:23:11] Let me share this whole screen, hope you're able to see my screen, I don't know if you confirm [02:23:21] please, right now you should be seeing my console, let me increase the settings so that you'll [02:23:32] be able to find, so this is my system, whole system has 32 GB RAM and I'm using VMware, this [02:23:50] is my VMware, one of the virtual machines is IIT Patna Atom 2026, all other virtual machines [02:23:59] are either passed or stopped, only virtual machine that is running is IIT Patna Atom 2026. [02:24:08] And this virtual machine, if I click here, and if I, cool, I'm not going to do that, let [02:24:20] let me cut here, let me secant, view, okay, the console view, so this has two processors [02:24:46] and 4 GB memory, so I can increase, decrease on the go, but it has 4 GB as of now, and it [02:24:56] has two processors, where is this two processor for this virtual machine coming from, and where [02:25:03] is this 4 GB RAM is coming from, it is coming from my Windows laptop, so my laptop has 32 GB, and it has [02:25:13] physical memory is 32 GB, out of that 4 GB is being allocated to this virtual machine, so this virtual, this is [02:25:23] virtual, it is not physical, but it is taking the actual resource from the physical memory, so how the [02:25:31] relationship is established, this will have a VA, that is virtual address, which will map it to the physical [02:25:39] address, and who will manage this between the physical address and virtual address, that is the MMC, MMC is [02:25:49] nothing but management console from the virtualization software, here in this case, mine is VMware, so this 4 GB is virtual [02:26:00] virtual memory, and this 32 GB is my physical memory, so similarly, if in this virtual machine, if I am enabling [02:26:12] paging, or swap memory, then out of this 60 GB, configure that it will use 6 GB as a swap memory, so this virtual [02:26:29] machine, instead of 4 GB, instead of 4 GB, it will have 10 GB memory, of which 4 GB is virtual memory, and 6 GB is [02:26:37] swap memory, but currently, I don't have swap, I have disabled the swap, if we want to run a cluster, for [02:26:47] example, for example, if you look at here, controller, node, node, these 3 virtual machines, if I start, it will start a [02:26:56] Kubernetes cluster for me, in these 3 virtual machines, I have disabled the swap memory, because Kubernetes does not [02:27:04] support back, so a quick explanation of virtual memory, how to address, virtual memory is addressed in both the [02:27:13] contexts, one is memory to memory virtual memory, hard disk to memory, that is also a virtual memory, now let us come back here, so now, let me open this [02:27:30] program, memory hierarchy, so it's a Python program, so, I will share this program, in the model, no worries, you can go [02:27:43] through, how this program is written, but, this is a conceptual simulator, basically, it models cache behavior, and the operating [02:27:54] system, type, virtual to physical translation, it does not inspect VMware's physical CPU, caches, the guest, guest [02:28:06] kernel, which is my guest kernel, my Ubuntu operating system is the guest kernel, real page tables, are the [02:28:12] hypervisor's methods, that is, so I am just, return this program, and this program, what it will do is, it is going to [02:28:21] give us, every, every information, cache line, let me go below, I have a function here, this function, is going to [02:28:36] split byte address into block numbers, that index and tag, and then, this is something which is, this function, this is [02:28:48] decode, and this is access, basically, it will perform one byte address, read or write, and return an [02:28:54] explanation, that is, this function's job, and this is basically a summary, so we should put everything [02:29:04] together, now, this function is basically to run a cache demo, and then, it will print the information, so, this is the [02:29:16] first part, which is, cache model, suppose if you are having a VMM, VMM is nothing but a virtual memory [02:29:25] model, in that case, how the paging table, works, so, we are just, trying to put some transaction, and that [02:29:39] transaction, where exactly, is performing, and I have written the code in such a manner, that while it is [02:29:50] performing, it will identify itself, and it is going to display on the screen, now, when you are doing, in the [02:30:01] virtual memory demo, it is also going to display all the information, right from the virtual memory, [02:30:10] paging, and also translation, eviction, all the four, it will display, so now, let me close the program, let me [02:30:24] try to run, I am using Python 3, let me run this, memory hierarchy.py, hopefully it runs, sometime that I have [02:30:33] not run this program, oh, great, so now, part 8, so basically, it simulates, okay, concept, it does not expose the [02:30:47] real CPU caches, just a simulation, one is cache hierarchy, second is VMM, virtual memory, or address [02:30:55] translation, so, cache is 64 bytes, capacity, the cache capacity is 64 bytes, that's the data which I have [02:31:06] put, 16 byte line, one cache line is 16 byte, two way set associative, so address cases are 0, R4, [02:31:16] R0, R32, R0, W4, so what is this? This is the four reads, and the four writes, and that's the actual [02:31:29] physical memory, which it has been provided to this particular virtual machine. Now, this is the write-through, [02:31:39] this is the write-through, and this is policy as write-track. So, when it is reading the address 0, first time, it's a cache miss. [02:31:51] It means it is, the data is not available in L1. So, block 0, set 0, tag 0, it was not available. [02:32:01] But when it was reading the address 4, it is a hit. The reason it is a hit is, the information was [02:32:10] available in this block for this particular read. So, 0, 4, 32. And read address 0. So, 32 also, [02:32:25] first time it is reading, so it is a miss. Because it is referring to block 2, set 0, and the tag 1. So, in this, [02:32:35] there were no data available in that. It's a L1 cache. So, now, since no data was available, [02:32:42] it is a miss. Miss does not mean that you will not get the data. You will get the data, but the lower [02:32:50] level cache, like L2, L3, RAM, has to provide that. So, it will take some time. So, now it is reading the [02:32:58] address 0 again. It's a hit. Here, it is a miss. But when you are doing 0 again, it is a hit. Because [02:33:07] this miss would have got the data into this. So, it is a hit. Hit means it found. So, it's write through [02:33:15] update memory immediately. Okay. So, it is basically write address 4. The next is, it is something similar to [02:33:26] our total variable, where we are updating the value to the variable. So, it is a write. So, write [02:33:33] where? Write in this address. So, here we read, it's a hit. Nothing happened. But the same block, [02:33:41] when we are trying to update, our program is trying to update the value. It is a hit. Because address has [02:33:49] the value, the data. Now, it is a write. So, it is a write through update memory immediately. Write [02:33:56] through means, not only in the cache, but it also needs to update the memory immediately. But [02:34:02] from memory to disk, this will not, this operation will not do. Memory to disk will be done by our [02:34:10] actual program. Means if I have written in my Python program, whatever value is written [02:34:17] here for the variable total, write it to the database in the system. Then only from memory, it will go to [02:34:28] hard disk. But by default, if there is a change in the cache, automatically the memory also will be [02:34:37] updated and that is write through. So, again, it is reading the address 64. Reading the address [02:34:46] 32. 32, here also we read. Here it was a miss. 32, again it was a miss. It is also blocked [02:34:54] to stat 0 and tag 1. Why it is a miss? Because evict tag 0. So, here. [02:35:07] So, that is the reason it is a miss. But next time when you do the 32 again, it will have the hit. [02:35:13] So, summary is we have for eight accesses, three hits and five misses. Hit rate is 37% and memory [02:35:22] write is 1. Why memory write is 1? Because only this request it has written through. So, this is a [02:35:33] return through policy. Now, in case if I have a write back policy. So, you can here write back [02:35:40] mark cache line dirty. It will not write it back to the memory. It will just mark the cache line as [02:35:48] dirty. That's all it will do. But here, if you look at it, it is a hit block 0, set 0, tag 0, [02:35:54] block 0, block 0, set 0, tag 0. So, here also it is a hit. So, again, rest dirty victim return [02:36:04] to memory where read access 32. That's fine. But our focus is write back. It will mark cache line as [02:36:13] dirty. Write through. It will update the same data in the memory immediately. Perfect. Now, virtual memory. [02:36:23] Same addresses. Virtual address 20, virtual address 30. Now, virtual address 20, [02:36:34] TLB miss. It is looking up the page table entry for VPN 0. Page fault because it's not there. Load virtual [02:36:46] page 0 into frame 0. What is page 0? Page 0 is the virtual memory and frame 0 is the referring [02:36:53] to the physical memory. So, the translation up. Because it's a page fault translation is happening. [02:37:01] So, virtual address 20 refers to physical address 20. VPN is 0, offset is 20 and frame is also 0. [02:37:11] So, this is the first time you are reading. But if you are reading this again, read virtual address. [02:37:20] TLB is again missed. It will look for the page table entry for VPN 0. It will evict virtual page [02:37:28] 1 from frame 1 because then 0. So, TLB replacement remove VPN 2. Where is VPN 2 coming from? [02:37:38] VPN 2 will come from? VPN 2 will come from here. Right. So, here we have 3 read virtual addresses. [02:37:48] 3 write virtual, sorry 2 write virtual addresses and 2 further read. So, whenever there is a TLB miss, [02:38:00] you will see TLB miss the maximum because it will look up the page table entry for here. It's a page fault. [02:38:10] Load virtual page 2 into frame 2. It means replacement remove VPN 0. Why it has to be replaced? [02:38:19] Because it was earlier referring to VPN 0. Now, it has to refer to VPN 2, offset 80 and frame 2. [02:38:29] Frame is referring to the physical. Page is referring. This virtual address is referring to the virtual memory. [02:38:37] And it is connected through the VPN 2. Offset is 80. Now, if you are accessing the same 530 again, [02:38:49] then you will not see the TLB miss as long as it is the same program which is running. [02:38:57] If one program has used that particular virtual memory, that function is over, program is over, [02:39:06] a new transaction comes, same program comes up, then it has to evict the value and get a new for the new customer. [02:39:13] New request means new customer for the application. And as far as resource also is concerned, it is a new. [02:39:22] So, it has to evict, get the new and that's what exactly this particular process has done it. [02:39:32] Now, page table. This is basically simplified for our understanding. [02:39:39] So, this is only for part B. 0, 1, 2, 3, VPNs. [02:39:49] Present. Was the data present? Information given? True. Frame 1. False. No frame. [02:39:58] True. Frame number 2. True. Frame number 0. [02:40:02] So, here 0 means its actual reference. If it is not present, it will say none. [02:40:09] The read or write? Only one write. Sorry, three writes. Is it referenced? Yes. All the four are referenced. [02:40:21] Out of which only one is marked as 30. This is the overall performance of this particular program using the resources from my virtual machine. [02:40:35] So, I used a virtual machine. I could have displayed this in my Windows operating system itself. [02:40:40] But if I am running it in the Windows operating system, it will not be able to refer to the VPN and other things, [02:40:47] because everything will be using the virtual memory. [02:40:51] That's the reason I used this virtual memory. [02:40:55] For to understand the concept. [02:41:00] I just wanted to pass here and check any queries, any questions, please. [02:41:07] Let me see the chat from here itself. [02:41:15] Any queries, any questions? [02:41:17] Any queries, any questions? [02:41:21] Can I assume we are good? [02:41:28] Is it clear? Can I assume we are good? [02:41:33] The quiz 2, I have not understood. [02:41:39] The quiz too, I have not prepared it. I'll be preparing the coming week. I think it will [02:41:54] get opened after November 30th. So it will contain all the portions. We still have two [02:42:06] sessions. One is on Saturday and next Sunday. We are good. We'll be covering. [02:42:15] Whatever we are covering until next Sunday, it will be part of your quiz too. [02:42:29] Yes, I will be uploading. I will just check and then if it is missing. See, [02:42:36] labs is something that only for reference of what activities we have done. I will upload it in the [02:42:45] lab. I don't see, because I have not used much presentation after the fifth or sixth lab session. [02:42:53] I have used the actual programs. So the recordings will have it. And I will also upload the programs [02:43:06] as part of the labs. But definitely the theory part is updated. Up to risk. I'll be uploading [02:43:17] this also. Next Saturday, Sunday also, I'll get it uploaded. So you should be able to wrap up that. [02:43:27] end some exam. Okay, that's a great question. If I am right, that is to have some 25 questions. [02:43:43] No, today's slide I will be uploading today itself. So your final exam is on 5th December. [02:43:56] Okay. So the EAC would be of all the types, quiz, true or false, multiple right answers. And it will also have descriptive [02:44:12] type questions, wherein you might have to type the answer on the screen itself. [02:44:18] Definitely, there won't be any question where you are expected to write a program. [02:44:25] So that you can be doubly sure of. [02:44:28] So this is what, but number of questions, once I set, I can confirm. [02:44:32] I'm expecting it to be somewhere between 25 to 30 questions. It will be of all types together. [02:44:42] Some 25 to 30 questions will be there. [02:44:46] So just wanted to check. Until now, it was only in MCQs and 12 faults. [02:44:52] All the topics that we have covered is, you have to mark as important because Patna themselves have restricted the topics and we have also gone through only that. [02:45:13] Descriptive, definitely, there will be one or two questions. [02:45:20] In all the sessions, whatever I have taken, there had been descriptive questions. [02:45:30] One or two, for example, [02:45:33] I can understand Paramveer. I'm going to check that. [02:45:46] Descriptive type means, for example, today's one, if you're speaking about, I'll be just telling you, [02:46:01] asking you to write about, you know, the sequence of the memory hierarchy [02:46:10] and describe the role of each element in that. [02:46:15] Just one example from today's session. [02:46:19] Maybe for four marks or something. [02:46:23] So there are four elements. [02:46:25] Sorry, five elements and five [02:46:28] elements for description of its role. [02:46:32] So that is the type of descriptive questions. [02:46:37] Generally, I'll put it across, but since you're telling it's a proctored exam and [02:46:42] something, so probably I will not add those one or two. [02:46:47] Anything else from, how many words will be part of the question itself? [02:46:56] It will say not exceeding 30 words, not exceeding 50 words. [02:47:00] It will be part of the question. [02:47:02] Now that Paramveer has said that this is what it is, because until today, [02:47:07] IIT had not come back and said, well, let us not have descriptive. [02:47:15] Because earlier, they had an option to write it on a paper and then upload also. [02:47:20] So that option was there. [02:47:33] Anyhow, let me check with the coordinator. [02:47:36] I will confirm you next week whether it will be there or not. [02:47:44] Anything else from anyone? [02:47:50] Yeah, I understand. [02:47:53] It's easy for me also, no? [02:47:56] Okay, cool. [02:47:57] Thank you so much, guys. [02:47:58] See you next Saturday. [02:48:00] Take care. [02:48:00] Bye-bye.