WEBVTT 1 00:00:07.589 --> 00:00:19.770 William Cheng: Hi, welcome back from the spring break. So today's lecture, I will divide them into two lectures. So this way I can, you know, take a break in the middle. 2 00:00:20.910 --> 00:00:37.290 William Cheng: All right, so I guess we're in Colonel to now Colonel to is do I guess you have you no more than two and a half week to finish. If you have co from previous semester, please don't look at them or copy them it's best that you get rid of it. 3 00:00:38.610 --> 00:00:45.840 William Cheng: And I guess. This week we have the midterm. So I assume that you're going to be studying for your mid term before you go back to doing a colonel assignment. 4 00:00:46.740 --> 00:00:53.940 William Cheng: So for Colonel to the the grading guidelines is kind of similar to Colonel one the the grading guidelines on where we will grade. 5 00:00:54.510 --> 00:01:00.720 William Cheng: You need to pass all the tests is something called BFS test. See, there's something like 500 tests in them. 6 00:01:01.200 --> 00:01:09.570 William Cheng: So again sometime you pass one test you're going to end up passing a lot of tests. Okay. And also there's another Tesco favorite FS tests. See 7 00:01:10.320 --> 00:01:19.110 William Cheng: So that one is to test the bfs code together with your kernel one code. So testing your file system code together with your thread code. 8 00:01:19.710 --> 00:01:42.180 William Cheng: So if you cannot pass BFS test. See, you shouldn't really try to pass a test in favor FS test RC next. Alright, so, so we don't have lecture for, you know, this Wednesday and Thursday. So I guess this Friday, I will go over some more of the colonel to code. Okay. 9 00:01:45.330 --> 00:01:57.420 William Cheng: All right, so I guess I hope you have seen email from me. If you haven't seen email from me about the midterm exam, you should, you know, check to see what's going on in your email. So maybe 10 00:01:57.780 --> 00:02:06.450 William Cheng: It went to the spam folder or something like that. You need to make sure you get every message I post to the classical group. Yeah. And so in the email. I mentioned that 11 00:02:07.170 --> 00:02:17.550 William Cheng: The I got an email from the dean's office to tell us not to have exam, you know, this week on Monday, Wednesday and Monday, Tuesday and Wednesday. 12 00:02:18.270 --> 00:02:30.300 William Cheng: So that means that our mid term on Wednesday, I can't really hold it. So I guess that will give the actually give me an opportunity to have a common example all sections of CS world to know 13 00:02:30.870 --> 00:02:40.080 William Cheng: So the plan is to have the midterm exam is going to be a common take home exam as I put take home in quotes, in a way, it's not really take home. 14 00:02:40.560 --> 00:02:52.560 William Cheng: You just have to take it. You know, I guess at home, but do a very, very quickly. So this will happen on Thursday, March 26 FROM 4PM to 4:40pm 15 00:02:53.100 --> 00:03:00.180 William Cheng: So I mentioned this a few days ago. So I said, if you, you know, if you cannot participate in the midterm. 16 00:03:00.570 --> 00:03:05.790 William Cheng: During this time, you need to let me know as soon as possible, and we can sort of figure out what to do with you. 17 00:03:06.180 --> 00:03:16.800 William Cheng: Okay. So, therefore, if you cannot take it at this time, you need to send me an email and tell me why you cannot take the exam. At this time, and also in you tell me when you can take when you can take these out. 18 00:03:17.400 --> 00:03:23.400 William Cheng: Okay, if the only reason is that it's not convenient for me or somebody like that you need to do really tell me why. Okay. 19 00:03:24.210 --> 00:03:32.820 William Cheng: So so so if you don't have any special circumstances, you should take a midterm exam. At this time, even though this exam is not a pre scheduled time 20 00:03:33.690 --> 00:03:48.270 William Cheng: All right but but this is everybody's at home, you know. So I think we have a lot of flexibility so the best thing to do is that everybody will take exam and this will be a 40 minutes examining only half the size of a regular of the exam that I plan. Okay, so it's going to be much shorter 21 00:03:50.070 --> 00:03:55.860 William Cheng: And also, I guess somebody was concerned about the length of the exam. So typically for my exam people finished really, really fast. 22 00:03:56.220 --> 00:04:00.750 William Cheng: Okay. So even for 80 minutes exam, something will finish in you know 40 minutes or something like that. 23 00:04:01.350 --> 00:04:07.680 William Cheng: So when it's a 40 minutes exam. Some people will finish in 20 minutes or 15 minutes it was designed to be finished in 30 minutes 24 00:04:07.980 --> 00:04:13.620 William Cheng: Okay, so you should have plenty of time to do this and some people concerned about, you know, we try to submit the exam, you know, what if 25 00:04:13.950 --> 00:04:21.390 William Cheng: There's glitches and internet or something like that. I mean, if you have glitches you let me know right away. You know when you try to make some just send me email right away so used to me. 26 00:04:21.930 --> 00:04:27.300 William Cheng: It's say that you're having trouble in the end if you are late by one or two minutes and that should be perfectly fine. 27 00:04:27.810 --> 00:04:37.710 William Cheng: Okay, but if you if you try to take longer than you know 40 minutes I mean that the basic idea over here is a 40 minutes. You need to stop writing answers on your exam. Yeah. 28 00:04:38.340 --> 00:04:44.220 William Cheng: So I sent out a mock exam. You're supposed to sign a pledge and inside the pledges that you have to follow all the rules. 29 00:04:44.430 --> 00:04:53.370 William Cheng: And I mentioned before, what are the rules are, and on the class website else with describe exactly what all the rules are so by signing the pledge you are basically agree that you will 30 00:04:53.610 --> 00:04:58.740 William Cheng: You will follow all the rules. Okay. And also you agree not to cheat and if you know other people are cheating. You have to let us know. 31 00:04:59.220 --> 00:05:12.480 William Cheng: Okay, so that's what you're assigning okay if you don't want to sign the pledge, then you are not allowed to participate in the midterm exam okay if you don't participate in the midterm exam, then what happened is that your final exam will be worth 55% of your overall great 32 00:05:13.500 --> 00:05:20.490 William Cheng: Okay, so that's going to be the deal. Yeah, I think the final exam was 55. I mean, it's basically it's the combination of the midterm and final yeah 33 00:05:21.180 --> 00:05:37.890 William Cheng: Alright, so, so you should have gotten an email, you should have, you know, starting your mock exam. So again, it's very, very just just try to get you used to the procedure and also make sure you send me your signed your, your, your, your sign the pledge. Okay, so please again read a very carefully. 34 00:05:39.000 --> 00:05:47.550 William Cheng: I set a deadline for the pledge, you must submit your pledge. By the end of Monday, which is, you know, today, March 23 35 00:05:49.260 --> 00:05:56.370 William Cheng: Also because it says that if you missed the midterm your final exam will be worth 60% of your overall grade. So I guess 25% plus 35% yeah 36 00:05:57.120 --> 00:06:07.170 William Cheng: So some people are emailing Yo yo yo yo sign pledge to me because you know they don't want to use the either the pledges too big because if you are bigger than one megabytes, you will not be able to use the web form. 37 00:06:07.680 --> 00:06:15.660 William Cheng: So I asked you to actually make a smaller but if for some reason you cannot, you know, shrink it down to one megabyte and for some reason you don't want to use the web form. 38 00:06:15.900 --> 00:06:20.640 William Cheng: You can email it to me. But if you email to me, I will not send you an acknowledgement, even if you asked me to 39 00:06:21.270 --> 00:06:26.760 William Cheng: Okay, because I don't want it because my friend has policy if I do as well. Once I have to do for everybody. So if I 40 00:06:27.330 --> 00:06:35.730 William Cheng: If I give you an announcement. I have to send 254 45 you know emails and I don't want to do that. Right. That's why we wrote software because we want to do, you know, 41 00:06:36.180 --> 00:06:45.570 William Cheng: We don't want to keep repeating doing the same thing. Okay, so, so if you want a receipt or this case it will be a ticket you just send me your sign a pledge using the web form. 42 00:06:46.530 --> 00:06:55.680 William Cheng: Alright, so. So again, if you have any issues, you know, let me know. And, you know, by the end of Monday, you know, you know, for all the people that has sent me their pledge. 43 00:06:56.340 --> 00:07:03.630 William Cheng: Then we can go on with it with the midterm exam. Yeah. Alright, so what I would do is that I will have a rehearsal. 44 00:07:04.290 --> 00:07:12.360 William Cheng: You know, for the midterm exam and some people concerned, you know, what is this too complicated or something like that. So, so I'm going to give you a rehearsal. Okay, so this way you know exactly what you have to do. 45 00:07:12.870 --> 00:07:22.200 William Cheng: So what I want you to do is that on Tuesday, which is two days before the midterm at exactly the same time for PM and the exam supposed to finish or 4:40pm 46 00:07:22.440 --> 00:07:37.440 William Cheng: So I want you to do is I want everybody to participate because what I will do is I will send you an email, just like the way I sent you. Your pristine kernel source code, right. So in the email. There's a link, you click on the link and then you can download your 47 00:07:38.490 --> 00:07:44.190 William Cheng: You'll get it on your midterm. So again, this is this is a rehearsal. So the midterm going to be the same thing as the mock 48 00:07:44.850 --> 00:07:52.170 William Cheng: The term. So you need to, you know, enter into the TXT file and then you need to submit it guys. So what I'm going to ask you to do is that you 49 00:07:52.740 --> 00:08:05.880 William Cheng: At four o'clock. I'm going to sort of send this one to everyone. So in a very, very short period of time. I need to send out 245 emails and there's going to be 245 downloads and want to make sure that my web server can handle the load. 50 00:08:06.510 --> 00:08:13.020 William Cheng: Okay, so that's why I'm going to ask everybody to participate exactly 4pm okay wait for my email, and then click on the link and download 51 00:08:13.230 --> 00:08:18.480 William Cheng: If there's any issue, I need to know because you know if you have issue now while later, I'm going to, we're going to end up with the same problem. 52 00:08:19.200 --> 00:08:34.290 William Cheng: Okay. All right. Otherwise, I'm going to ask you to F exactly 4440 4:40pm which is when the mock exam supposed to end. I want you to all upload you know the the answer. Remember that text file, only a few lines upload that file using the web form. 53 00:08:35.340 --> 00:08:41.010 William Cheng: Okay, so again if it doesn't work for you. You need to let me know. So, you know, again, we need to arrange that you can actually send email to me. 54 00:08:41.250 --> 00:08:47.010 William Cheng: But, you know, sometimes email can take hours of that, you know, can take days. So therefore, emails, really, really big problem. 55 00:08:47.520 --> 00:08:52.440 William Cheng: Okay, so therefore, I mean, I strongly encourage us to do to to to to to use the submission 56 00:08:52.740 --> 00:09:04.050 William Cheng: You know, the, the web form. This way, you get a ticket you know exactly when I get the, you know what, when I get your file. So again, if you are missed by a few seconds or a couple of minutes. Don't worry about. I'm not going to take it to take points off. 57 00:09:04.590 --> 00:09:11.280 William Cheng: Okay, but if you're starting to be really, really late that's gonna be a problem. Okay. Alright so today we're going to do a rehearsal. Okay. 58 00:09:12.660 --> 00:09:13.710 William Cheng: Okay, so 59 00:09:14.790 --> 00:09:22.890 William Cheng: So I guess today. Again, I'm going to cut the lead you into two parts. So the first part of the video. I actually, I have no idea how long it's going to go. So anyways, 60 00:09:23.970 --> 00:09:24.780 William Cheng: We'll see how it goes. 61 00:09:26.730 --> 00:09:36.300 William Cheng: All right, so last time we were talking about segmentation and we sort of go over some of the feature you can add it in segmentation, you can have protection, you can share 62 00:09:36.600 --> 00:09:42.930 William Cheng: You know you can share memory segments. You can even implement copy on write you can implement memory map, map file. 63 00:09:43.590 --> 00:09:52.740 William Cheng: So, you know, so even with segmentation. There's a lot of stuff can be done. Okay, so, so, so, so, so even in the good old days when they don't have, you know, page. And like we have today. 64 00:09:53.250 --> 00:10:02.220 William Cheng: Even with segmentation, they can actually implement a full fledge operating system. Yeah, I guess we sort of have one more feature that we need to introduce for 65 00:10:03.150 --> 00:10:16.980 William Cheng: You know, for for segmentation. So, so, yeah, I'm trying to follow the schedule from for 2019 right. So again, if you look at the fourth 19 lecture web page, you can actually see where I'm trying to, you know, start and finish. Okay. 66 00:10:19.140 --> 00:10:26.790 William Cheng: All right, so there's one more thing that we can do. We can actually implement our swapping as it turns out that at this point we don't really need to add any new feature. 67 00:10:27.660 --> 00:10:31.380 William Cheng: Well, actually, we need to actually add one more feature, you know, into the MMU 68 00:10:31.950 --> 00:10:41.280 William Cheng: So, so, so far what we have inside of me right we have, you know, for every segment, we have a base register over bound register. We also have another flag inside the MMU to say whether 69 00:10:41.700 --> 00:10:46.920 William Cheng: The memory protection, whether this particular memory segment is read only or rewrite 70 00:10:47.190 --> 00:10:57.000 William Cheng: Okay. And also we talk about private and, you know, share mapping again that particular bid is typically not inside the mmm you that pretty Europe is actually stored inside the operating system. 71 00:10:57.600 --> 00:11:04.290 William Cheng: OK, so again inside me. We had the base register you have the bounce register you have read only or rewrite. So that's all you have. 72 00:11:04.680 --> 00:11:12.000 William Cheng: Yeah, so now we need to add one more thing to implement back in store and this one is guy is that every pair of basis inbound register, we're going to add another bit 73 00:11:12.240 --> 00:11:20.130 William Cheng: Okay, the spirit is called the validity bit, it can be equal to one or zero when it's equal to one, that means that this MMU register is valid. 74 00:11:21.000 --> 00:11:31.470 William Cheng: Okay so equal to one means that this parent MMU register. I mean is good about is that is valid. If the equal to zero, that means that the MMA register is invalid. So therefore habits. Why, if it's invalid going to get you're 75 00:11:33.300 --> 00:11:39.030 William Cheng: Gonna get a segmentation fall you trapped into the operating system and hopefully the operating system can fix things for you. Yeah. 76 00:11:39.660 --> 00:11:47.190 William Cheng: Alright, so now I mean this MMU picture that I draw over here. I don't draw the read only and rewrite anymore because I want to save some space over here. So again, 77 00:11:47.490 --> 00:11:54.810 William Cheng: Again, over here, there's, it's Understood, understood that inside this every pair. And then we register. There's a read only and rewrite it. Yeah. 78 00:11:55.200 --> 00:12:01.560 William Cheng: Alright, so now we add the validity equals one over here, that means that this you know all these four pillars of base and Bella gesture. 79 00:12:02.100 --> 00:12:09.360 William Cheng: They're all valid. But again, that can be more, you know, again, we're not trying to picture. Yeah. Alright, so, so, so there will show that you know all these things, sort of, you know, 80 00:12:09.750 --> 00:12:12.870 William Cheng: A point to all these different memory segment, because the base register. 81 00:12:13.470 --> 00:12:20.130 William Cheng: You know, contains the physical address of these memory segments and the bound register contain the size of the memory segment. 82 00:12:20.430 --> 00:12:30.780 William Cheng: Now alright so the validity of bit over his say they're valid. Right. So when did they become invalid while so so so what you can do is that we can actually use this to implement swapping. Yeah. So, for example, 83 00:12:31.110 --> 00:12:33.450 William Cheng: You know, we mentioned before that in physical memory. 84 00:12:33.930 --> 00:12:38.580 William Cheng: Since we're doing segmentation. We're going to use the first fifth memory allocated elegant physical memory. 85 00:12:38.850 --> 00:12:44.910 William Cheng: And one problem with the first word memory alligator is that at some point we run out of space. Okay, well we run out of space. What do we have to do. 86 00:12:45.120 --> 00:12:53.280 William Cheng: Well, in this case, we need to swap something out, we need to take the the content of one memory segment and we're going to write it to the desk and we've got to remember where this 87 00:12:54.120 --> 00:13:00.090 William Cheng: Okay, so what we do over here is that, you know, so at some point, I'm going to run a physical memory and this case wouldn't take this memory segment over here. 88 00:13:00.240 --> 00:13:07.590 William Cheng: We need to swap it out to the desk. So how do we know that this is the one to swap out. Well, whatever the colonel algorithm will use. We're going to do some kind of malware, then 89 00:13:07.950 --> 00:13:11.490 William Cheng: Look at all the memory segment and decide that this is the best memory segment to swap out 90 00:13:11.880 --> 00:13:19.590 William Cheng: Okay, so later on in the second part of chapter seven. We're going to sort of talk about what the algorithm is Dan for for now one of the memory segment, you know, is 91 00:13:20.580 --> 00:13:30.660 William Cheng: It is picked out and then what we'll do is that we need to write it out to the desk. So when it goes on to the desk. We need to remember where it goes, right. So inside the operating system, we're gonna do some kernel data structure. 92 00:13:30.960 --> 00:13:40.140 William Cheng: To remember where it goes, sort of look like this right inside our system over here, this memory segment has been written out to the desk. So inside the operating system it will remember that. 93 00:13:40.740 --> 00:13:48.930 William Cheng: I guess in the previous example over here, this is the heap segment somehow we decided this is the one we need to swap out so we need to change this this particular 94 00:13:49.320 --> 00:13:59.220 William Cheng: You know me register to be invalid. So this way, meaning that the base of the bows and nothing there is is valid. So if you try to use this particular memory segment, you're going to get a segmentation Paul 95 00:13:59.550 --> 00:14:09.060 William Cheng: Yeah. So inside albinism over here I draw a bunch of dashed line over here to say that the third pair of me read your show over here for the heap segment is tied to this data sitting on the desk. 96 00:14:09.720 --> 00:14:20.010 William Cheng: Okay, so this way when I get a segmentation fall when I try things out operating system. The system will look at this data structure and it will know how to fix the segmentation fall. And again, it will be able to return to the 97 00:14:20.550 --> 00:14:24.270 William Cheng: To the user space program and the user space for one can try to get that 98 00:14:25.080 --> 00:14:32.340 William Cheng: Right, so, so let's do this. Right. So in this case, again, the user program is going to continue to run as long as it doesn't use this memory segment. Everything is fine. 99 00:14:32.820 --> 00:14:37.740 William Cheng: But eventually what I try to access memory location 678 so again we can actually see that 100 00:14:38.250 --> 00:14:45.330 William Cheng: Address 678 over here. It's going to be 78 bytes into the heap segment. So inside you know from the inner core of the CPU. 101 00:14:45.840 --> 00:14:59.850 William Cheng: Memory reference is going to come out is that it will use a third pair of base inbound register and the offset equal to 7878 is less than 1000 so that's fine. But unfortunately, at this point, v equals zero. That means that none of the value of yours are valid. 102 00:15:00.360 --> 00:15:06.420 William Cheng: Okay, so therefore we're going to, we're going to generate a fall into the inner core of the CPU and now you try into the organism. 103 00:15:06.870 --> 00:15:10.950 William Cheng: Once you're going start operating system. Again, the audience's that need to look at the 104 00:15:11.280 --> 00:15:18.420 William Cheng: The outer space representation and find out which virtual address calls the fall. So in this case, you will see that it's going to be the heat segment. 105 00:15:18.780 --> 00:15:23.670 William Cheng: But then at this point. Obviously symbol realized that, oh, he knows what to do, right, because this particular memory segment. 106 00:15:23.910 --> 00:15:35.220 William Cheng: Has been swapped out to desk. So all it has to do is to go to the desk over here and then swap it into a physical memory. And so what is optimism has no right now. So what it will do is it will run the first fit memory. 107 00:15:36.150 --> 00:15:42.090 William Cheng: A memory allocation algorithm again try to find a place in physical memory that's big enough with this memory segment. 108 00:15:42.360 --> 00:15:52.110 William Cheng: Yeah. So in our example we hear this memory segment is 1000 bytes long. So what you will do is it will allocate some memory is that physical memory and this example. What it will do is it will find 109 00:15:52.320 --> 00:16:00.570 William Cheng: memory location 1000 I guess in the previous case, it starts out as 2200. So now you know move to a different place, it will start, you will find a 110 00:16:00.930 --> 00:16:04.230 William Cheng: Location 1000 and what it will do is it will start at this operation. 111 00:16:04.470 --> 00:16:11.790 William Cheng: Take the data from the desk copy them into physical memory. The Colonel to fall asleep when the operations is done inside interrupt service routine. 112 00:16:12.000 --> 00:16:20.250 William Cheng: The Colonel thread got woken up and now he knows that this data has been transferred from that this into memory. So what it needs to do. Now, it needs to fix up all the colonel data structure. 113 00:16:20.610 --> 00:16:31.230 William Cheng: Right, so, so, you know, this particular memory segment over here and now it's no longer city inside the, I guess, over here, this space over here is known as the swap space or just call the swap space over here now. 114 00:16:31.770 --> 00:16:35.880 William Cheng: So this particular memory segment is no longer in the spa space and now it's inside 115 00:16:36.120 --> 00:16:44.190 William Cheng: You know, it's actually, it's a physical memory. So therefore, the ability to update data structure, it needs to set the validity bit over here equals to wine and also 116 00:16:44.460 --> 00:16:52.140 William Cheng: We need a new base register, because this memory segment get put into a different memory location right so the base over here is going to be 1000 instead of 2200 117 00:16:52.770 --> 00:17:00.840 William Cheng: In this case, the size of the segment is still what it was before. So therefore, we're going to put it, what it was before. So now we fix the segmentation fault. 118 00:17:01.380 --> 00:17:11.760 William Cheng: Okay. So the obvious isn't will not return to the user space program when you return to the user space where it will try it again and again it will access officer 78 using the third pair of is not register. 119 00:17:11.970 --> 00:17:23.910 William Cheng: Now 78 is less than 1000 so you ask 78 and also the validity of bit over here is equal to one. So you asked me a into 1000 you're going to end up accessing this memory location. That's exactly what you want. 120 00:17:24.750 --> 00:17:32.940 William Cheng: Yeah, alright. So, this is, this goes swapping. So what you can do is that, you know, wasn't a while, you would do this you swap data out to the desert, and then you can bring it back in. Yeah. 121 00:17:33.930 --> 00:17:40.530 William Cheng: Alright, the next slide over here says you can swap out all the memory segments. So why would you want to swap out all the memory segment. 122 00:17:40.890 --> 00:17:51.780 William Cheng: Right, so there are programs. I always use the example you have 50 program running on your laptop, some of them. They only run once a day. Some of them only run once an hour, whereas most of time. We don't need this program. 123 00:17:52.200 --> 00:18:01.170 William Cheng: Okay, so in that case we can actually swap out the entire program on to the desk all the memory segment, they will go to the desk right so that will look like this. Right. So this one of the immune register over here again. 124 00:18:01.410 --> 00:18:07.530 William Cheng: They will be all zero, and the organism says that while these are the four places they're actually got that it actually sitting on the desk. 125 00:18:07.710 --> 00:18:17.160 William Cheng: Yeah, so this way when your program run again, what's going to happen the next time is that we're going to get a segmentation fall and then the operating system will bring the memory segment on a distinct memory one segment at a time. 126 00:18:17.520 --> 00:18:24.330 William Cheng: Okay. What if you at that time, you don't have physical memory. So again, what you need to do is you just swap out the data from physical memory onto the desk. 127 00:18:24.600 --> 00:18:33.840 William Cheng: This way you can bring in more data on this into memory, right, I mean, this is the case that we talked about in chapter four, when we sort of tried to map, map one gigabyte. 128 00:18:34.350 --> 00:18:43.260 William Cheng: You know fall into our address space again. We use the same kind of trick right if something is that memory is not what we need, we need to swap it out to the disperse. And then we can actually bring in another 129 00:18:43.980 --> 00:18:55.470 William Cheng: Country another page. Yeah. Alright, so we can swap out all the memory segment over here. So this way you know this program. If you only run run once once an hour. It's not going to take up any physical memory. Yeah. 130 00:18:56.370 --> 00:19:02.490 William Cheng: The second comment over here says we can actually start with all the memory segments as if they were swapped out 131 00:19:03.510 --> 00:19:08.250 William Cheng: Okay, so when we start running a program. Why don't we not bring any data from the desk. 132 00:19:08.610 --> 00:19:15.840 William Cheng: All we need to do is to set up the, you know, set up an operating system data structure to make him look like the whole thing is swapped out there. What do we want to do that. 133 00:19:16.560 --> 00:19:23.910 William Cheng: Well, the reason we need to do that. The reason we would like to do something like that, is that this way when you start your program, it will be really fast. 134 00:19:24.360 --> 00:19:27.210 William Cheng: Right, because if you imagine if you have Microsoft Word in the good old days. 135 00:19:27.690 --> 00:19:35.220 William Cheng: The executable word is a really, really big memory segment you know for the tech segment. So if you just want to copy the data from this into memory. It will take a very, very long time. 136 00:19:35.790 --> 00:19:46.500 William Cheng: Okay. So, this way we can we can we can make it as if the entire memory and segment is swapped out. So this way. I pulled on will start really fast. And once you start running the program that we can actually bring the data that we need it. 137 00:19:47.070 --> 00:19:55.260 William Cheng: Okay, so this way, your organization will appear to be more responsive. Because when you double click on the program, it will appear to that it will run really, really fast. Yeah. 138 00:19:56.280 --> 00:20:01.680 William Cheng: Of course, this is just an illusion. Because in the end, if you really want to use that you still need to bring all the data that you want. Yeah. 139 00:20:03.600 --> 00:20:14.040 William Cheng: Alright. So as it turns out that the second, the second comment over here. This is actually very, very common on the modern days. Pretty much all the operating system are doing that when you start running a program all the data sitting on the desk. 140 00:20:14.280 --> 00:20:18.450 William Cheng: And you try to bring the bring all green only the data that you need. Okay. 141 00:20:21.960 --> 00:20:28.080 William Cheng: Alright, so again the state of structure. So the show your you know that this is how we implement our, the, the, the, the address space. 142 00:20:28.620 --> 00:20:37.320 William Cheng: This one also show you the backing store, right, because if you look at the tech segment over here the tech side which is read only when you try to swap it out to the desk. Where should I go 143 00:20:37.950 --> 00:20:46.440 William Cheng: Well, if it's read only the data should be identical to to what's on the desk. My. So in that case, you can actually use the file object to get the data. So in this case, we don't really 144 00:20:46.740 --> 00:20:50.550 William Cheng: The operating system actually can use this this this data structure to keep track of where things are. 145 00:20:51.000 --> 00:20:56.220 William Cheng: OK. Similarly, for the the data segment over here. If the data segment. If you haven't really modify any data side. 146 00:20:56.640 --> 00:21:07.080 William Cheng: Any data inside your data side, man. Well, in that case, the data is how your data segment is exactly the same as inside executable file wrestling that case, again, you can use the file object over here to get your data. 147 00:21:07.800 --> 00:21:12.390 William Cheng: The example that we have before we have a memory map file and this one we map it read right 148 00:21:12.870 --> 00:21:22.350 William Cheng: Okay. So, therefore, you know, if you want to swap out this particular data. What you can do is I can use the file object over here, right to the file and next time, will you need a data. You can read the data from the file. 149 00:21:23.190 --> 00:21:30.210 William Cheng: Okay, so in that case this is all you need. But what about the heat region over here in the stack region over here. So again, they don't really have a 150 00:21:31.590 --> 00:21:38.040 William Cheng: We have a place to go inside the desk. Okay. So, therefore, in this case, we need to do something special for them now. 151 00:21:38.850 --> 00:21:44.700 William Cheng: Is that on the next slide over here. So the point over here is that, you know, for the heap. A segment and the stack segment over here. 152 00:21:44.880 --> 00:21:55.170 William Cheng: The way that we're going to store them on to the desk is that we're going to use an object to remember where they go. Okay, so this object is no as anonymous object. I guess you can call it the swap object. But again, the typical 153 00:21:55.680 --> 00:22:05.040 William Cheng: Guess Linux and even for our current assignment. We next they use the term anonymous object because you know these object has no file system path. 154 00:22:05.310 --> 00:22:11.910 William Cheng: So therefore, when you try to swap out this entire assignment, what you will do that you will as an anonymous object and then the data will go into your swaps race. 155 00:22:12.840 --> 00:22:22.410 William Cheng: Okay, so, so again the Anonymous. Anonymous object over here, we try to swap out the data. The unknown anonymous RJ will remember it at a location on the desk where the data goes to right. So later on. 156 00:22:22.890 --> 00:22:30.150 William Cheng: If you like the example that we saw over here where you try to bring back the heap segment you as an anonymous object to go to the 157 00:22:31.410 --> 00:22:42.210 William Cheng: Go to the swap part of your desk and then bring the data and now instead of Colonel Danish actually he can remember, you know, not, not this data is no longer sitting on this and now it's actually a city me. Okay. 158 00:22:44.370 --> 00:22:52.260 William Cheng: All right. Ah, so, so I guess I mentioned before that the private and the ship is inside as region over here. So again, the tech segment is shared. 159 00:22:52.500 --> 00:23:05.640 William Cheng: All the other memory segments over here against their private and again when you perform memory map file, you can map it any way you want. You want to map shared you want to map a private we want to map it read only rewrite. You can do it any way you want. 160 00:23:07.530 --> 00:23:14.070 William Cheng: All right, so. So again, this, this picture. I'll be here represent the user address space. So I guess I keep getting the same 161 00:23:14.700 --> 00:23:22.230 William Cheng: Keep getting questions about you know the address space for the Colonel. The Colonel doesn't need an address space. The Colonel is very powerful. He knows exactly what everything looks like. 162 00:23:22.590 --> 00:23:32.100 William Cheng: Okay, so therefore, again, this representation is only for the user space memory. Okay, so, so, so, yeah, the entire you know a program can be swapped out onto the desk. 163 00:23:32.520 --> 00:23:39.420 William Cheng: So that's for user space memory. What about the colonel there. As it turns out, this is operating system dependent or this is a design decision. 164 00:23:39.810 --> 00:23:43.500 William Cheng: In Windows. Some of the kernel memory can be swapped out 165 00:23:43.980 --> 00:23:51.900 William Cheng: Okay, but if you do that, you got to be very, very careful. If you swap out the wrong memory. So for example, if you swap out the code that's going to bring the code back from the desert into memory. 166 00:23:52.140 --> 00:24:02.370 William Cheng: And then once you stop after that is going to be in big trouble. Okay. So, therefore, you know, what will you do things in Windows, something like that, if some of the kernel memory can be swapped out. So, by the way, why would you want to talk about kernel memory. 167 00:24:03.480 --> 00:24:11.490 William Cheng: Okay, well, Windows has a different philosophy windows. Want to make the application as happy as possible. So Windows want to give all the memory to the application. 168 00:24:11.880 --> 00:24:25.050 William Cheng: Okay, so the colonel doesn't really want to hold on to to too much memory. Is there a memory that can be that can be swapped out windows, who actually do that. Okay. But again, they have to be careful you don't want to swap out you know memory that you're not supposed to swap out. Okay. 169 00:24:28.590 --> 00:24:43.950 William Cheng: All right, so that's segmentation. So we're done with the segmentation and now we're gonna we're gonna move on to modern, you know, a virtual memory system where the hardware. We're going to start using paging and no longer will no longer use segmentation, guys. What's wrong segmentation. 170 00:24:45.090 --> 00:24:50.070 William Cheng: OK, so the segmentation is what we just saw before again. 171 00:24:50.400 --> 00:25:00.210 William Cheng: We divide the the the address space into these memory segment the memory segment. Some of them are big. Some of them are small and we use the first fit memory allocators allocate physical memory. 172 00:25:00.630 --> 00:25:04.590 William Cheng: Okay, and first remember alligator is terrible, you'd certainly don't want to use that 173 00:25:05.550 --> 00:25:11.520 William Cheng: Instead of Colonel right so that's one of the reasons we don't want to use segmentation anymore because of the memory allocated problem. No. 174 00:25:12.180 --> 00:25:17.610 William Cheng: One get one horrible thing about the first memory alligator is that it can have external fragmentation. 175 00:25:18.060 --> 00:25:28.020 William Cheng: You're going to end up with physical memory that you cannot use. And that's really wasteful. Yeah, and also first fit you know it's linear search, right. So, therefore, they can do the algorithm can be really, really slow. 176 00:25:28.650 --> 00:25:40.560 William Cheng: So these days. It's not very common, you know, for memory alligator. If you have a religious some kind of a toy optimism, maybe they can use the first memory alligator. Otherwise, everybody's using page today. Yeah. 177 00:25:40.950 --> 00:25:42.420 William Cheng: Alright, so what does paging right so it's a page. 178 00:25:42.930 --> 00:25:52.170 William Cheng: Again, typically we think about a page is four kilobytes in size four kilobytes equal to, to, to the 12 so we're going to divide the outer space into four kilobytes pages. 179 00:25:52.470 --> 00:26:00.660 William Cheng: Okay. So in this case, you know, we will no longer have external fragmentation, but in this case we are going to have internal fragmentation. So again, why do we have internal fragmentation. 180 00:26:00.930 --> 00:26:06.000 William Cheng: Right, so every page over here. So the minimum allocation, just like the buddy system is four kilobytes. 181 00:26:06.450 --> 00:26:13.170 William Cheng: Guys. So, therefore, if you want to only want one bite, you're going to end up getting four kilobytes. So, therefore, you think that you're only using one by but in 182 00:26:13.710 --> 00:26:24.090 William Cheng: This case, the other 4095 bites. They are unusable. So therefore, the unusable is it's unusable memory is inside alligator blog. So, therefore, this is called internal fragmentation. 183 00:26:24.450 --> 00:26:28.230 William Cheng: Right, okay. You have to choose either external fragmentation or internal fragmentation. 184 00:26:28.680 --> 00:26:35.070 William Cheng: So in the end, you know, operating system decide to choose internal fragmentation. Because if you think about it, you have a really, really good memories like 185 00:26:35.940 --> 00:26:40.530 William Cheng: Really big memories that man at the beginning part over here you can allocate four kilobytes at a time. 186 00:26:40.770 --> 00:26:52.740 William Cheng: Only the last part over here, it might have internal fragmentation. So in the end, if you waste a memory. You don't really waste very much, guys. Even though this is a really silly example you only want one by all kind of memory segment is only one by law. 187 00:26:53.760 --> 00:27:01.770 William Cheng: That's very, very unusual. Right. So typically members segment is big enough, you only waste the, you know, you only waste memory in the last page. Yeah. So again, 188 00:27:02.250 --> 00:27:05.190 William Cheng: The way you think about memory is out there contiguous addresses. 189 00:27:05.640 --> 00:27:19.500 William Cheng: Yeah, there were the way you think about a segment is that there. They have contiguous virtual address. So that's why the beginning part over here, they're completely filled with 44 kilobytes pages or only the last one I have internal fragmentation. Okay. 190 00:27:20.970 --> 00:27:32.340 William Cheng: Alright, so now we're going to talk about, you know, paging or talking about what they are and what you know what happens inside the hardware and then on the next lecture, we're going to talk about the operating system support for all these paging hardware. Okay. 191 00:27:35.610 --> 00:27:39.480 William Cheng: Alright, so we're going to map this 32 bit virtual address to physical address 192 00:27:39.930 --> 00:27:50.640 William Cheng: So I guess, you know, so the mapping is done. Depends on how much physical memory you have right you know in the good old days, you have one gigabyte of physical memory. I guess in the really old days, you know, you have 256 megabytes of memory. 193 00:27:51.240 --> 00:28:01.650 William Cheng: So the example that I've given before is that you have one gigabyte of physical memory and your virtual address basis for your four gigabytes of memory. So you're mapping 32 bit two to 30 bit 194 00:28:02.100 --> 00:28:13.770 William Cheng: Yeah, alright. So, so what we're going to do that we're going to divide everything into fixed size pages, we're going to divide virtual address space into fixed size pages. We also going to divide the physical address space also into the same size pages. 195 00:28:14.220 --> 00:28:22.140 William Cheng: Okay, so this way when you perform address translation, what would you do right so here's a virtual address over here the virtual address for 32 bit machine is a 32 bit law. 196 00:28:22.350 --> 00:28:26.670 William Cheng: We're going to divide into two parts, the left part over here is 20 minutes long and again 197 00:28:27.090 --> 00:28:35.760 William Cheng: You know, a page size is four kilobytes. That's equal to two to the 12 so the last 12 beers over here is called the offset it gives you the offset within a page. 198 00:28:36.120 --> 00:28:46.020 William Cheng: Okay, so therefore the beginning part of the beginning 20 minutes over here will give you a page number. So since this one is a virtual address we call the beginning 20 bits over here, a virtual patient number 199 00:28:46.560 --> 00:28:53.100 William Cheng: Okay, so here's got a V VPN or the virtual page number you're going to see this term, you know, over and over and over again. Yeah. 200 00:28:53.880 --> 00:29:01.170 William Cheng: Alright, so what we need to do is that we need to cover this virtual address into a physical address. We're going to keep the last 1212 bits to address. 201 00:29:02.070 --> 00:29:10.920 William Cheng: The address and offset within the page. So the last 12 days over here is going to get copied into a physical address the physical address over here is 30 minutes long. So leading 202 00:29:11.190 --> 00:29:21.300 William Cheng: 18 biz over here is known as a physical page number, right. So again, the number of leaving this over here. It depends on how much physical memory you have if you have 16 gigabytes of memory. They ain't gonna have no 203 00:29:21.570 --> 00:29:31.110 William Cheng: More than 18 beds over here. Sorry, I say 1618 pages over here if you only have one gigabytes of physical memory, which is the netbook that I have in my office. 204 00:29:31.650 --> 00:29:35.640 William Cheng: So in that case, the physical page number over here will be 18 bits law. 205 00:29:36.060 --> 00:29:44.010 William Cheng: Okay, so when we perform address translation. Right. And last time we sort of talked about the concept of virtualization. We're going to convert a virtual address to a physical address 206 00:29:44.250 --> 00:29:53.520 William Cheng: Since we are we are preserving the last four beds. So in this case, all we're doing when we perform a translation is that we're going to convert the virtual page number into a physical page number 207 00:29:54.450 --> 00:30:05.490 William Cheng: Okay, so this conversion is done inside the MMU so the job of the MMU is to convert a virtual page number which is 20 minutes long into a physical piece number. So in this example is eight minutes long. 208 00:30:06.810 --> 00:30:15.510 William Cheng: Alright so that is the job of the MMU right. So, again, is that me, we're going to have a bunch of MMU register that tell you how to perform this address translation. Yeah. 209 00:30:16.290 --> 00:30:30.090 William Cheng: Alright so address translation and page, it is you want to convert a virtual page number to a physical page number and the offset within the page will always stay exactly the same. OK, so the offset doesn't change. Okay, very important point. Okay. 210 00:30:32.730 --> 00:30:39.960 William Cheng: Alright so against that, you know, again, we're going to go through some of these important you know terminology you can see down this page, there's some red stop. There are some blue stuff. 211 00:30:40.470 --> 00:30:47.760 William Cheng: Is a very important page. So when we're doing pages. We're going to map. We're going to map a fixed size pages into physical memory. Okay. 212 00:30:48.180 --> 00:30:56.850 William Cheng: So, so, so we're going to map virtual pages to physical pages. So again, the address basis divine two pages, they're indexed by virtual page number 213 00:30:57.240 --> 00:31:00.180 William Cheng: So the way you can also think about is, is that is that, you know, 214 00:31:00.990 --> 00:31:14.010 William Cheng: If I have a 32 bit address over here, I can sort of think about, I have an array of objects every object is four kilobytes in size, whereas in this case, what is the virtual page number here or the virtual page number is simply an array index. 215 00:31:14.430 --> 00:31:22.320 William Cheng: Right. If this number is completely zero you're accessing object number zero which is page zero if this one is all once you're accessing 216 00:31:22.830 --> 00:31:34.740 William Cheng: You know, the, the, the page over here zero x F, F, F, F, F, right, each one of them is for biz four times five is equal to 20 minutes. Okay, so you're accessing so you're using this 217 00:31:35.160 --> 00:31:43.560 William Cheng: Particular rate index. Yeah. So again, another way to sort of think about is that the virtual page number is simply an array index into your address space. 218 00:31:43.980 --> 00:31:51.510 William Cheng: Yeah. Similarly, the physical page number over here is simply an array index. So you take the physical memory divided into four kilobytes. 219 00:31:51.900 --> 00:32:01.710 William Cheng: You know, objects, right, every, you know, every object is it can be actually using a re index the array index over here will be the physical page number. Okay, so no matter how you think about it. 220 00:32:03.150 --> 00:32:04.710 William Cheng: Is it's going to be the same thing. Yeah. 221 00:32:07.110 --> 00:32:14.760 William Cheng: All right, so virtual pages, your address space is divided into virtual pages and your physical memory is also divided into, you know, 222 00:32:15.300 --> 00:32:22.230 William Cheng: You know, a physical pages and the page size are exactly the same. So, therefore, what you need to do is that, you know, when you perform address translation. 223 00:32:22.440 --> 00:32:29.970 William Cheng: You need to have a look up data structure that will map a virtual page number to physical patient number, right. So again, this is the picture that I draw before over here. 224 00:32:30.150 --> 00:32:40.770 William Cheng: You start your the MMU is a look up data structure, given a virtual page number. That's the input, the output is a physical piece number. Okay, so that's the main purpose. Right. Yeah. 225 00:32:42.930 --> 00:32:52.080 William Cheng: Alright, so in this example over here if we have one gigabyte of physical memory are then the number of physical pages going to be equal to, to, to the 18th as over here actually calculate them for you. 226 00:32:52.500 --> 00:32:59.280 William Cheng: This one is page zero page to one page to to to the 18 minus one is this number 262143 227 00:32:59.550 --> 00:33:10.050 William Cheng: So again, it's a really, really big number. So you can again you can sort of think about this physical memory, all the things are array index and the object inside the array. Every one of them is exactly four kilobyte small yeah 228 00:33:11.700 --> 00:33:18.060 William Cheng: Alright, so there's important terminology, you're going to see it over and over again, especially when you're doing your colonel colonel three assignment. 229 00:33:18.390 --> 00:33:24.930 William Cheng: It's called a page align address there's what's a patient line address the page align address that means that the offset is equal to zero. 230 00:33:25.500 --> 00:33:34.530 William Cheng: Okay, so if you have a virtual address or you have a physical address. So, this applies to both virtual address or physical address in the last 12 bits which is the asset. They're all zero. 231 00:33:34.950 --> 00:33:41.790 William Cheng: What does that mean that means that you are accessing the first bite you know you accessing the first bite inside of page. 232 00:33:42.360 --> 00:33:50.880 William Cheng: OK, so the address is known as the page align address. So all it means is that the least significant bit of a virtual address or physical address. They're all zero. 233 00:33:51.840 --> 00:34:01.050 William Cheng: Okay, so again, if you look at this picture, every one of these pages. The first memory address for particular page is a page align address. Okay. All the other address. They are not page align 234 00:34:01.410 --> 00:34:10.680 William Cheng: Because they have an offset that's greater than zero. Okay. When offset equal to zero, you have a page line address offset not equal to zero. You don't have a baseline address. Yeah. 235 00:34:11.520 --> 00:34:17.760 William Cheng: Alright, so in chapter seven over here at the beginning part of chapter seven. We're going to talk about some of the hardware mapping techniques. 236 00:34:18.060 --> 00:34:23.040 William Cheng: We're going to talk about what the mm you looks like. Again, there are different kinds of MMU for implementing paging 237 00:34:23.490 --> 00:34:30.420 William Cheng: We also going to talk about, you know, somebody's got to pay stable right we mentioned before. So, you know, here's the pace table over here. 238 00:34:30.960 --> 00:34:37.950 William Cheng: As another piece table mostly is done inside software because remember we talked about a pace the pace table is a colonel data structure. 239 00:34:38.490 --> 00:34:45.480 William Cheng: Okay, so therefore it's a software data structure. Okay, but it's a special software data structure because this data show to is going to be used by the hardware. 240 00:34:46.500 --> 00:34:51.810 William Cheng: Or so, therefore, when he tried to build this. There's actually going to be very careful if you if you have one of the bits that are wrong. 241 00:34:52.170 --> 00:35:00.960 William Cheng: When the hardware, try to use it. The horror will get totally confused. Okay, so therefore against the data structure. The Colonel will bill and it will be used by the hardware and that one is called paste it. 242 00:35:02.160 --> 00:35:10.320 William Cheng: Right. There are other data structure we're gonna take a look at what we're going to take a look at look at look at a probably in the next lecture guy so so today's lecture I'm going to 243 00:35:11.100 --> 00:35:16.050 William Cheng: The rest of today's lecture I'm going to talk about the you know the MMU and all the page tables so 244 00:35:19.710 --> 00:35:28.230 William Cheng: All right, so before I talk about I sort of want to introduce a very, very important term because this term, it's going to be, it's going to cause major confusion and you'll Colonel three 245 00:35:28.920 --> 00:35:34.350 William Cheng: So, and also, you know, when people talk about operating system and they will start using this term called a page frame. 246 00:35:35.040 --> 00:35:41.100 William Cheng: Okay, so what does the page frame as a, as a, so the page. I mean, the analogy I can sort of think of is that the patient is like a picture frame. 247 00:35:41.760 --> 00:35:52.860 William Cheng: Okay, so what is a picture frame a picture frame is a frame that you put a picture in it. Okay, so then what does the page frame a page frame is a object that you put a physical page inside of it. 248 00:35:53.730 --> 00:36:01.380 William Cheng: Guys over here, here's a, here's a picture of PageRank the page where I'm over here. It's a frame is that the spray. There is a physical page. 249 00:36:02.460 --> 00:36:10.320 William Cheng: Okay, so what do you do on a picture frame on the printer. Friends, sometimes you can actually write it on the site. You can write notes on it, you can carve things on it, you can do all had stuff on it. 250 00:36:10.530 --> 00:36:19.230 William Cheng: Okay, so we're going to do exactly the same thing on the page frame the page frame is the data structures are on this data structure, we can write any notes that we want on this page right 251 00:36:20.100 --> 00:36:23.400 William Cheng: Okay so different operating system. There was store different stuff inside the page frame. 252 00:36:23.880 --> 00:36:31.710 William Cheng: When you're working on the winnings often uses and the page name is going to be a very, very important object, you should look at the patient object. Look at all the fields. And then, you know, part of your 253 00:36:31.980 --> 00:36:37.770 William Cheng: Assignment is to make sure that you implemented a patient object correctly and they will be used to tie a lot of stuff together. 254 00:36:38.430 --> 00:36:41.700 William Cheng: Guys will get into Patreon is a very, very important data structure now. 255 00:36:42.330 --> 00:36:51.780 William Cheng: So what's inside of us. So again, the PageRank data structure is used to maintain information about physical pages and their association with important data structures. 256 00:36:52.140 --> 00:36:59.430 William Cheng: Guys, with a patient matching is want to actually tried a bunch of stuff together. We saw inside the address space right there's as region that's important data shelter. 257 00:36:59.610 --> 00:37:04.320 William Cheng: And then what it will point to is that, you know, they will point to all these follow up, Jay, they'll point to anonymous object. 258 00:37:04.650 --> 00:37:11.280 William Cheng: To keep track of where data goes on to the desk there. And then we're going to see that later on we're going to see some, you know, some object that has page frames. 259 00:37:11.760 --> 00:37:19.020 William Cheng: So the page trends over here is where you actually, you can you can actually if you use the patient object, you can find out where data is stored in a physical memory. 260 00:37:19.950 --> 00:37:23.490 William Cheng: Okay. And also, there are some other use, you know, for the page object. Yeah. 261 00:37:24.270 --> 00:37:39.450 William Cheng: Alright so this one, it says that the patient market contain the virtual address for reading and writing to this particular page. Yeah. So again, the pictures like this, we have a page frame that's around a physical page. How do you write data into this particular the physical page. 262 00:37:40.680 --> 00:37:46.230 William Cheng: Well, we mentioned before is that if you even if you are the Colonel. If you have a physical address. There's nothing you can do. 263 00:37:46.680 --> 00:38:02.190 William Cheng: Okay, you will not be able to write data into a physical page. Okay. So, therefore, the job of the page frame is to provide a virtual address that allow you to write this physical page. OK, so the patient of object is an object that knows the virtual address for writing into a physical page. 264 00:38:03.300 --> 00:38:08.760 William Cheng: Okay, because without that the Colonel. Can I write any data into the physical page and also the Colonel. Can I read data from the physical page. 265 00:38:10.050 --> 00:38:12.510 William Cheng: Okay, so what is the current want to read it off on the physical page. 266 00:38:12.930 --> 00:38:20.370 William Cheng: Well, so for example, you ask this to transfer data from the disk into memory when it turns with this data into memory is going to sit inside of page. 267 00:38:20.610 --> 00:38:27.360 William Cheng: Wow. So then what you need to use. I need to put a page frame around it. Why super patient and around it, it will give you a colonel virtual address 268 00:38:27.540 --> 00:38:32.670 William Cheng: Using the colonel virtual job, you will be able to read the data that just got transferred by the disc into physical memory. 269 00:38:33.540 --> 00:38:41.010 William Cheng: Okay, so without the pace frame object. There's no way for you to actually, you know, figure out what virtual address to use to read the data from this particular page. 270 00:38:41.250 --> 00:38:47.610 William Cheng: Now, similarly, when you try to write it down to this. How do you actually filled this particular page with data. Well, then again you need 271 00:38:47.790 --> 00:38:57.210 William Cheng: You to Colonel virtual address and you use that address to write all over this page. And when you're done you tell that this is hey now copy this data from the physical page from a physical page. 272 00:38:57.660 --> 00:39:05.280 William Cheng: You don't want to do this, right. So, why do you have to tell it to to write the right data from physical page because the data I need to go over the bus and 273 00:39:05.640 --> 00:39:14.310 William Cheng: That the you know the disk controller is going to be a DMA device, so therefore it will use a DMA operation where you use DMA they can only use physical address 274 00:39:15.270 --> 00:39:20.760 William Cheng: Man, so therefore the page frame is an important bridge that connects between physical address and virtual address 275 00:39:21.060 --> 00:39:28.050 William Cheng: Okay, when the colonel tried to read and write memory. It has used virtual address when the disk controller need to copy data, it has used physical address 276 00:39:28.560 --> 00:39:31.200 William Cheng: Okay, so therefore, again, the page object is very important. 277 00:39:31.920 --> 00:39:39.600 William Cheng: Alright, so the patient objects contain the virtual address that the colonel can use to read and write to that particular page. It also contains a physical piece. I mean, 278 00:39:39.930 --> 00:39:52.020 William Cheng: This picture I sort of draw a physical page actually you don't need that. All you need is the verb is the physical patient number, right, because if you take the physical page number if you left shifted by 12 minutes. What do you get you get a page aligned physical address 279 00:39:53.130 --> 00:39:57.960 William Cheng: That. So again, if you look, go back to the previous picture over here. Let me clean this up a little bit. 280 00:39:58.770 --> 00:40:02.880 William Cheng: Okay, if you have a physical page or if you have a physical page number over here. 281 00:40:03.540 --> 00:40:10.020 William Cheng: So if you go to the patient will give you a physical page number. If you take the physical page number over here, you left shifted by 12 beds. 282 00:40:10.200 --> 00:40:15.930 William Cheng: And when you do a left shift, you're going to get the offset or equal to zero. So you're going to end up with the page align address 283 00:40:16.860 --> 00:40:27.030 William Cheng: Okay, so therefore, all you need to do is to remember what the physical page number and anytime you want a physical address you left shifted by 12 beds. You got a page in line address if you want to add any offside are into it, you can actually do that. 284 00:40:27.780 --> 00:40:31.590 William Cheng: Guys, but again the page frames of every important object that keep track of this 285 00:40:32.280 --> 00:40:39.480 William Cheng: That what's even more important is that there's a one to one mapping between page friend and allocate a physical pages. 286 00:40:39.870 --> 00:40:45.660 William Cheng: Yeah. So the basic idea over here is that every time where you allocate a physical page. How do you allocate the physical page. 287 00:40:46.530 --> 00:40:48.120 William Cheng: You ask the buddy system for it. 288 00:40:48.930 --> 00:41:00.210 William Cheng: So remember what the buddy system do right but but this is then it built this you know tree data structure and would you do that you ask for a page from the buddies, is that every time you allocate a page, the first thing you do is that you stick it instead of pastry. 289 00:41:02.070 --> 00:41:10.410 William Cheng: Okay. So whenever you call, you know, I guess you're doing you know we makes you probably saw something that could allocate a page. Every time you will get a page. Would you do that you stick it inside of patriot. 290 00:41:11.070 --> 00:41:14.790 William Cheng: Guys so this way you have to Colonel virtualize you can actually read them right to that page. 291 00:41:15.120 --> 00:41:26.280 William Cheng: You also you can actually pass the physical page number to the device driver and they can transfer data. Okay, and what's important is that there's a one to one correspondence between a patient object and the corresponding physical pages. 292 00:41:27.390 --> 00:41:34.710 William Cheng: Okay, because every time we allocate. Why, you ask the buddy system for physical page you stick it inside a page rank and also the buddy system was will you know what 293 00:41:34.920 --> 00:41:40.440 William Cheng: When the bus is that returning a physical piece to you. It will also tell you what Colonel virtual address that you should use 294 00:41:40.800 --> 00:41:48.420 William Cheng: To to read and write that particular page. So again, the patient object where we will the patient object will remember that. Yeah. Alright. 295 00:41:49.380 --> 00:42:00.780 William Cheng: So unfortunately, since there's a one to one mapping between patron and physical pages, you're going to see this all over the place. We're going to use the term page frame and physical page interchangeably. 296 00:42:01.530 --> 00:42:06.780 William Cheng: But guys, why do we do that. Well, it's because that's how often this is when people talk about operating system. 297 00:42:07.320 --> 00:42:12.420 William Cheng: Because unfortunately that's how they talk about it you when you try to read the textbook you'll see that the textbook, does the same thing. 298 00:42:12.720 --> 00:42:17.220 William Cheng: Sometimes, will you be flexible. You say it doesn't make sense. Why is the upper the textbook talk about page rain. 299 00:42:17.430 --> 00:42:25.530 William Cheng: When it's clear that is talking about a physical page. Well, it's because there's a one to one correspondence. So you can actually use the term page frame to refer to physical page. 300 00:42:25.740 --> 00:42:31.410 William Cheng: Okay, and sometimes they would use the word physical page because it, what is it talking about is talking about Colonel data structure. 301 00:42:31.620 --> 00:42:40.290 William Cheng: One. So, in that case, again, it's okay to do that because there's a one to one correspondence between the physical page and the page, right. Okay, so we're going to see that in the 302 00:42:41.490 --> 00:42:44.700 William Cheng: You know, for, for the rest of the semester on the lecture slides. 303 00:42:45.360 --> 00:42:51.180 William Cheng: You know, we're going to see the word physical page and the word page rain that are used interchangeably. 304 00:42:51.450 --> 00:42:58.320 William Cheng: Okay, and that's because, you know, that's how princes and people talk when somebody use the word term PageRank. You need to sort of think about the contacts. 305 00:42:58.560 --> 00:43:04.980 William Cheng: And try to sort of figure out whether they're talking about the patient objectives or the kernel or they're talking about physical page. 306 00:43:05.550 --> 00:43:16.500 William Cheng: Yeah. Alright. So over here, I say, you know, there's a one to one mapping between patient and the allocated physical page. Why do I say is allocated right because if it's not allocated its own by the buddy system and it's a free page right 307 00:43:17.190 --> 00:43:21.540 William Cheng: Where I mean, again, I'm sorry, use the word free page right at the free patient actually doesn't make sense. 308 00:43:21.900 --> 00:43:34.980 William Cheng: Okay, so get free page for me as a free fiscal page if it's free. That means it belongs to the buddy system and you know obviously some places. It was a free page right and that's okay because you know page frame and physical page, they're interchangeable. 309 00:43:36.030 --> 00:43:40.560 William Cheng: Guys it's unfortunate, but this is how you know how we're going to talk about it. Yeah. Alright. 310 00:43:41.550 --> 00:43:45.930 William Cheng: So, so another super important use for the patient without the pace friend can be shared. 311 00:43:46.230 --> 00:43:54.540 William Cheng: By one can be shared. Right. So if you think about a text like man in the tech segment you have many, many programs tried to share the same data and the same data is going to sit in a physical memory. 312 00:43:54.900 --> 00:44:04.860 William Cheng: Okay and this physical memory is going to be maintained by the page frame object or managed by the patient of object or so, therefore, you know, this particular patient will be shared by multiple user processes. 313 00:44:05.370 --> 00:44:12.480 William Cheng: Okay, so this is why this data searches. So I'm getting a little messy because the patient object now can be shared by multiple user processes. 314 00:44:13.500 --> 00:44:20.040 William Cheng: Okay, so this is going to be one of the more complicated data structure that you will see in your kernel assignment okay because of all the sharing that's going yeah yeah 315 00:44:21.450 --> 00:44:30.180 William Cheng: All right, I have a weird note over here. I said, this is the waning. So for Colonel three incredible three a weapons that we saw, you know, Colonel three, you're going to see something called a page now. 316 00:44:30.930 --> 00:44:43.230 William Cheng: Okay, it's called paste on Ph. D mem over here. It's part of a, I guess it's part of the patient data structure. So, please understand that page now has nothing to do with virtual page number of physical piece number 317 00:44:43.920 --> 00:44:50.400 William Cheng: Okay, a page number over here, it's typically a small small array index to go from 0123 runs 318 00:44:50.970 --> 00:44:59.880 William Cheng: And things like that guy. So you'd go to Colonel three we're going to introduce the panel three to you at that point we're sort of going to clarify what exactly what a page that I'm is or if you want to 319 00:45:00.240 --> 00:45:08.400 William Cheng: You know, get a head start. You can read the kernel three FAQ will actually have a lot of stuff explaining what a paste them is because that's a major confusion. Right. So again, if you go back to the 320 00:45:08.640 --> 00:45:13.440 William Cheng: Previous Page over here the virtual page number over here. Typically, you know what a virtual base number look like 321 00:45:13.890 --> 00:45:21.510 William Cheng: Well, so again this is a, you know, this is part of your address space. And if you think about your stack segment the virtual page number is a really, really big number. 322 00:45:22.170 --> 00:45:29.340 William Cheng: Yeah. What about the physical page number over here. What depends on your buddy system, your buddy system allocate these pages, the buddy system allocate random 323 00:45:29.910 --> 00:45:38.130 William Cheng: As far as you know what it looks like at a allocate a random, you know, physical page number. So the physical page number OBO can also be a very, very large number 324 00:45:38.850 --> 00:45:45.690 William Cheng: OK, so the virtual page number and the physical page number. They're typically they're pretty large the paste. I'm over here instead of pace. Right. 325 00:45:46.890 --> 00:45:52.890 William Cheng: There, it's a typical it's an array index. So therefore, typical is a very, very small number go from zero to 20 and that's about it. 326 00:45:53.460 --> 00:46:02.970 William Cheng: Okay, so a lot of the colonel bugs and I stopped before is that, you know, people will store really large number into page, Tom, what if you do that, you're going to get a rise out of bounces are pretty soon you're going to crash. 327 00:46:03.780 --> 00:46:10.560 William Cheng: Okay, so therefore, again, it will in the kernel. When you see paste up. It's a small array index, not, not a virtual page number and not a physical page number 328 00:46:10.980 --> 00:46:16.560 William Cheng: Okay, right, the version number is called VF N or is this call. I'm as a VF N already 329 00:46:17.040 --> 00:46:28.200 William Cheng: You know, before I say VPN is a virtual page number. So why is the color bfm right because page frame pages. They're what they're used interchangeably. So some people will refer that as a virtual frame number 330 00:46:29.160 --> 00:46:39.750 William Cheng: Because again inside of frame. There's a physical page. This was go page can be shared by many, many, you know, user processes. So therefore, again, they're they're sharing the same page. Right. Okay. 331 00:46:45.720 --> 00:46:53.940 William Cheng: All right, I think this is the last thing about patient patient and perform a very, very important function is performed look up on June, so look up again is that, you know, 332 00:46:54.330 --> 00:47:00.480 William Cheng: It's like a map data structure, you know, given X. He tried to look up why right so again in Colonel to you're going to perform this look of operation. 333 00:47:00.960 --> 00:47:08.190 William Cheng: There are lots of look up data structure right my for to listen to look up data structure, given the key you try to find values or I can always 334 00:47:09.510 --> 00:47:10.320 William Cheng: Look up data structure. 335 00:47:10.950 --> 00:47:18.360 William Cheng: That so PageRank is also look up data structure. Okay. They actually perform two kinds of look at one is called a forward. Look up. So what does the phone lookup. 336 00:47:18.570 --> 00:47:28.950 William Cheng: Given a virtual page number you can convert that into a physical page number, right. And again, that that does sort of typical us. So the for look up over here is that given a virtual address of a process, find the page frame. 337 00:47:30.060 --> 00:47:34.950 William Cheng: Okay. So, therefore, what is that the pace frame. There's a lot of pace frame right every, every patient object. 338 00:47:35.130 --> 00:47:45.960 William Cheng: Has a physical page. So in the end, if all the page. All the physical page are allocated, you're going to end up with gazillion Patreon objects. Okay, so therefore the data structure for managing Patreon is typically very, very complicated. 339 00:47:46.260 --> 00:47:56.070 William Cheng: Okay, this could be a hash table. This could be a tree or something like that. So in that case, you need to find a particular page, right. How do you do that. Yeah. So, given a virtual address, find the corresponding page right 340 00:47:56.850 --> 00:48:08.790 William Cheng: Okay, so that's called for look up right so so if you, you know, so. So for example, when you are when you got a baseball. Okay, you're gonna walk down your, you know, address space representation with your which is your link list of as region. 341 00:48:09.180 --> 00:48:15.900 William Cheng: Then what you need to do is that you need to look for page frame. So in that case, you're going to look at us. It's kind of data structure for you to find the page, right. 342 00:48:16.350 --> 00:48:27.990 William Cheng: Yeah. Alright, so let's go forward. Look up the other one is called reverse lookup if we start with the pace friend. We need to find all the user processes that are using this page right. Okay, so in this case it's going to be 343 00:48:28.620 --> 00:48:34.710 William Cheng: So, so the first before look up over here is going to be a one to one mapping why I probably shouldn't say that. One more. One more. 344 00:48:35.340 --> 00:48:43.140 William Cheng: one to one mapping it can be one to nothing mapping if it turns out it's a valid virtual address in that case, when you perform I look up operation, it will not be corresponding anything 345 00:48:44.070 --> 00:48:50.640 William Cheng: Okay, but if correspond to something, then look up will be successful. So the first four lookup can be successful or can fail. 346 00:48:51.090 --> 00:48:56.070 William Cheng: Then the second one will be as a little reverse lookup. It's a one to many operation because 347 00:48:56.610 --> 00:49:09.900 William Cheng: If you start with the PageRank. You need to be able to find all the user applications are sharing this page object that's okay. That's called reverse lookup given a PageRank find processes and virtual addresses that map to this page right 348 00:49:11.250 --> 00:49:21.480 William Cheng: OK. So again, you have a page ran this patient is shared by multiple user processes and every user process. There are many, many memories segment. So what you're trying to find out is that for this particular patient object. 349 00:49:21.720 --> 00:49:25.800 William Cheng: Which processes are using it and which memory segments actually using this particular page rank. 350 00:49:26.670 --> 00:49:32.910 William Cheng: Or as it again the data structure is complicated. Yeah. So when it's patient data structure is a bit involved. That's an understatement. 351 00:49:33.810 --> 00:49:45.270 William Cheng: The Colonel must use a virtual address to write into a physical page numbers again from the page frame, you can actually find the virtual address with the colonel and the Colonel can actually use that virtual address to read and write to a page. Yeah. 352 00:49:46.260 --> 00:49:51.150 William Cheng: So, so, so, so, so once you start doing that, you're going to get a pointer and then you got to be able to add 353 00:49:51.480 --> 00:49:59.190 William Cheng: An offset into. So you're going to end up doing a lot of pointer math. And so again, the kernel is going to be a lot more complicated because of all these things that you have to do. Yeah. 354 00:49:59.550 --> 00:50:02.940 William Cheng: Alright, so, so again you when you start doing a colonel three 355 00:50:03.360 --> 00:50:13.140 William Cheng: One of the first thing that you should do is to read the for Colonel three FAQ because a lot of stuff that even though you don't understand what they're talking about, but it's again it's a good to actually start reading them so so so later on. 356 00:50:14.130 --> 00:50:20.670 William Cheng: You know when you when you got started because they're all remember that. Oh, I saw that actually in the kernel FAQ. I'm going to go back and read it again. Yeah. 357 00:50:24.060 --> 00:50:30.840 William Cheng: Alright, so, so that's Patreon, whereas, I'm going to forget Patreon for a while and now we're going to sort of talk about address translation using paging 358 00:50:31.410 --> 00:50:41.700 William Cheng: Okay, so here is the basic address translation, you know, scheme, right. So, so this is known as the basic page table. This is there a sort of a, you know, the 359 00:50:41.970 --> 00:50:48.570 William Cheng: The basic representation of Asia. Well, it also known as a two level paste a ball. It's called to level because we're going to take the virtual address 360 00:50:48.780 --> 00:50:57.360 William Cheng: We're going to chop it into two parts, guys. Later on I'm chopping into three parts, or even more parts, guys. And now we're okay. The virtual address which up into two parts, which is what we did before. 361 00:50:57.690 --> 00:51:04.260 William Cheng: We take the virtual address over here, chopped into two parts, the beginning part of you has 20 minutes long. It's called a virtual page number 362 00:51:04.680 --> 00:51:17.430 William Cheng: The remaining part over here is called an offset. Okay, so yeah that's that's top is long, because the page size. So again, as far as this cost is concerned, and anytime we don't say anything special. All the page size or four kilobytes law. Okay. 363 00:51:18.750 --> 00:51:27.390 William Cheng: All right, so, so wait for for other translation over here is that we're going to use the virtual page number it use it as an array index and that will access the page table. 364 00:51:28.380 --> 00:51:38.070 William Cheng: Guys, remember, the patient will mentioned before, there's a 1 million entry right so to to the 20 years 1 million. So what you will do is that you will use the virtual page number over here as an array index. Whereas, okay. 365 00:51:38.280 --> 00:51:46.830 William Cheng: The virtual page number over here, equal to zero, that means that you're accessing the first entry into your purse table to be equal to y, actually, you know, re index number why you said ah 366 00:51:47.130 --> 00:51:53.700 William Cheng: The last entries over here is going to be true to the 20th minus one, guys. Okay, the page table over here is a very, very big data structure. 367 00:51:54.150 --> 00:52:05.370 William Cheng: It has 1 million entries or or 220 countries. Yeah, every data, you know, so it's a real data structure every these data structure. I mean, the name is not very creative is known as a page table entry. 368 00:52:06.450 --> 00:52:17.430 William Cheng: Okay, so it's an array A PIECE table entry right if you have an array index, I will give you a page table page. They were entry right so again it's a lookup functioning. But implementing using array. Right. Given a virtual page number 369 00:52:17.700 --> 00:52:25.440 William Cheng: I will give you a page table entry right. What is that a page that we're entry was inside the page table entry is everything that we have saw before, from segmentation. 370 00:52:26.490 --> 00:52:37.890 William Cheng: Lady does India, we want to use paging to implement all those great functionality that we saw before. In segmentation. So, therefore, if you take a page table entry or over here on the right hand side over here I blow it up to see what's inside of it. 371 00:52:38.370 --> 00:52:48.450 William Cheng: Yeah, there is the validity bit. That's the last thing we talked about to implement swapping guys okay if we equals to one that means that this page table entry every entry over here is 372 00:52:48.990 --> 00:52:55.680 William Cheng: Every bit over here is valid. Okay, so if equal to y is equal to zero, that means that the entire entry over here is invalid. 373 00:52:56.130 --> 00:53:00.930 William Cheng: So again, if you perform address translation, you take the virtual page number over here, use an array index. 374 00:53:01.200 --> 00:53:08.100 William Cheng: Access the page table. If you see me equal to zero. What do you do you tap into the opposite, right. So in this case, you cannot, you can get a fault and you talk 375 00:53:09.090 --> 00:53:14.070 William Cheng: Yeah, right. The second bit over here. So the second bit over here. We actually haven't seen it. 376 00:53:14.520 --> 00:53:20.940 William Cheng: This one is a little weird, called a modify. You know, it's called a modified bit so I have to modify a bit overkill equals two, one 377 00:53:21.180 --> 00:53:27.570 William Cheng: That means that the could the corresponding physical page. So get the job of the address translation is take a virtual page number 378 00:53:27.780 --> 00:53:33.660 William Cheng: Translate into a physical page number and then we're going to extend it with the added the offset. We're going to end up with a physical page. 379 00:53:34.050 --> 00:53:44.730 William Cheng: Okay, so if the physical page has been modified the M over here will be set to one. But guess what does it mean to modify modify, meaning that this page is different from what's sitting on the desk. 380 00:53:45.840 --> 00:53:51.720 William Cheng: Because remember we talked about the address space right you know every memory. Suddenly, you can actually talk them out onto the desk when 381 00:53:52.080 --> 00:54:01.380 William Cheng: You know, once you bring in that page from this into memory. If you have a modify it. What that means that the data in, you know, the data in memory is going to be exactly the same as data on desk. 382 00:54:01.950 --> 00:54:12.780 William Cheng: Okay. So, therefore, if n equals zero. That means that they are the same in men, n equals two, one, that means that there are modify. So in this case, if you need to swap out this page, what do we have to do. Well, you have to actually write it on to the desk. 383 00:54:13.230 --> 00:54:19.860 William Cheng: Okay if m equals zero. He tried to swap it out. What do you do well. There's nothing to do, because the data is exactly the same on this, you can just get rid of it. 384 00:54:20.520 --> 00:54:27.780 William Cheng: Okay, so this way they watch you save you time if you decide to get ready to set a stop on a page. And if this patient on modify while you can just get rid of it. 385 00:54:28.560 --> 00:54:38.100 William Cheng: That alright the next bit over here is no as a reference bed. So, this one will tell whether this page has been used or not, because this is kind of a weird bit over here. 386 00:54:38.760 --> 00:54:45.930 William Cheng: So if this was one that means that this page has been referenced in this equal to zero, that means that this page has never been referenced. 387 00:54:46.920 --> 00:54:53.910 William Cheng: Okay, so it's kind of weird why would you bring in a page you're never gonna you're never going to reference it so again we're going to see how this bit is being used at a later time. 388 00:54:54.450 --> 00:55:01.830 William Cheng: Okay, as this point this one sort of say that the corresponding physical page, whether it has been read or it has been written to. Yeah. 389 00:55:03.180 --> 00:55:08.280 William Cheng: Alright, the next page over here. It's called the protection bit over here, you can see that this one is actually draw a little wider. 390 00:55:08.670 --> 00:55:13.830 William Cheng: Because this one can be can be one big can be too big, can be three bears different CPU has different kind of MMU 391 00:55:14.430 --> 00:55:30.540 William Cheng: So, so this example, it could be two bits, right. It could be, you know, 00011011 so one of them might be read only. The other one will be rewrite and maybe the other ones execute only, you know, some CPU does that. And then the other one will be invalid. I have no idea what what what 392 00:55:31.920 --> 00:55:38.580 William Cheng: What they are putting some CPU, they have more than one bit for for the Intel CPU, the protection bit over here is on one bit. 393 00:55:39.120 --> 00:55:50.550 William Cheng: Therefore, into this is this is either read only. Are we right. Yeah. All right. The rest of the page table entries over here again you need to read the CPU manual. Maybe they have other stuff in them. 394 00:55:51.240 --> 00:55:56.490 William Cheng: So one one nice goes inside the other the page that weren't you over here is going to be the physical page number 395 00:55:56.850 --> 00:56:04.020 William Cheng: Right. So this is how accurate translation work, you use the virtual page number over here as an array index and it will give you the physical page number 396 00:56:04.890 --> 00:56:12.480 William Cheng: Alright, so the additional sessions actually very, very simple. Okay, you take the merger page number use an array index it will give you a physical page number. Yeah. Alright. 397 00:56:14.100 --> 00:56:24.540 William Cheng: So, so again, there's no share or private bit over here instead of page table entries. Again, the paste a while we're here, it's a data shows that the colonel builds it's being used by the MMU okay 398 00:56:25.590 --> 00:56:33.330 William Cheng: Alright, so let's go through the process of actually performing address is a translation here. So again, I don't translate. You got to start with a 32 bit address 399 00:56:33.570 --> 00:56:37.680 William Cheng: And then I need to translate that into a physical address right so what do I do over here. Yeah. 400 00:56:37.920 --> 00:56:46.770 William Cheng: I chopped them into two parts over here, the leading part of years 20 bits. The virtual page number. I'm going to keep the last hope is over here. Okay, I'm going to use a later time. 401 00:56:47.310 --> 00:56:54.060 William Cheng: So this virtual page number over here is going to be used as an array index to to to access the page table. So how do you use that 402 00:56:54.360 --> 00:57:08.370 William Cheng: As an array index. Right. So again, you have to perform pointer math. You need to know the base address of the page table and then you add the offset into this page table so. So in this case, what is going to be the offset. Yeah, the page table entries over here. How big is it 403 00:57:09.690 --> 00:57:17.490 William Cheng: Well, the physical page number. The example that we saw before. It's 18 bit long for one gigabytes of memory. If you have four gigabytes of memory is going to be 20 minutes long. If you have 404 00:57:18.060 --> 00:57:30.120 William Cheng: A gigabyte of memory is going to be 21 big lie. If you have a 16 gigabyte memory is going to be 22 bits law if you add all the other bits together over here so you can sort of think about a page table entry should be, you know, I guess for by law. 405 00:57:31.020 --> 00:57:39.960 William Cheng: Okay, so every one of these pages table and God is going to be four bytes law. So the entire page table has 1 million n g. So, this page table size is four megabytes of memory. 406 00:57:41.370 --> 00:57:46.260 William Cheng: Guys, okay, this is a really, really large Colonel data structure is going to be a four megabytes law. Okay. 407 00:57:46.950 --> 00:57:51.630 William Cheng: All right. So in this case, if every page table and you over here is for buys long or it's almost like an array of integers. 408 00:57:51.930 --> 00:57:54.840 William Cheng: Whereas, in that case, yeah. How do you actually compute an address. 409 00:57:55.050 --> 00:58:04.260 William Cheng: Incidence page table now. So again, we're going to take the virtual page number over here we're going to multiply by four or multiply by the size of a stable energy which is equal to four. 410 00:58:04.470 --> 00:58:11.190 William Cheng: And then we're going to add it to the base address or the page table and this will give us the address of this this page table entry. 411 00:58:11.760 --> 00:58:23.460 William Cheng: Whereas, again, whereas this page table entry this page table entries that you're sitting across the bus. So, therefore, what we actually need that we need the physical address for this page table entry. So how do we get the physical page address of the page table entry. 412 00:58:24.510 --> 00:58:32.220 William Cheng: Well, as it turns out, a little bit tricky. So, so what's what's actually stored inside the MMU has to be the physical address of the page table. 413 00:58:33.030 --> 00:58:41.640 William Cheng: Okay, so the address that we added over here right over here. I say you add the, the, the base address of the page table, but in this case the address has to be a physical address 414 00:58:42.000 --> 00:58:48.330 William Cheng: Now, because if you add the physical address over here, this four gigabytes of memory is going to be, you know, Sydney sittings or physical memory. 415 00:58:48.780 --> 00:58:55.740 William Cheng: Yeah, so if I know the first memory location over here, I can use a virtual page number, multiply by for additive the physical address 416 00:58:56.010 --> 00:59:07.200 William Cheng: Of the of the page table. So this way, I will get the physical address of the page table entry, I will put that onto the bus there. And then this way. I will read a page table entries from across the 417 00:59:08.670 --> 00:59:11.310 William Cheng: Pond across the bus from from inside physical memory. 418 00:59:11.820 --> 00:59:25.770 William Cheng: Whereas okay I joined like this over here, this page table entry is actually sitting in their physical memory. I need a bus cycle to read this page there but entry into my CPU, and I should not reading my CPU reading my MMU because MMU that's perfect address translation. 419 00:59:27.120 --> 00:59:33.480 William Cheng: Okay, so therefore again what the enemy will do is that take the virtual page number and multiply by four. 420 00:59:33.690 --> 00:59:47.040 William Cheng: Added to the base address of the page table. Get a physical address of the page table entry start a bus cycle, read the paper entry into the MMU and then you will check the V bit over here to see if it's valid if it's invalid, it will 421 00:59:47.550 --> 00:59:57.030 William Cheng: Generate a fall, otherwise it will see if the operations that the CPU is compatible with the protection, right, if you're trying to, you know, a right to a read only page. 422 00:59:57.210 --> 01:00:04.260 William Cheng: Again, you can attract into the ordinances them otherwise if everything is compatible. It will take the physical page number over here and know what to do. 423 01:00:04.680 --> 01:00:12.990 William Cheng: The physical page number over here. I need to left shifted by 12 minutes to get a page align address for physical page and then I will add the offset to it. 424 01:00:14.160 --> 01:00:21.060 William Cheng: Whereas, look at the picture I draw over here, right, if I take the physical page number I left shifted by 12 days I'll get a patient I address for fiscal page. 425 01:00:21.270 --> 01:00:26.700 William Cheng: If I add the offset into it. Therefore, this is going to be the address that, that the other the other the that I need. 426 01:00:27.360 --> 01:00:37.260 William Cheng: There. So again, let me review one more time. The job of address translation is to start with a virtual address convert that into a physical address. Okay, so here is the entire school. Yeah. 427 01:00:38.010 --> 01:00:41.430 William Cheng: Now you take the virtual address your chopped up into two parts. 428 01:00:41.700 --> 01:00:50.640 William Cheng: To leaving parts over here 20 bits, called a virtual patient number you multiply by four and you add it to the base address of the physical the physical base address 429 01:00:50.850 --> 01:00:58.020 William Cheng: Of the page table that will give you a physical address of the page table entry, you put that onto the bus you start a bus operation. 430 01:00:58.260 --> 01:01:11.820 William Cheng: And then you read a four bytes of data into the MMU you check the validity bill you check the protection beer. If everything checks out. You take the physical page number left shifted by 12 bits inside the MMU and you add the offset tool. 431 01:01:12.120 --> 01:01:18.180 William Cheng: And now you end up with the physical address. What do you do with the physical address. You go to the bus again and you read and write that memory location. 432 01:01:20.520 --> 01:01:30.000 William Cheng: Okay, so, so that means that you need to go to the bus twice. Right. So yeah, you know, so okay so so when you perform address translation, the MMU is the wind will go to the bus wise. 433 01:01:30.180 --> 01:01:35.580 William Cheng: And when you finish the address translation, while in a way the CPU is the one that actually go to the bus and read the actual data. 434 01:01:37.530 --> 01:01:47.700 William Cheng: Okay, so, so, so, so what is the what is the menu now. Okay, so the MMU has two things in that number one is that it contains the physical address of the page table. 435 01:01:48.660 --> 01:01:56.550 William Cheng: Okay, so the MMU contain the physical address of the page table. It also it has all the hardware that will perform all the address translation. 436 01:01:57.060 --> 01:02:03.990 William Cheng: Okay, so when I say chop this address in half, who's doing that for me was doing that. Who is doing the addition over here, you know, multiply by four. 437 01:02:04.500 --> 01:02:15.360 William Cheng: By four is simply the left shifted by two beds right and you add it to this. Mm. You register over here. And then you start the bus operation you wait for the bus to finish all that is done by the mm you 438 01:02:16.200 --> 01:02:24.750 William Cheng: Guys are mmm you contain the logic to actually run this machine over here to to to to to do all these math and then to start a bus operation. 439 01:02:24.990 --> 01:02:35.220 William Cheng: Read all the data in here. Compare the validity beer culture. The production, Beth. Take the physical page number left shifted by 12 bit add the offset. All these are done by the MMU 440 01:02:36.090 --> 01:02:44.970 William Cheng: OK, so the MMU has a register. It also has a bunch of logic that can perform all these operations. Okay, so that is the MMU when you're doing paging yeah 441 01:02:49.860 --> 01:02:51.930 William Cheng: Alright, so let's go to the next page over here. 442 01:02:53.070 --> 01:03:10.200 William Cheng: Okay, so. So over here I claim that the page table entry is analogous to the base of the inbound register approach. Go. Why is that so what was the base, what the base, the base address is the physical page number left shifted by 12 minutes. That's the base address right 443 01:03:11.670 --> 01:03:15.810 William Cheng: Okay, so if you take the physical page number you left shifting I topic, you can a patient line address 444 01:03:16.020 --> 01:03:26.940 William Cheng: And then that's the address you add offset into it. Well, that's the basic though that's the base register. Okay, so therefore the physical page number is correspond to the base or register. What about the bounds register. 445 01:03:28.260 --> 01:03:31.740 William Cheng: Okay, so when you are using page and you can never be out of balance. 446 01:03:32.910 --> 01:03:44.280 William Cheng: Okay, because the balance always four kilobytes, and the offset over here is 0240 95 so it can never be out of balance. Okay, so when you're using paging it becomes impossible to be out of balance. 447 01:03:44.730 --> 01:03:53.220 William Cheng: Yeah. So over here, there's a common right here. He said that when you're using paging the resolution is low, lower because over here, the resolution over here is that 448 01:03:53.520 --> 01:04:00.360 William Cheng: If you know within a page. If you can access this first memory location within a page, then you can access any memory location onto the page. 449 01:04:01.380 --> 01:04:10.740 William Cheng: Okay, when you were using segmentation is a little different because remember the example that I give a segment can be 300 bytes long can be 500 bytes law if you try to access, you know, 450 01:04:11.040 --> 01:04:14.430 William Cheng: The next bite beyond the end of the memory segment, you're going to get a segmentation ball. 451 01:04:14.820 --> 01:04:24.000 William Cheng: Okay, so when you're using segmentation, the protection boundary is set at the by boundary. When you're using paging the protection boundary is set at the page boundary 452 01:04:24.270 --> 01:04:28.680 William Cheng: Okay, so either you dis out a page is protected or the entire page is not protected. 453 01:04:29.160 --> 01:04:38.100 William Cheng: Yeah, so therefore the resolution of the protection is lower. When you're using paging then we are using segmentation, the resolution of protection is one bite. 454 01:04:38.820 --> 01:04:51.510 William Cheng: Guys over here as well as four kilobytes. So therefore, the resolutions, much lower because those little we're over here, right. So if you have a memory segment, actually. And right here. You can actually go beyond the memory segment over here to access data, is that okay 455 01:04:53.010 --> 01:04:56.430 William Cheng: I mean, once you get into it. Once you get used to it and it's really not that bad. 456 01:04:56.970 --> 01:05:07.200 William Cheng: Okay. Just sounds a little weird, you know, before because we will get used to think about memory segment. But if you think about a memory segment actually consists of pages. Well then, then it's actually OK. OK. 457 01:05:08.190 --> 01:05:18.150 William Cheng: Right. What did you have more than four gigabytes a physical memory is again the physical page number over here at the example that I have is 18 beds. When you have four gigabytes of memory, the physical page over here is going to equal to 20 458 01:05:18.900 --> 01:05:27.810 William Cheng: So all you need to do is to have more bit instead of physical page number. Okay, so actually give it a special name when you have the physical page number more than 25th law. 459 01:05:28.380 --> 01:05:38.310 William Cheng: You are using something called a physical address extension or p. So, inside the the segment register, you know, again, the segment registered inside Intel CPU is special. 460 01:05:38.760 --> 01:05:46.110 William Cheng: The only used by Intel, you actually have to set a bit to say I'm using more than 20 bits of physical address, guys. Anyways, that's how they remember it. 461 01:05:48.600 --> 01:06:02.820 William Cheng: All right. As I mentioned before, the page table is a colonel data structures sitting in memory. So the, so this data shark is four gig. You know, it's four megabytes in size. Okay. It doesn't go into the CPU. Okay. It doesn't go into the interview because too big. 462 01:06:03.930 --> 01:06:12.150 William Cheng: Okay. So, therefore, you know, so yeah, so. So this is just a kernel data structure is sitting across the bus sitting inside memory. So what goes into the MMU 463 01:06:12.570 --> 01:06:20.310 William Cheng: The MMA only takes one page table entry at a time. Okay. So, therefore, what goes into them and news is one page. They weren't is only for bite at a time. 464 01:06:21.450 --> 01:06:25.950 William Cheng: Okay, so that's important to understand that the page table is not sitting in study and then you there. 465 01:06:26.310 --> 01:06:37.080 William Cheng: Are so during other translation. We need to read a page table entry. Again, you're going to see the word P many, many times everywhere there's P PDs that web page table entries for by as long country all this kind of information. 466 01:06:37.740 --> 01:06:39.540 William Cheng: So you're going to read the PDF from across the bus. 467 01:06:39.780 --> 01:06:49.380 William Cheng: At the end of the address translation, you're going to access memory. One more time. So in this case, once you finish address translation and gotta figure address. Once you have a physical address, you're going to go to the bus. The second time. 468 01:06:49.890 --> 01:07:05.190 William Cheng: Okay, so when you are using paging every time when you try to access memory location. You know, so it will say, well, when you provide need to access memory location, you have to go to the bus twice the first time is actually done by the MMU and the second time is done by the CPU. 469 01:07:06.810 --> 01:07:12.120 William Cheng: Alright, so that's the cost of pain of doing paging is 100% overhead. 470 01:07:13.140 --> 01:07:24.390 William Cheng: Okay, so let me say that again. Normally when you try to access memory you only go to the bus ones. And now you have to go to the bus twice because using paging so paging is you have to slow down by one by by 50% 471 01:07:25.410 --> 01:07:32.280 William Cheng: Now guys, so therefore this overhead is terrible later I'll go to sort of see how to actually fix this pretty good over here. Okay. 472 01:07:36.240 --> 01:07:41.550 William Cheng: All right, the location of the page table is part of the context of a process. Okay. 473 01:07:42.090 --> 01:07:55.590 William Cheng: You see it already, right, you could have one assignment right what's instead of process control blah, right, there's something called page. Page Durfee underscore page dirt. Okay, so, so that is the base address of the page table. 474 01:07:57.720 --> 01:08:01.410 William Cheng: All right, so, so this is, I mean, some people will see that in curtain. What is it, what is it, and then they'll 475 01:08:01.710 --> 01:08:10.980 William Cheng: Want FAQ says what. Yeah. Did you just call this function and everything will be okay right so. So now you know the paste. Are we here is part of the part of the contents of your process. 476 01:08:11.190 --> 01:08:18.690 William Cheng: Will you switch from one process to another, you need to load the MMU register with the content of the page Easter from another process. 477 01:08:19.020 --> 01:08:29.520 William Cheng: Whereas it again. Would you can do is that you can actually grab it again. Again, that you need to get used to using grab grab P underscore pager in your in your precinct kernel source and find out who's using that 478 01:08:30.060 --> 01:08:38.490 William Cheng: That, as it turns out, in the Linux kernel over here, what's inside of the page there over here if you print out this address, you will see that this is a colonel virtual address 479 01:08:38.760 --> 01:08:44.550 William Cheng: That but I just mentioned that inside the CP inside the MMU you need a physical address of the page table. 480 01:08:44.910 --> 01:08:52.710 William Cheng: Well guys will happen is that when you try to you know what we switch on one process to the other. We're going to go to the process process control, blah. 481 01:08:53.010 --> 01:09:05.760 William Cheng: Get the page there over here. And then we're going to perform a lookup function come and you know for for, you know, for, for this particular virtual address. We're going to convert into a physical address and then we're going to assign the physical address into the mm you 482 01:09:07.140 --> 01:09:15.840 William Cheng: Guys, remember, every time when you switch on one process to the other process, you need to load the MMA registered with a different value. Why, here we go. Right, well you switch on one process to the other process. 483 01:09:16.050 --> 01:09:26.610 William Cheng: You're going to go to the pace directory you know that the score pager going to go to paste her convert that address into a physical address and then you need to copy that into the MMU 484 01:09:27.780 --> 01:09:32.490 William Cheng: Okay, so, so instead MMU over here, you actually have a register that store or a physical address 485 01:09:33.240 --> 01:09:38.250 William Cheng: Then for x86 the physical address of the page table is store inside a register. 486 01:09:38.430 --> 01:09:51.060 William Cheng: So there's a register cause CR three and see our three is MMU register, but it's part of the CPU. So now you know that inside Intel CPU. There's one register actually contain a physical address. And that's the car through register. 487 01:09:51.870 --> 01:09:57.960 William Cheng: Because again, if you want to see where see our three years, you can again right using the grip command and you look for lowercase c are three 488 01:09:58.200 --> 01:10:03.240 William Cheng: Inside you pristine kernel source. And then in that case you will find all places they use a car through register. 489 01:10:03.930 --> 01:10:14.520 William Cheng: Okay, and they should be surprised that only a few places are using the car through register. Yeah, because this operation is not done very, very often only way you perform you know process switching switching one process to another process. 490 01:10:19.830 --> 01:10:30.900 William Cheng: Alright, so, so, so, you know, when we provide your sensations are going to think about, you know, all these process, they have their page table. I have a blue process over here I have a blue page table. I have a pink process will be have a piece database table. 491 01:10:31.620 --> 01:10:38.430 William Cheng: Maybe in some openings to send okay you know some optimism, you know, the organism will also have their own 492 01:10:39.060 --> 01:10:47.100 William Cheng: Pace table. And here's the address space of the operating system. Right. So again, you know, we talked about it in, you know, in our assignment, you know, we don't have addresses representation 493 01:10:47.340 --> 01:10:50.790 William Cheng: But maybe their optimism out there that actually has an address face. Yeah, right. 494 01:10:51.150 --> 01:10:57.450 William Cheng: Our physical memory over here. We're going to allocate four kilobytes at a time. So some of this physical page will belong to Colonel 495 01:10:57.630 --> 01:11:05.490 William Cheng: I'm going to call them green, some of them belong to the pink process over here and some of them belong to the blue process over here if every one of them is four kilobytes long 496 01:11:05.850 --> 01:11:14.250 William Cheng: The example that we use is that the blue process, the addresses spaces only 300 bytes law and the pin process over here is 500 bytes long one. In that case, you know, this should be enough. 497 01:11:16.050 --> 01:11:25.230 William Cheng: As it turns out these processes they have bigger address space or somebody outer space by be sitting on this. So when you try to access them. Then we're going to bring them bring an infinite this into memory. Yeah. 498 01:11:25.590 --> 01:11:31.650 William Cheng: Alright. So normally we Internet access em over here, we perform address translation. So I guess this example that I'm using over here. 499 01:11:33.210 --> 01:11:37.080 William Cheng: Let's see what happens over here. Right. I think that didn't color this properly over here. 500 01:11:37.590 --> 01:11:47.100 William Cheng: So, so when you try to access virtual address 100. So again, coming out of the inner core of the CPU. I'm not writing inner core anymore because I understand is that is that, you know, called the CPU. 501 01:11:47.640 --> 01:11:56.790 William Cheng: We're going to regenerate the virtual address right for the blue, you know, for process. A and B over here and we all use exactly the same virtual address now using address isolation. 502 01:11:57.030 --> 01:12:04.500 William Cheng: You know, if you're running the blue process inside the CPU. Then we're going to access data. We're going to use the page table for the blue process. 503 01:12:04.800 --> 01:12:11.400 William Cheng: Or if we're accessing data for the pink process. Then we went up a ladder transition. Using the pink page table. Yeah. 504 01:12:12.060 --> 01:12:24.960 William Cheng: Alright, so here's an example. So let's say that will run the pink process over here, which are the access virtual address 20,000 over here. And again, in this case, you know, we tried to perform address translation. We're going to use the pink, you know, 505 01:12:26.160 --> 01:12:30.630 William Cheng: So, so yeah we switched on one process or the other. We're going to load the MMU register so now 506 01:12:30.840 --> 01:12:36.060 William Cheng: The base address of this page table is now inside MMU so when you perform address translation, you will 507 01:12:36.270 --> 01:12:48.000 William Cheng: It will, it will try to access the page table entry is the page table entry over here have equal to zero, you're going to end up traveling into the you're talking to the ordinances and insert optimism over here, we need to fix this particular page fall 508 01:12:48.720 --> 01:12:58.920 William Cheng: Okay. So this guy is how are you supposed to fix the page for this particular page over here. The equals zero, that means that this particular page. So again, now we're doing page and we're no longer doing segmentation. 509 01:12:59.430 --> 01:13:06.750 William Cheng: Okay, when we talk about segmentation, which I said that the entire segment is sitting on this we are bringing the entire segment and the segment can be really, really big. 510 01:13:06.990 --> 01:13:17.820 William Cheng: Now we're only doing a one page at a time. Right, so that's why there's one called aging. So, this particular page table entry over here, the equal to zero, we need to bring in four kilobytes from the desk into memory. 511 01:13:18.960 --> 01:13:29.790 William Cheng: Okay, right. So over here, I'm going to perform these operations know as pays for all right you try to, you know, perform address translation address translation cannot be done because the equal to zero, the page table entries invalid. 512 01:13:30.330 --> 01:13:39.360 William Cheng: Okay, so therefore we need to tap into the ordinances and we need to fix this particular page for that. Alright, so this is what we do. So again, we have that data structure inside the kernel. 513 01:13:39.840 --> 01:13:48.750 William Cheng: For the address page representation, we need to sort of figure out, you know, where is it inside a linked list right there's a link listed as region over here. So again, we need to walk down that data structure. 514 01:13:48.960 --> 01:13:59.820 William Cheng: Starting with the virtual address of the pace fall look for the memory segment over here to see which one it belongs to. OK. So now every memory segments over here are implemented by many, many page frames. 515 01:14:01.380 --> 01:14:08.760 William Cheng: Whereas when I said again right every memory said one over here, right. So this memory segment here. So let's say this is the example that we saw before. This was one gigabyte. 516 01:14:09.660 --> 01:14:15.660 William Cheng: Okay, so one a big about what we are, how many pays rent. Do you need what we need, you know, to, to the 18th page frames. 517 01:14:16.500 --> 01:14:25.080 William Cheng: Okay, so this memory segment is implemented by to to the 18 page frames are so it's really, really big memory segments are in that case, they had a lot of patient go on to it. 518 01:14:25.530 --> 01:14:36.570 William Cheng: The tech side went over here again depends on how big it is, they are you know multiple patient over here. So what we need to do is that we need to go down this link list over here. Find out the address that you get paid for out which memory segment belongs to 519 01:14:37.680 --> 01:14:42.300 William Cheng: Okay, if you know I guess the example that we saw saw before, was that this one belongs to 520 01:14:42.690 --> 01:14:52.200 William Cheng: The, the heap segment. So again, here's a text, here's the data plus BSS here the heap segment over here we're going to find this virtual dress over here. And then we look at the colonel data structure is that, oh, 521 01:14:52.440 --> 01:15:01.650 William Cheng: This one is actually it's a patient that we know how to handle okay because we know where the data is their story on the desk. Right. So again, what we need to do is that we need to, what do we need to do. 522 01:15:02.160 --> 01:15:08.160 William Cheng: Well, we need to create a page frame object we get out, we need to ask the buddy system for page and we need to put it inside of PageRank. 523 01:15:08.970 --> 01:15:16.950 William Cheng: That. So, therefore, what we do over here is that we need to find a page from over here with needs to ask the buddy system for for, you know, for, for, for free. 524 01:15:17.370 --> 01:15:21.420 William Cheng: Free page and then as soon as we allocate it, we need to stick it inside a page, right. 525 01:15:22.080 --> 01:15:27.240 William Cheng: Okay. And then what we need to do is that we need to ask that this controller to copy data from the disc into memory. 526 01:15:27.570 --> 01:15:31.950 William Cheng: Okay. I mean, this case, this one is a heap segment. So therefore, the data is stored inside the 527 01:15:32.310 --> 01:15:42.150 William Cheng: Store inside the swap space again the anonymous object know where to go, right, this guy's he was started this transfer copying data from a distant memory are kernels, who is going to fall asleep. 528 01:15:42.600 --> 01:15:44.970 William Cheng: We're going to switch to other processes that can do whatever they want. 529 01:15:45.180 --> 01:15:56.160 William Cheng: Eventually when data transfer is completed our Colonel, so I will get woken up when we woke up. We know that the data has been transferred into this memory location over here. So what we need to do is that we need to fix up all the colonel data structure. 530 01:15:56.490 --> 01:16:03.300 William Cheng: And we also need to fix up this page table entry. How do we figure out this page, a big right we need to set V equals two, one 531 01:16:04.200 --> 01:16:10.320 William Cheng: Okay, and for the heat segment you know the the access right over here need to set to rewrite over here. 532 01:16:10.950 --> 01:16:14.610 William Cheng: And also the physical page number, we need to point to this particular physical page. 533 01:16:15.060 --> 01:16:19.230 William Cheng: There. So therefore, in that case what we need to do over here is that when the fix up all this data structure. 534 01:16:19.530 --> 01:16:27.060 William Cheng: After the data has been transfer. And now, Colonel. So I got woken up, we need to fix everything up over here. And now we're ready to go back into the user space program. 535 01:16:27.540 --> 01:16:33.240 William Cheng: Where so right before I go back into the user space program. We need to make sure that the colonel data structure is all in very good shape. 536 01:16:33.600 --> 01:16:40.380 William Cheng: And then we returned back in your user space program, the user space for about what it will do is that, well, again it come inside of Colonel, you know, 537 01:16:41.340 --> 01:16:43.380 William Cheng: Coming out of Colonel because of a page fall 538 01:16:44.010 --> 01:16:53.190 William Cheng: So typically, if it turns into a segmentation fall the corner will kill your program if it turns out if you return from the current online that case it will try that now operation. One more time. 539 01:16:53.640 --> 01:17:05.010 William Cheng: Okay. So in this case, who is returning that particular operation. Well, we actually were in the middle of the MMU operation we perform address translation. So in that case, the MMU actually pick up where he left off. 540 01:17:05.520 --> 01:17:12.270 William Cheng: Yeah. So what do you, what is it will perform address translation, again, you know, virtual address is 20,000 over here we're going to use that page table entry over here. 541 01:17:12.480 --> 01:17:21.420 William Cheng: But the page table entry now have the equal to zero and then the access right over here will be rewrite. So in this case, you can use that address you get data from this fiscal page and 542 01:17:21.870 --> 01:17:30.750 William Cheng: You get, you get you get you get the page table over here from the physical. I mean, oh sorry I draw this picture outside again all this data is are actually insert physical memory. 543 01:17:31.590 --> 01:17:34.230 William Cheng: Now, so again I'm sort of, you know, throw them outside 544 01:17:34.860 --> 01:17:42.810 William Cheng: So, so, so again, you're going to get the data from physical memory. And then finally you finish your address translation, you get a physical address and then you go to memory over here and access data. 545 01:17:43.650 --> 01:17:54.390 William Cheng: Or as a look at this, you know, in this case, you actually have to go to the bus, many, many times, because we have a page fall and things get really, really complicated. Okay, so this is the operation that has to happen during a page fall 546 01:17:55.860 --> 01:17:59.760 William Cheng: Okay, you'll Colonel three, you're going to have the pleasure of implementing a page for 547 01:18:00.300 --> 01:18:12.990 William Cheng: Okay, so this is why this is such an important operation that I actually have to go through all these details to get you familiar familiar with what you have to do, because when you are implementing your kernel three, you have to implement this entire process. Yeah. 548 01:18:16.680 --> 01:18:22.110 William Cheng: All right. Ah, OK. So, so that's, you know, that's address translation and that's also, you know, 549 01:18:23.010 --> 01:18:33.030 William Cheng: Handle paste fall rise and this example the pace or that we saw the equals zero. You can up before address sensation. They also other kind of pace fault. Right. Well, you try to write to a read only memory say 550 01:18:34.080 --> 01:18:41.400 William Cheng: I shouldn't use the word memory segment. Will you try to write to a read only page, right. So he said, yeah, the tech side, man. You have you have a linked list of as region. 551 01:18:41.610 --> 01:18:46.770 William Cheng: The first one over here the tech side, man. The tech segment is implemented using many, many page frames. 552 01:18:47.490 --> 01:18:54.870 William Cheng: Okay, so therefore, when you try to write one of these particular page for a while you're gonna get a segmentation bar right again the segmentation for at the beginning is going to be a peaceful 553 01:18:55.050 --> 01:19:04.260 William Cheng: You come inside of Colonel you walked on this list of as region. You say, Oh, this patient or happen inside the tech segment or you try to write into the tech segment. So therefore, we're going to kill your program. 554 01:19:05.250 --> 01:19:13.350 William Cheng: Right. So again, they're all these different kinds of pace for hours or so. And, you know, as we move on to chapter seven. We're going to talk about more kinds of different kinds of pitfall. Yeah. 555 01:19:14.070 --> 01:19:19.710 William Cheng: Alright, so, so, so we talk about paste. While we're talking about paging what it looks like. How to Play understands Asian 556 01:19:20.340 --> 01:19:26.310 William Cheng: So now we're down with the basic to level page table. So what's wrong with the basic level page but table right so there to problem. 557 01:19:26.520 --> 01:19:37.560 William Cheng: Number one is too slow. There's a 100% overhead because when you perform address translation is going to go to the bus wines and later we dealt with the address translation. You gotta go to the bus. The second time. Right, so it's 100% overhead, then 558 01:19:38.130 --> 01:19:45.780 William Cheng: The other problem is that the page table take up too much space for every process you spend 44 megabytes of memory. 559 01:19:46.260 --> 01:19:50.250 William Cheng: You know, on page table. So on your laptop. If you're running 50 processes. 560 01:19:50.850 --> 01:20:01.170 William Cheng: Everyone that them take a four gigabytes of memory. So that will be you know 200 megabytes of memory. I mean, the good old days, you know, a laptop will have 256 megabytes of memory. So, pretty soon you're going to be out of memory. 561 01:20:01.980 --> 01:20:10.680 William Cheng: Yeah, so we're going to sort of look at these solution to this problem of going to first look at the solution to the space problem. And then we're going to take a look at a solution to the speed problem. 562 01:20:11.370 --> 01:20:17.700 William Cheng: Yeah. And again, there's a space time trade off. So when you try to solve the speed problem is that we sell try to solve the space problem. 563 01:20:17.880 --> 01:20:25.350 William Cheng: The speed problems. I should have done to get even worse and worse and worse than later. And then idea going to solve all the speed problem in one shot. Yeah. 564 01:20:26.070 --> 01:20:34.380 William Cheng: All right, I'm going to pause right now. So that will be the end of the first part of the video. So then we're going to continue, you know, with the second part. Yeah.