WEBVTT 1 00:00:02.190 --> 00:00:04.290 William Cheng: This is the second part of lectures. 2 00:00:05.339 --> 00:00:16.980 William Cheng: So last time we were talking about Linux and today we're going to start with Windows. So again, we don't really focus too much on windows because windows, a proprietary system. 3 00:00:17.640 --> 00:00:25.080 William Cheng: Here's what we know about Windows the windows address space layout for 32 bit process. There are two choices. 4 00:00:25.560 --> 00:00:31.680 William Cheng: Because you know typically Windows is more, you know, they've been around for a long time, they need to give their customer more flexibility. 5 00:00:32.190 --> 00:00:41.940 William Cheng: So there are two choices. One is to, you know, divide the address space evenly between the user space and the kernel space. So in this case, user gets two gigabyte. 6 00:00:42.360 --> 00:00:56.250 William Cheng: The Colonel also get to two gigabyte at the other choices, the same thing as Linux. I do three gigabyte per user. And then one gigabyte for, you know, for, for, for, for, Colonel. So why would you have cases where you know you need a bigger 7 00:00:57.450 --> 00:01:04.860 William Cheng: Sort of a bigger space inside, Colonel. Right. And if you think about the Linux here. What is the Colonel actually require more than one gigabytes of memory to run the Colonel. 8 00:01:05.730 --> 00:01:14.730 William Cheng: Okay, so if you have a 32 CPU. You're allowed. There's no way for you to refer that radical and also it's not very flexible. The only thing you can do is you can run a 64 bit CPU. 9 00:01:14.970 --> 00:01:20.820 William Cheng: Right. So in that case, in that case, the colonel colonel space can be much bigger than Windows. They give you two different configuration. 10 00:01:21.390 --> 00:01:30.540 William Cheng: So I think, typically in the server, you know, soda in Windows Server. They typically have the configuration on this on the left. So this way. The Colonel can be much bigger. 11 00:01:30.720 --> 00:01:35.580 William Cheng: Because support a lot of user processes, while on the desktop you typical to go to see the other configuration. 12 00:01:36.270 --> 00:01:43.560 William Cheng: So again, this is, you know what, when you set up your machine, you have to decide which way you want it. So this is how it goes. 13 00:01:44.520 --> 00:01:47.940 William Cheng: Also, sort of a quick summary of the windows paging strategy. 14 00:01:48.660 --> 00:01:54.630 William Cheng: You know, so for Windows. They actually they use the terminology of working set. But again, this is just an approximation of the working set 15 00:01:54.900 --> 00:02:04.650 William Cheng: As we mentioned last time, the working set principle, even though it's a pretty good idea in reality is very difficult to implement. So what window does is that for every process that guarantee a certain 16 00:02:04.890 --> 00:02:07.950 William Cheng: You know, certain number of pages and they call it. They call it the working set 17 00:02:08.340 --> 00:02:15.090 William Cheng: Okay, so, so, so the philosophy behind window is that if you want. They want to encourage people to write these very, very small program. 18 00:02:15.360 --> 00:02:23.190 William Cheng: If you have a very small program. You don't need too much memory. So in that case whenever you know whenever, whenever you ask what page frame the page, where are your private page for him. 19 00:02:23.490 --> 00:02:29.310 William Cheng: So, therefore, you always have that right so this way you're small program can run very quickly, a bit of all die and then return you know 20 00:02:30.330 --> 00:02:39.810 William Cheng: Return the members of the operating system. Okay. So in this case, you know. So again, you know, there's every, every process has has a minimum guarantee we don't really know what the number is. 21 00:02:40.680 --> 00:02:51.120 William Cheng: But if you process it requires more pages and that then they will need to compete with the global pool guy. So the sort of the example that we mentioned before, as it turns out it was well what what what window windows actually 22 00:02:51.810 --> 00:03:01.830 William Cheng: Implement windows, you know, the page on demand. They use a wild handed club algorithm. So again, that can be you know more aggressive again depend on you know how often you sleep. 23 00:03:02.460 --> 00:03:06.330 William Cheng: They also have, you know, so. So here's one part of Windows very, very different. 24 00:03:06.750 --> 00:03:15.900 William Cheng: They have a swap or threatens the Colonel, there will swap out idle processes and their definition of idle process is that a process that has been inactive for 15 seconds. 25 00:03:16.230 --> 00:03:25.080 William Cheng: Okay, so if you have a program or even a process is not running for 15 seconds What windows will do is that it will be very aggressive they tried to take all your memory. And then they will swap out 26 00:03:26.070 --> 00:03:34.290 William Cheng: Stop the process out of disk. Okay, so this way, they will free up all the pace rain. So the window philosophy is that, you know, we're running Windows, the 27 00:03:34.770 --> 00:03:40.680 William Cheng: I guess there's one application that's the most important application. And that's one that application is the is the active one 28 00:03:41.130 --> 00:03:50.700 William Cheng: Okay, so if you have used windows. You'll notice that whenever you click on an application, it comes to the top. That will be the most important application and windows. Want to give all the resources to that application. 29 00:03:51.300 --> 00:03:57.510 William Cheng: Okay, so all the other ones are running that program, they will try to swap them out as soon as possible, you know, after 15 seconds and then they will 30 00:03:58.080 --> 00:04:03.000 William Cheng: You know they they they they will give the memory 2221222 the one 31 00:04:03.960 --> 00:04:04.740 William Cheng: that's running on the top. 32 00:04:05.130 --> 00:04:12.810 William Cheng: Okay, so you've you've, you have been using window, you will notice that once you are using like Word or Excel for a long time, and anytime you want to switch to a different application. 33 00:04:12.990 --> 00:04:19.920 William Cheng: You can actually hear that this going, I have because what happens that you try to try to bring all the pages from the back end store up that back into memory. 34 00:04:20.790 --> 00:04:29.040 William Cheng: So against this is very, very different, you know, from the Linux flaw philosophy windows even more aggressive they make some of the kernel memory. 35 00:04:30.180 --> 00:04:39.480 William Cheng: You know some of the kernel memory can be paste out. So this way you can actually free out even more memory to give it to the application that they give to the active application. 36 00:04:40.020 --> 00:04:44.550 William Cheng: Okay, so in that because you got to be very careful because because if you if you try to page out, you know, 37 00:04:45.270 --> 00:04:49.560 William Cheng: Some of the colonel component over here. What if you accidentally page on the page. I'll demon 38 00:04:50.010 --> 00:04:58.980 William Cheng: Well, if you page after page demon or you page up a part of the part of the kernel code that will bring that data back from that this into memory. Well, then in that case, nothing will actually bring the data back into memory. 39 00:04:59.670 --> 00:05:08.880 William Cheng: Okay, so in this case there Colonel has to be a little more, you know, the it'd be a little more careful. You got to be able to lock down certain pages so that they will not be accidentally paid out to the desk. 40 00:05:09.360 --> 00:05:14.280 William Cheng: Okay. So yeah, this is sort of a quick summary of the the the window patient strategy. 41 00:05:15.000 --> 00:05:26.670 William Cheng: That window pays frame go to different states, a little more complicated than Linux right lineage just have active inactive and free windows. Again, we're not going to talk about windows too much in this class. 42 00:05:28.050 --> 00:05:37.620 William Cheng: All right, so we finished the representative system we talk mostly about Linux. And we talked a little bit about Windows. So the next thing that we're going to do is look at how to implement copy on write 43 00:05:38.190 --> 00:05:45.030 William Cheng: We mentioned about how to implement copy on write already so so now. Right now we're going to sort of talk about a main problem with copy on write 44 00:05:45.480 --> 00:05:48.780 William Cheng: As it turns out, the main problem copy on write that it needs to work with fork. 45 00:05:49.230 --> 00:06:01.770 William Cheng: Okay, so, so let's talk about for how to implement fork first and then we'll go to sort of bring up the issues of copy on write and fork and then we're going to sort of see, see, see, see what the problems are and what are the solutions for, you know, for for copyright, together with for 46 00:06:03.480 --> 00:06:10.950 William Cheng: All right, so, you know, the semantic a fork is that when you for coffee shop process, the child process, get a copy of the parents address space, right. 47 00:06:11.130 --> 00:06:17.340 William Cheng: Right, so we used to work copy intentionally to mean that you need to make a copy from the pens outer space to the child process. 48 00:06:17.940 --> 00:06:28.890 William Cheng: Space and now both the parent and the child can actually modify their address spaces simultaneously. Okay. But if you do that, as it turns out, is going to be really, really slow and also one of the child processes gonna call exact right away. 49 00:06:29.310 --> 00:06:39.660 William Cheng: Okay, you make a copy of the parent address space if the parent is a really, really big program, you know, you spend all your time making a copy of the entire address race. That means including all the page frames. 50 00:06:40.200 --> 00:06:51.060 William Cheng: That belong to belong to the parent process you're going to make a copy of it. Right. And as soon as you, you know, finish doing that, you're going to call it exactly. You can call the Executive Board and you wipe out the entire address space. 51 00:06:51.900 --> 00:06:56.310 William Cheng: Okay, so in that case all the, you know, all the data you have copy a complete waste of time. 52 00:06:56.850 --> 00:07:03.780 William Cheng: Okay, so, so even though this is sort of these, the most straightforward way to implement for it, but nobody does it this way because it's too inefficient. Okay. 53 00:07:04.410 --> 00:07:11.280 William Cheng: So what are the solutions. Over here, we sort of mentioned, you know, copy on write. That's one way to do it. There's also another way to do it. That's called the virtual fork. 54 00:07:12.060 --> 00:07:22.320 William Cheng: Well, as it turns out, virtual for is the fastest way to forecast the child process. So what they do over here is that when the parent for carpet tile process, the parents actually going to loan the address space to the HR process. 55 00:07:23.160 --> 00:07:28.680 William Cheng: Okay, but he said what they wanted to the parent, the parent doesn't have an address space anymore, so therefore we have to suspend the parent 56 00:07:28.920 --> 00:07:34.800 William Cheng: And then we need to give the address space, the child alone. So this way you know i mean what you know so so 57 00:07:35.250 --> 00:07:41.430 William Cheng: If you go Paul somebody's car when you try to return a call. He has been perfect condition. You're not allowed to mess mess it up. So we have the same kind of problem over here. 58 00:07:41.640 --> 00:07:51.150 William Cheng: If you, if you give your address space to the child process. You got to make sure the child us. It doesn't mess it up when we tell process doesn't mess it up and they tell us is going to call it exactly what the exact system call 59 00:07:51.480 --> 00:07:56.550 William Cheng: What it needs to do is it needs to destroy the address space, but in this case the address based on loan from the partner. 60 00:07:56.790 --> 00:08:02.490 William Cheng: All you have to do is we'll return that that just based on the parent. So this way you know you can actually implement for really, really fast. 61 00:08:02.700 --> 00:08:12.270 William Cheng: That. So this is no as before, right. The advantage of this particular approach that is very, very fast, but the disadvantage is that this only work if the child doesn't exactly if the child doesn't 62 00:08:12.600 --> 00:08:17.880 William Cheng: Doesn't do an exact. Well, then in that case the parent will not be up, up, up, up to execute and so that will be a problem. 63 00:08:18.390 --> 00:08:29.250 William Cheng: Also, the other problem is that, you know, when the child Baldy I just spent the child must make sure that they do that, it doesn't modify the address space, right, because if you if you modify the address space and you return the, I guess. 64 00:08:29.550 --> 00:08:34.830 William Cheng: The parent, the parent will be very surprised that. So as it turns out that this particular 65 00:08:35.940 --> 00:08:46.470 William Cheng: This video characteristics needs to be taken care of by the application programmer, because the application programmer is making the form system call. So therefore, the application programmer needs to make sure that the child process. 66 00:08:46.740 --> 00:08:53.910 William Cheng: doesn't modify the address space, you know, do his mother. My mother modify the outer space all the way until they make the exact system call 67 00:08:55.260 --> 00:09:02.040 William Cheng: Okay, so if you if you're the application programmer, you write the code that we saw before you forgot which are process after a few instructions will call you. 68 00:09:02.310 --> 00:09:07.590 William Cheng: Got to make the exact to the ball. What about the stuff in the middle. Did you accidentally modify the address space. 69 00:09:08.160 --> 00:09:11.010 William Cheng: Okay. So as it turns out, this is actually very, very difficult to determine 70 00:09:11.400 --> 00:09:21.690 William Cheng: It's very, it's too much burden on the application programmer, because they advocate application programmer. What they will do is that it will accidentally modify the address space. So when the address space is returned back to the parent, the parents going to be very surprised. 71 00:09:22.890 --> 00:09:28.590 William Cheng: Okay. So in the end, even though the fork has, you know, it has it that is being very, very, very, very efficient. 72 00:09:29.010 --> 00:09:34.650 William Cheng: The downside. As it turns out, is too much for the application programmers to handle. So therefore, these days, we don't use before anymore. 73 00:09:35.160 --> 00:09:44.160 William Cheng: Okay, so instead we try to make a compromise, you know, between copy the entire address space, you know, versus the V4. And the way we do this is to use copy on write 74 00:09:45.480 --> 00:09:52.650 William Cheng: The copy on write it. Okay. It's an instance of a lazy evaluation, the idea over here is that, you know, so I get that that's a, you know, the 75 00:09:53.370 --> 00:10:03.270 William Cheng: Sort of, remember the definition of a copyright. Well, you try to share something. Read Only you can share all you want, but will you try to write to it for the first time you make a copy and writing for the copy 76 00:10:03.870 --> 00:10:06.540 William Cheng: Okay, so we're going to do is that when we perform the full cooperation. 77 00:10:06.750 --> 00:10:11.880 William Cheng: Instead of making a copy. Instead of using v4, or we're going to do is that we're going to share the parents address space. 78 00:10:12.060 --> 00:10:17.760 William Cheng: Okay, we're going to share the parents address space read only until we write it for the first time, when we write it for the first time. 79 00:10:17.940 --> 00:10:25.740 William Cheng: We're going to do this one page at a time. So when you write one of the page for your, for the first time you're going to try this out a colonel colonel. We're going to make a copy. And we're gonna 80 00:10:26.970 --> 00:10:29.550 William Cheng: We're gonna have all your modification over here. Go into the copy 81 00:10:30.600 --> 00:10:38.310 William Cheng: Okay, so this way you know semantically idea that is over here is that the semantically, this is equivalent to the original form if you implement this perfectly 82 00:10:38.670 --> 00:10:42.870 William Cheng: Okay, so yeah. You started out with sharing everything read only right that is perfectly okay 83 00:10:43.050 --> 00:10:51.960 William Cheng: But as soon as she's had a right to any page for the first time you make a copy of the page and you make sure the modification, going to the copy. So this way, the parent when I'd be surprised. Yeah. 84 00:10:53.190 --> 00:11:05.490 William Cheng: And also this is usually faster than the original form right, especially if you fork and after you do a four, you're going to do an exact pretty quickly. Then in that case, maybe you only modify the address space at a little, you know, in one or two places. 85 00:11:05.670 --> 00:11:10.230 William Cheng: And then pretty soon you gonna call the exact right so in this case you can, you're not going to end up copying a lot of pages. 86 00:11:10.860 --> 00:11:15.840 William Cheng: That this advantage over here is that of course is going to be slower than before, because before you don't copy anything 87 00:11:16.260 --> 00:11:32.790 William Cheng: So that's the fastest way to go. Right. So, so there's no way to go faster than before. So, so this is a slight disadvantage, so, so, so, so that's why in today's all the modern companies is that they all you know us lazy evaluation that all use copy on write to implement for that. 88 00:11:35.640 --> 00:11:45.180 William Cheng: So if you implement better for it. Well, we need to use the copy on raw. So, you know, again, the process gets a private copy of A. So since we're doing page and out right within this one page at a time. 89 00:11:45.420 --> 00:11:56.790 William Cheng: The process, get an old get a private copy of the page. Only after a threat in the process perform the right to that page for the first time. Right. And also there's only happened was once you perform copy or otherwise. From this point on, 90 00:11:57.600 --> 00:12:01.530 William Cheng: The order modification will go into the copy. Okay, so, India, this is still pretty efficient. 91 00:12:01.950 --> 00:12:12.090 William Cheng: OK. So the way we have to do this is that, you know, for that particular page. Page that we're doing copying and right at the beginning when you try to share the page for reading you set the pace table entry over here to read only. 92 00:12:12.420 --> 00:12:15.660 William Cheng: Mode. So this way where you try to riff on that page, you can read as many times as you want. 93 00:12:16.650 --> 00:12:23.340 William Cheng: And know of course, at that point, the address space you're welcome to share, but whenever you try to write to that page for the first time. 94 00:12:23.520 --> 00:12:32.610 William Cheng: Since the PT is set to read only. While in this case you will try things out of Colonel so inside Ricardo, what you have to do is that you need to, you know, call the buddy system to get to, to, to, to 95 00:12:32.970 --> 00:12:41.370 William Cheng: Get a new page and then make a copy of it. And then, you know, fix up the pace table entry and fix up your address space data structure and then and then eventually return back to the 96 00:12:41.610 --> 00:12:53.460 William Cheng: Factory users baseball bat and we return back to the user. This program, they will try it, try it again. So this time, you know, you know, this case they branches over here will be changed to rewrite and the data with the modification of that page will go into the new page. 97 00:12:54.600 --> 00:13:05.820 William Cheng: Okay, so therefore yeah well you try these out a cardinal, how do you know that you have to do copy on write, write the head over here is that when you try to, you know, write to a page and it's read only. Right. So again, this is how you 98 00:13:06.240 --> 00:13:18.630 William Cheng: How you end up with a fault or, you know, the trappings out of Colonel, and then when you walked on that list of VM map as our VM area you find out that that particular VM area is rewrite and it's privately map. Okay. So we write a private 99 00:13:20.400 --> 00:13:24.270 William Cheng: Is sort of a signal for you to say that you need to perform copy. Oh, right. 100 00:13:24.960 --> 00:13:32.520 William Cheng: Okay, so, so again, when we walked on that list of VM area, you need to check the flag over here. And in order for you to determine what is the right thing to do. 101 00:13:32.970 --> 00:13:42.600 William Cheng: Okay, so if you got to pace for for writing to a page. And if it turns out that memory segment is rewrite and privately map, then that means that you're, you need to perform copyright 102 00:13:42.930 --> 00:13:48.870 William Cheng: Okay. What if it's not, you know, privately about what what what is she happy. Why not case. You don't have to perform cumbia copyright 103 00:13:49.770 --> 00:14:00.900 William Cheng: Law now so we use that copy on. Right, right. So we're doing copyright to make to make fork as fast as you sort of as fast as reasonably reasonably possible 104 00:14:01.560 --> 00:14:08.610 William Cheng: Okay, so the copyright must work with for it because all the modern implementation or for all use copied on right so what could be the problem. 105 00:14:09.330 --> 00:14:15.990 William Cheng: Okay. So we mentioned about this algorithm over here, you know, this seems to work. So under what condition does it work under what condition does it fail. Okay. 106 00:14:16.290 --> 00:14:20.580 William Cheng: As it turns out, you know, you know, sometimes you. This is actually good for it at the other, the other one is not 107 00:14:20.820 --> 00:14:27.000 William Cheng: There. So we're going to take a look at this. The this case over here, this is the first guy that actually works. You know, the way we have talked about it already. 108 00:14:27.480 --> 00:14:36.540 William Cheng: So this was probably about being we're going to copy on write occurs after for that. So first of all, I'm going to sort of start with booking a child process. OK. And now we're going to perform copied on right 109 00:14:37.230 --> 00:14:43.770 William Cheng: Okay. So this guy is that they'll get what is copyright right so you want to write to a zoo, you'd write, read your particular page for the first time. 110 00:14:44.250 --> 00:14:51.960 William Cheng: So let's say that on page z over here, there is a goal. Grab over here called data right data if you're sitting over here. So it looks like this over here. 111 00:14:52.740 --> 00:15:02.730 William Cheng: There's a data of equal to zero. And now the parent process over here on the left hand side over here will execute this instruction called data. So these searches that data equal to 17 112 00:15:03.240 --> 00:15:09.120 William Cheng: OK, so again we're stayed over here. So data is in page z. So if you think about the parents page table over here. 113 00:15:09.540 --> 00:15:15.750 William Cheng: So in this example. So this example we have we have a memory segment that's made out of three that's made out of three pages. 114 00:15:16.500 --> 00:15:24.660 William Cheng: OK. So again, what does that memory segment by right so let's say that you have a memory segment or 10 kilobytes inside right here is a memory segment. Here's a VM area right we're 115 00:15:25.140 --> 00:15:35.460 William Cheng: All the terminology Linux where I called VM area. Yeah, I'll be here. So let's say that this particular VM areas or 10 kilobytes long okay we saw before, you know, the 116 00:15:36.300 --> 00:15:46.770 William Cheng: I guess in chapter four, right. We saw you know sort of tech segment over there is that actually get covered by by three pages over here. So again, no. Here's an example. We have a memory segment. 117 00:15:47.010 --> 00:15:54.060 William Cheng: That's 10 kilobytes in size. We need to cover it with three different pages. So here the first one over here is four kilobytes over here in a second. Hope is the fourth pillar by 118 00:15:54.270 --> 00:16:01.530 William Cheng: The last one over here, we only need two kilobytes. But since we're allocating four kilobytes at a time. We're going to end up also covering with a four kilobyte page. 119 00:16:02.040 --> 00:16:07.500 William Cheng: Okay, so we're going to call these three pages over your X, Y, and Z overhears over here is x y AMP Z right 120 00:16:07.680 --> 00:16:13.710 William Cheng: This is the corresponding page table entry for these three pages over here. And then over here, we said I want, you know, instead of page table entry. 121 00:16:13.890 --> 00:16:18.960 William Cheng: What do we have we have validity be equal to one we have read only over here because we're doing copy on write 122 00:16:19.140 --> 00:16:31.860 William Cheng: We also have a physical page number. So the physical page number of your plenty. This one called page z over here. So again, you know, some people can ask, well, what is it, what is actually here is x A virtual page or a physical page. I mean, you know, so we are, we just trying 123 00:16:32.190 --> 00:16:39.000 William Cheng: To join a few slides over here we're going to, sort of, you know, assume that this x over here can be a virtual page. You can also be a physical page. 124 00:16:39.300 --> 00:16:43.020 William Cheng: Okay. It depends on what picture you draw X, sometimes referred to a virtual page and 125 00:16:43.290 --> 00:16:50.520 William Cheng: Sometimes there's going to refer to it to a physical page that. So in this example, via since we use a page table entry will be 2.2. So in this case, yeah. 126 00:16:50.790 --> 00:16:56.580 William Cheng: Yeah. Yeah, this one sort of four point the physical page. But we're also going to call this one page x, y. So, this gives you will be a virtual patient number 127 00:16:57.660 --> 00:17:00.510 William Cheng: Alright, so again, x over here, referred to, you know, the 128 00:17:03.000 --> 00:17:10.170 William Cheng: This particular page could be a virtual patient could be a physical page that knows there's little confusing, but if I start introducing multiple you know 129 00:17:11.160 --> 00:17:17.280 William Cheng: Multiple symbols represent these kinds of is going to be a total mess. Okay. So, therefore, I'm just going to call this one page x there. 130 00:17:17.850 --> 00:17:22.890 William Cheng: So there are these three pages over here, x, y, and z. And they mapped to the three physical pages over here, x, y, and z. 131 00:17:23.430 --> 00:17:34.650 William Cheng: So where is data right there is there is right here sitting on page z. So, when the parent process over here says, Did you go to 17 what will happen, right. So again, data is going to be one memory location overhearing page z. 132 00:17:34.860 --> 00:17:43.800 William Cheng: When you perform address translation well right into our, you know, writing to this page is incompatible with read only. So in this case you will trapped inside a kernel. 133 00:17:44.610 --> 00:17:51.990 William Cheng: That so he jumped into the corner. What is the current supposed to do, right, you walk down that list of VM area and you find out that this particular VM area is 134 00:17:52.890 --> 00:18:00.840 William Cheng: This particular example this VMware whereas over here is rewrite all right. It's also private PR IV over here. 135 00:18:01.230 --> 00:18:07.500 William Cheng: So therefore, we know we need to put one copy on write. Okay. So in this case, what we'll do is that we're going to ask the buddy system for new page right this is 136 00:18:07.830 --> 00:18:15.660 William Cheng: A new page. So we're going to get four kilobytes over here. And then we're going to make a copy of this page. So this page over you're going to make a copy right here. So, this will be the newsy 137 00:18:16.260 --> 00:18:21.300 William Cheng: Okay, and then the newsy, why not data is going to be going away data equal to zero because you just copy the entire page. 138 00:18:21.600 --> 00:18:28.230 William Cheng: Okay, so this museum, he will be exactly the same as the OC every bite are exactly the same. And then what do we have to do. 139 00:18:28.740 --> 00:18:38.340 William Cheng: Guys are this guy, we need to change this point over here deployment. This one I need, we need to change this one to rewrite right and now we return back into the user space program. So sort of work like this. 140 00:18:39.450 --> 00:18:46.080 William Cheng: Okay, I'm looking at a new page I make a copy of this one over here I change this point over here I change your answers to to relax. 141 00:18:46.260 --> 00:18:59.430 William Cheng: And not returning to the user space for when the user. So as well as going to try this operation. The second time and now right is compatible with the rewrites so so you it's going to follow the pointer and he will change this data from zero equal to start from zero to 17 142 00:19:00.840 --> 00:19:09.720 William Cheng: Okay, so again, this is how copy on write works, right. First, I said it to read all the way until the first page fall and then I make a copy and then all the changes over here. We'll go into the copy 143 00:19:09.900 --> 00:19:13.290 William Cheng: And also from this point on, next time when I say data equals to 15 again. 144 00:19:13.470 --> 00:19:19.890 William Cheng: It will not cause the page farther than the next time because this one is already read right so therefore I cannot make all my modification over here and paste the 145 00:19:20.040 --> 00:19:26.160 William Cheng: Whether they are data whether whether there are other data on page z. So, from this point on, there's no page fall on page see 146 00:19:27.690 --> 00:19:32.250 William Cheng: Okay, so. So again, I only need to perform copy on write once for this particular page. Yeah. 147 00:19:33.840 --> 00:19:40.080 William Cheng: So in this case, you know, you know, the question over here is that, you know, is this the correct way to implement copy. All right. 148 00:19:40.470 --> 00:19:51.960 William Cheng: Okay, so why is you said that I go to 17 you ask the parent process. What is the value of data parent process gonna follow this fight over here says that they they go to 70. What do you see as the child has and what is the what is the value of data. 149 00:19:56.760 --> 00:20:02.370 William Cheng: Right. So remember the parent and child over here, they are using the same address space over here. So, therefore, 150 00:20:02.520 --> 00:20:11.130 William Cheng: For data for the child. Over here is also point to the same memory location. And now if you follow the pointer over here, you know, to access this data. So for the child processes to chop lessons because they did they go to zero. 151 00:20:11.340 --> 00:20:16.590 William Cheng: And that's exactly what you want, right, because the parent modify its own space and it does not affect the child. 152 00:20:17.670 --> 00:20:22.920 William Cheng: Then similarly what what are the chances data equals to five over here, right. So this guy's again. 153 00:20:23.280 --> 00:20:31.590 William Cheng: Right is not compatible with read only. You're trapped inside of Colonel, we're gonna walk down that list of VM area over here and we find out that this particular memory segment. 154 00:20:31.950 --> 00:20:40.020 William Cheng: Is covered by three pages, x, y, and z. And they are rewrite and private so therefore we need to perform copyright, because as the buddy system for four kilobytes. 155 00:20:40.200 --> 00:20:47.790 William Cheng: We're going to make a copy of this page. So, well, we're done. D. What a zero over here we're going to change this point at the point of this way. I'm going to change this to rewrite 156 00:20:47.970 --> 00:20:53.730 William Cheng: We're going to go back to the user space and the user smell performed equal to five again. And now what it will do is that it will change this modify 157 00:20:54.720 --> 00:21:00.060 William Cheng: OK. So again, this will be the correct operation because from this point on, if you ask the child processes. What is the value of data. 158 00:21:00.240 --> 00:21:11.130 William Cheng: The child process will say that this is equal to five. And if you ask the parent process that will say, what is the value of data, the parent process is going to say, you know, the path of us is going to say that that's equal to seven game. 159 00:21:12.660 --> 00:21:18.060 William Cheng: Okay, so when you perform copy on right after fork. There's actually no problem at all. Yeah. 160 00:21:20.130 --> 00:21:25.140 William Cheng: Alright, so this is the first case, there's actually no problem. The second case of years. What have you ever share mapping 161 00:21:25.440 --> 00:21:34.590 William Cheng: Okay, so in this example over here. Again, our memory segment over here is a 10 kilobytes right x, y, and z over here. But in this case, they are rewrite and then they are shared. 162 00:21:36.570 --> 00:21:41.760 William Cheng: That. So in this case, is there a shirt over here. So this guy is that the parent over here for these three pages over here. They're all rewrite 163 00:21:41.940 --> 00:21:47.550 William Cheng: For the child over here. They're all rewrite. So when the parent says data equal to 17 this data will change to 70 164 00:21:47.790 --> 00:21:54.570 William Cheng: The child if you ask the shell. What is the value of data. The Charles say that they're able to 70 should the child be surprised that it has been changed by the parent 165 00:21:55.290 --> 00:22:04.800 William Cheng: Or the answer will be no, because that's why share mapping means right if you're sharing a file when when one process modify the data instead of file. What, then, the other process. You also see the changes inside that file. 166 00:22:05.130 --> 00:22:10.500 William Cheng: Okay, so again, this case doesn't cause any problems when you have shared mapping it works perfectly right because you know they're supposed to. 167 00:22:11.190 --> 00:22:16.290 William Cheng: This is how it's supposed to work. So in this case, you know, what if the child doesn't want to see it while, then you shouldn't really share 168 00:22:16.710 --> 00:22:22.950 William Cheng: Why did you say you're doing share mapping, you shouldn't be surprised that that data get changed by another process. Okay. Because that's why sharing things. Yeah. 169 00:22:24.900 --> 00:22:31.890 William Cheng: All right. The third example is over here it says the copy on write happens before fork. Right. So, so right now we don't have a child process yet. 170 00:22:32.130 --> 00:22:36.450 William Cheng: We only have kind of positive over here and now the parent process over here. We're doing copy on right 171 00:22:36.570 --> 00:22:49.350 William Cheng: So initially, all these three pages over here, x, y AMP Z. They're all we don't eat. So again, the corresponding memory segment over here. There's 10 kilobytes x, y, and z over here. So this one is going to be rewrite right and this one is also going to be private. 172 00:22:49.860 --> 00:22:56.670 William Cheng: Right. That means that we're doing copy on write that. So in this case, we're going to do copy on write first and then we're going to create a child process. 173 00:22:57.030 --> 00:23:01.380 William Cheng: Okay. So as it turns out, this is the case, we're going to have problem. Okay. All right. 174 00:23:02.130 --> 00:23:07.920 William Cheng: So what does example right data equal to 17 right then it was 17 over here data sitting right here and now. 175 00:23:08.190 --> 00:23:15.780 William Cheng: You know, right, is incompatible with three dolly you trapped inside the Colonel, we asked the buddy system. We walked on a linear list of VM area over here. 176 00:23:15.990 --> 00:23:20.250 William Cheng: With find out this memory segment is rewrite and private so therefore we need to copy. All right. 177 00:23:20.460 --> 00:23:27.390 William Cheng: We asked the buddy system for four kilobytes would make a copy of this page and not data equal to zero we change the point of the pie right here. 178 00:23:27.600 --> 00:23:32.190 William Cheng: change this one to rely and then we return back into the user space user space. So I'm going to do it again. 179 00:23:32.370 --> 00:23:44.310 William Cheng: And I was going to change your 17. So, so far it's exactly as the way that we described before, right, because copyright. Copyright is still do exactly the same as what it does before and now we're going to perform a fork. Fork of the parent process. 180 00:23:45.240 --> 00:23:52.770 William Cheng: Okay, so the question over here is that, you know what, how do we actually implement for that. So when we focus help us as well. I'm going to create a child process we're going to create a cop. 181 00:23:53.460 --> 00:23:58.980 William Cheng: We're gonna actually the child has, it has their own page table. Okay, so what if we actually copy the press page table. 182 00:23:59.250 --> 00:24:09.090 William Cheng: Okay, we can copy the parent page table over here. Then over here. Here's three x, y, and z over here. So point here, right, why will point here and z will point here. 183 00:24:09.360 --> 00:24:17.850 William Cheng: part right here and this one will be read only this one will be read only. And this will be rewrite right so that will be one way to do it. Okay. The other possibility is over here is that 184 00:24:18.390 --> 00:24:21.840 William Cheng: You know, so you can see that this is one that actually doesn't really work very well. 185 00:24:22.260 --> 00:24:30.870 William Cheng: Because as soon as I do this over here and now the parent and the child are sharing the same page over here. So if the child over here, go and modify that page of yours that data equals to five. 186 00:24:31.770 --> 00:24:36.870 William Cheng: What's going to have it right over here, this entry is over here is we. Right, right. So, if he said data equal to five, one in 187 00:24:37.110 --> 00:24:42.000 William Cheng: This case the right will actually happen. I'll be here you will change this one to five and now the parent will get 188 00:24:42.300 --> 00:24:44.520 William Cheng: The, the parent will get I will, I will get surprised. 189 00:24:44.730 --> 00:24:56.250 William Cheng: And also dependent can do the same thing in the process data equals two, one over here, right, the child over here is actually reading this data. The passes that equal to one. Then in this case it will change to one and now the child processes will chop prices will be surprised. 190 00:24:57.360 --> 00:25:00.150 William Cheng: Okay, so it seems I copy the page table here is not 191 00:25:00.810 --> 00:25:08.880 William Cheng: Is not going to work so well. What other options do we have, well, if we actually keep the old copy of the page table for the parent one, then we can actually get a copy of the old 192 00:25:09.210 --> 00:25:13.410 William Cheng: The old page table from the parent that. So in that case, what would that look like whereas over here, we 193 00:25:13.740 --> 00:25:23.670 William Cheng: Have a choice over here is a page z we can point here, we can point here. If we have a copy of the old page table and then next will part right here and this one will be read only over here, is that correct 194 00:25:24.540 --> 00:25:30.480 William Cheng: Well, as it turns out that's also wrong because right now if you ask the Chow. What is the value of data, the charts and what did I go to zero. 195 00:25:31.110 --> 00:25:37.530 William Cheng: Okay, but what should be the value of data. The data should be actually has the value of 17 because at the time when the parent for college how process. 196 00:25:37.710 --> 00:25:45.150 William Cheng: That data equal to 70 so will you for coffee shop. I said at the Chopra this supposed to get a copy of the parents address as well. So therefore, the data better be 17 197 00:25:46.530 --> 00:25:53.100 William Cheng: Okay, so it looks like if we point here and we use rewrite and if we find here is in read on a none of that works over here's what it's going to be the solution. 198 00:25:54.150 --> 00:25:54.510 William Cheng: Now, 199 00:25:56.340 --> 00:26:01.050 William Cheng: Alright, so the solution over here. So again, this doesn't work. That doesn't work. None of them work over here. 200 00:26:02.190 --> 00:26:11.400 William Cheng: So, so again, this is the way that you just copy the page table. This is the way that you copy the old version and paste a ball eaten on either way it's going to work. So, the solution is gonna be somewhere in between. 201 00:26:12.030 --> 00:26:19.920 William Cheng: Okay, so what we should do is that, you know, this pointer over here, better point to the new page Z because because the data is equal to 17 right. So this part is 202 00:26:20.520 --> 00:26:30.870 William Cheng: Clear that I should point right here. So Robin is that, you know, the page table entries over here is actually incorrect. It needs to be sent it to read only. So this way when the, when the child processes tried to write to the right to Z again. 203 00:26:31.110 --> 00:26:39.750 William Cheng: Now, this should do copy on write all over again. Okay, because we must not allow the child processes modifies that data over here because the data over here is being shared with a parent. 204 00:26:40.350 --> 00:26:44.370 William Cheng: Okay, so therefore this entry is over here has to be reality. But what about the parent 205 00:26:44.640 --> 00:26:57.000 William Cheng: The parent also need to do the same thing. Why this page. End of the year. If it's equal to rewrite over here, what the person did or equal to one, but in this case the child processes will be surprised. So therefore, for the parent. We also need to set this one back to read only. 206 00:26:58.290 --> 00:27:06.240 William Cheng: Then, so the idea here is that whenever we for coffee shop ourselves. We have to reset all these page table entries over here back to what it was before. 207 00:27:07.620 --> 00:27:14.850 William Cheng: OK. So the idea here is that, you know, you know, that's the correct solutions over here that we're going to copy the page table entry from the parent 208 00:27:15.060 --> 00:27:23.070 William Cheng: And then we're going to reset for copy on write for all the privately, the full, full, full, full, full, full for all the for all the private pages. 209 00:27:23.430 --> 00:27:33.840 William Cheng: Okay. So this guy is the private phase over here are x y AMP z. So, we need to go to every entries over here and change the pace of the protection of your back to reality. We are resetting so that we can get ready for copy all right again. 210 00:27:35.190 --> 00:27:41.550 William Cheng: That. So once we have done this, what's going to happen. Right, so, so, so, Susan. So this case over here. When the parent says they they 211 00:27:42.000 --> 00:27:46.770 William Cheng: I guess at this point they they are equal 17 over here is the charts as data equal five 212 00:27:47.190 --> 00:27:54.030 William Cheng: That. So again, right over here is going to be incompatible with the read only. So in this case, you're trapped inside of Colonel you walked on that list of 213 00:27:54.510 --> 00:28:01.140 William Cheng: VM area and you find out you need to copy. All right. So you ask the buddy system for four kilobyte pages over here and now. Where do you copy from 214 00:28:01.590 --> 00:28:05.340 William Cheng: Right, you need to copy from this page over here. So now, data is going to be equal to 17 215 00:28:05.910 --> 00:28:07.680 William Cheng: Okay, because there might be other places has already 216 00:28:07.980 --> 00:28:16.800 William Cheng: Been modified by the pair. So, therefore, you have to copy from here, there, and then you change this point over here to point to the new page over here and changes to rewrite and you return back into the US. 217 00:28:17.100 --> 00:28:23.940 William Cheng: Back into the chat box as the child classes will do t equals to five again. And that's going to be compatible with with three right and now you change this one to five. 218 00:28:25.050 --> 00:28:33.390 William Cheng: Okay. So in this case, you know, if you ask the child process. What is the value of data. It was it five, he asked the other, the, the parent process. What is the value of beta, the parents gonna say 17 219 00:28:33.750 --> 00:28:39.300 William Cheng: Okay, what are the at the same time, the process D or the one right. So again, this one's going to be incompatible with read only. 220 00:28:39.480 --> 00:28:47.610 William Cheng: You trapped into the kernel you walk down the list of VM area or you find out that you need to perform copy on write you ask the buddy system for another four kilobytes over here. 221 00:28:47.790 --> 00:28:55.860 William Cheng: You copy from this one over here and now, data is going to be able to 17 right and then you change this point over here. The point of this one change this one to rewrite over here. 222 00:28:56.070 --> 00:29:02.790 William Cheng: In return back into the user space program, it will do t equals two, one again. And now it's compatible with the rewrite you modify this one to one. 223 00:29:03.630 --> 00:29:11.850 William Cheng: That. So now, if you ask the parents. What is the value of data, the parents gonna say is equal to one if you ask the child, what is the value of data. The data is going to say is equal to five. 224 00:29:12.300 --> 00:29:23.370 William Cheng: What about this page over here. Well, maybe this page is still on by the grandparents. So if you ask the grandparents. What is the value of data, you know, it depends on whether the grandparents on either this one or this one the grandparent was a sequel to zero equal to 17 225 00:29:24.660 --> 00:29:31.980 William Cheng: Okay, so, so, so now you can see that, you know, you know, whenever I perform a fork operation. I need to go to every memory segment. 226 00:29:32.280 --> 00:29:41.910 William Cheng: Okay, I need to go to every member summer figure out which one is private, and for every one of those page table entry that belong to that memory seven I have to reset for copywriting just send it all back to read only. 227 00:29:43.170 --> 00:29:49.140 William Cheng: Okay. So, from this one. Oh, I can install doing copy on write all over again. And this way, it will be correct. Yeah. 228 00:29:50.760 --> 00:29:59.760 William Cheng: Alright, so the question over here is that, you know, where should you copy from whereas over here, we saw the example you know something, you know, one time you copy from this page. And why don't you come on this page, and then, you know, and 229 00:30:00.150 --> 00:30:08.250 William Cheng: So, so, so we're going to end up with how many page z over here we have one page see over here and one over here. No one. So in this example, we're going to end up with four page see over here. 230 00:30:08.520 --> 00:30:18.240 William Cheng: What is the child over your for common knowledge shall pass as the parent will be a fork of knowledge. Help us as we're going to end up with gazillion pages. These over here. Okay, so we won't copy or right when we copy file. 231 00:30:18.990 --> 00:30:22.800 William Cheng: Okay. So one way that you can sort of think about is that whenever, whenever you know this example. 232 00:30:23.190 --> 00:30:28.350 William Cheng: When I tried to perform copy. All right. What do I copy problem. I can actually follow this pointer over here to copy this page. 233 00:30:28.860 --> 00:30:39.210 William Cheng: Okay. Originally when I try to copy from this page. Again, I need to follow the point of view and powerful this page. As it turns out, you can't really always do this, it is possible that the page table over here will be completely invalid. 234 00:30:41.490 --> 00:30:43.680 William Cheng: Okay, so, so, so, so, so there's a lot that is that 235 00:30:44.220 --> 00:30:51.270 William Cheng: So the basic idea over here is that when you see the data structure inside of page table over here, the data structure is a temporary data structure. 236 00:30:51.480 --> 00:31:01.080 William Cheng: This page table. We can be entirely wiped out for whatever reason is that a kernel, guys, so therefore we can never rely on the pointer inside the page table be here to be valid. 237 00:31:01.860 --> 00:31:08.850 William Cheng: Okay, so even though the example that we saw up here said, hey, we just, we just follow the pointer over here, everything will work. Right, but we cannot use page table over here to keep track 238 00:31:09.120 --> 00:31:16.440 William Cheng: And as soon as I'm going to see an example later why you happen to the patient branches over here is that is that he might, he might get entirely wiped out. 239 00:31:17.010 --> 00:31:29.490 William Cheng: Okay, so what is wiped up, especially when the equal to zero, also for this this page, ensure that we're if equal to zero, that means that the page table entries over here is invalid and that you are not allowed to copy from that because invalid. 240 00:31:31.290 --> 00:31:39.810 William Cheng: Okay. So in this case, you got to be very careful, you have to use the colonel data structure in order for you to figure out where to copy from. So in this case, there are four pages. These over here. 241 00:31:40.020 --> 00:31:45.870 William Cheng: Where you need to copy from you need to use a colonel data structure. So, what is the cuddle data structure. The Colonel data structure is your virtual memory map. 242 00:31:46.380 --> 00:31:50.670 William Cheng: Okay, so he's that virtual memory math there has to be some way to tell you where to copy from 243 00:31:51.480 --> 00:31:57.000 William Cheng: Okay, so are virtual memory map so far is a very, very straightforward. So now it's going to get a little more complicated. 244 00:31:57.810 --> 00:32:06.510 William Cheng: But so the solution over here is going to be what is going to be the solution and the solution is, again, it's going to be one level indirection. Right, we should never be surprised that we see one humbling direction. 245 00:32:07.110 --> 00:32:11.310 William Cheng: Because it seems that every time we sort of see a problem. We use well of indirection that 246 00:32:11.940 --> 00:32:22.920 William Cheng: So, so in order for us to get this to work, is that, you know, originally Robin is that inside the VM area over here. We're going to point to the fall object. Right. The Fall objects over here is the one that has those those three three patient X y&z 247 00:32:23.520 --> 00:32:28.920 William Cheng: Okay, so, so in order for us to perform one level and direction will be here. We're going to add an object in between. 248 00:32:29.370 --> 00:32:38.610 William Cheng: The VM area over here. So this one is the VM area is over here at this one point to the the object, then we're going to ask something in the middle. Over here, as this is called a shadow object. 249 00:32:38.940 --> 00:32:46.290 William Cheng: Okay, so they saw object is one level and direction. So what is inside a shout out yet the shuttle object is there to keep track of pages. 250 00:32:46.530 --> 00:32:50.700 William Cheng: That were originally copied on right so which pages are really originally copied on right 251 00:32:50.970 --> 00:33:02.910 William Cheng: Now, so the data coming from the fall over here. Originally, you know, so, so this, this guy, this memory segment over here is rewrite and private, that means that we need to perform copy on write that data. In this example, originally come from the desk. 252 00:33:03.960 --> 00:33:07.770 William Cheng: Okay, so therefore, in this case, the original data over here, you know, have not been 253 00:33:09.120 --> 00:33:20.730 William Cheng: Has not been subject to copyright. So therefore, x, y, and z over here we have data that's exactly the same as what sitting on desk. Okay, so these are the data. There are copies on disk over here. From this point on, we're doing copy on write 254 00:33:21.780 --> 00:33:36.690 William Cheng: Then, so feel for the shuttle object and they keep track of pages that were originally copied on right but have been modified over here. So we saw before we start with the pasty and when you make a copy of the page z. And now you right into the copy that one has been modified 255 00:33:37.800 --> 00:33:49.260 William Cheng: Right, because you know the original one, the original one is crazy, right. That's why with equal to zero, where you make a copy of it. Will you right into the copy the one that you run into that one needs to be managed by the shuttle object. 256 00:33:50.220 --> 00:33:54.180 William Cheng: Okay, so let's get going to end up with a new page see over here that's inside chatter object over here. 257 00:33:54.390 --> 00:33:59.280 William Cheng: That. So the way we're going to sort of draw this picture is that if you see a page Z inside a shadow object. 258 00:33:59.460 --> 00:34:08.520 William Cheng: That means that this page z and this page Z. There are different because the one at the bottom over here at that one is original data that was the one's going to be look exactly the same as what's on desk. 259 00:34:08.790 --> 00:34:11.940 William Cheng: And the one inside the shadow object that's the one that has been modified 260 00:34:12.660 --> 00:34:22.530 William Cheng: Okay, so this way you know when you start performing copy on write over and over again and do going to end up with a lot of pages each and every one of these pages is going to be sitting in different shadow objects. So this way we can keep track of all that 261 00:34:23.550 --> 00:34:33.090 William Cheng: Okay, so that's how we're going to use the shadow object to keep track of all the patients that were originally, you know, the originally copied on right but they have been modified 262 00:34:33.810 --> 00:34:43.620 William Cheng: Okay alright so page. Is that a memory map or virtual memory map over here, in which an object has been my private right so to over here. Here is a 263 00:34:43.890 --> 00:34:48.780 William Cheng: You know, here's the VM area over here. It was my private has an associated shadow object. 264 00:34:49.350 --> 00:34:56.550 William Cheng: Okay. So, so what we told our address phase right we saw is limitless IBM area, the VM area appointed a file object, it points to the anonymous object. 265 00:34:56.790 --> 00:35:03.840 William Cheng: But now it's no longer true if this one is private and rewrite the first point over yet. I will point to is going to point to a shadow objects. 266 00:35:05.550 --> 00:35:12.270 William Cheng: OK. So again, the previous feature that we saw the point are coming out of the VM area, it points to a file object or it points to anonymous object. 267 00:35:12.510 --> 00:35:19.800 William Cheng: Now, if we're doing copy on write, we're doing a private mapping in that case the pointer over here will point to first your point to a shadow object. 268 00:35:21.180 --> 00:35:26.910 William Cheng: Or is it what is this one over here is sure it's not private. So anyway, that case it will point to a file object will point to anonymous object. 269 00:35:27.300 --> 00:35:30.450 William Cheng: Okay, but if its private, then it will point to a shadow object. 270 00:35:30.990 --> 00:35:40.920 William Cheng: That. So if a page is managed by the shadow octave over here or references that a shot object, like the picture that I drove me here is as a here is a page Z that's sitting over here pages. These any hobby. Yeah. 271 00:35:41.370 --> 00:35:52.860 William Cheng: So this one, you know. So this guy's z over here has been modified. It's different from the original data, right, the original data is the one that said about him over here. So he said, the way you should think about is that you know the the you know the 272 00:35:53.310 --> 00:36:00.510 William Cheng: The, the, these pages that are sitting inside the file object or since I since I did not have a subject. They were the original out object. 273 00:36:01.110 --> 00:36:04.830 William Cheng: Okay, all the one has been modified they're sitting inside a shadow object. Yeah. 274 00:36:05.580 --> 00:36:14.250 William Cheng: Yeah, yeah. Otherwise, the page is managed by the original object. Could be a file object or it could be an anonymous object so Anonymous is something also call the zero object. 275 00:36:14.550 --> 00:36:22.500 William Cheng: And the read the reason for that is that for Linux system. Whenever you create a the whenever the anonymous have to create a page is filled with zero 276 00:36:22.770 --> 00:36:28.200 William Cheng: Right, so that's why some people call it the zero object, okay. Because, because the, the, the job of the object is zero out the page. 277 00:36:28.710 --> 00:36:34.500 William Cheng: Guys so again. So again, in our class will call it an anonymous object, but some people call it the 00 object. 278 00:36:35.310 --> 00:36:47.370 William Cheng: Right, the X, Y, and Z on the right over here are our physical pages, right. They also pays frame over here, right. So again, you know, in this case, again, that's why we sort of use the word page frame physical page interchange interchangeable, you know, 279 00:36:49.020 --> 00:36:53.910 William Cheng: The bottom line over here is that the shahada tells you where to copy from where you need to put him on copyright 280 00:36:54.150 --> 00:37:07.140 William Cheng: Okay, so before you the example we have for PC over here. Where do you copy from you're going to use the colonel data structure over here and you're going to run an algorithm that would tell you where to copy from. Okay, so we're gonna also going to describe the algorithm for you. Okay. 281 00:37:09.510 --> 00:37:22.620 William Cheng: All right, so the original picture look like this. Right. So we have a linear list of VM area right I've. One of them is via mail as region memory segment over here at Tech data plus BSS heap and map will be here right and the next one over here. 282 00:37:23.160 --> 00:37:28.380 William Cheng: The one that that are created from the file system. They pointed the fall logic over here, I just want to follow. Yeah. 283 00:37:28.620 --> 00:37:35.730 William Cheng: And this is memory map files or to come on the buses and ponder the project all the otherwise the heat and the stag, they don't come from the fastest 284 00:37:35.970 --> 00:37:46.200 William Cheng: So therefore, they pointed out was ok ok so now for every one of these memories segment that are that are doing copy on what we need to change the point a to point to a shadow object. 285 00:37:46.590 --> 00:37:49.620 William Cheng: Okay, so this guy just want to share it. So, therefore, there's no shot object. 286 00:37:49.800 --> 00:37:55.770 William Cheng: This one is probably this one is private. In this example, this one is rewriting private. So again, this one is also subject to copy. All right. 287 00:37:55.950 --> 00:38:04.680 William Cheng: And this was a copyright. So in this case, we need to add a shadow object, you know, all you know for all these form every segments over here. So, India, I'm going to end up with this picture like this. 288 00:38:06.480 --> 00:38:11.130 William Cheng: Okay, so, so, so, so in this case this will be, you know, this will be a shot object. 289 00:38:11.550 --> 00:38:20.400 William Cheng: Okay, I also changed the picture a little bit. I sort of showed a little more detail inside the weaning softening says that in the Phoenix operating system. This point over here doesn't point to the 290 00:38:21.000 --> 00:38:26.790 William Cheng: To the fog yet. Okay. So actually inside the fall object. There is something called the memory management object. 291 00:38:27.540 --> 00:38:38.970 William Cheng: OK, so the memory management, if there is an object that managed page ranks. Okay. One of the PageRank. Right. They don't want to. We saw X, Y, and Z their pace rain that. So in this case, this point over here actually point to the animal VJ 292 00:38:40.650 --> 00:38:45.450 William Cheng: Okay, so, so that looks a little weird over here at this point you're right here appointed and then we'll BJ over here. 293 00:38:45.690 --> 00:38:56.790 William Cheng: This point over here also point to the shadow object, right. So, so again, this is the same point are coming on the VM area. How can appoint a point to the demo BJ as some time and also point to shut off. 294 00:38:57.630 --> 00:39:12.480 William Cheng: As a matter of time. Well, that means that we're doing polymorphous them. Okay, so this point are coming up a VM area, it can point to either mo BJ or it can point to, you can you can also point to another subject. Now what about this pointer over here coming out of 295 00:39:13.980 --> 00:39:17.340 William Cheng: Coming out the shadow objects over here, this is the one, also called upon to emoji. 296 00:39:19.050 --> 00:39:27.060 William Cheng: Well as okay again this point of view is gonna be a party movement point or a component of different kinds of memory management object. As it turns out, you know, the, the, the 297 00:39:28.860 --> 00:39:38.100 William Cheng: As it turns out, the, the shadow object is a memory management object, right, because they manage page frame we saw that you know you manage patient that has to be modified. Right, so they will get you know it's an emo BJ. 298 00:39:38.340 --> 00:39:45.210 William Cheng: Also the anonymous object over here if this one is a shared memory segment over here, whether this quantity or we will point directly to anonymous object. 299 00:39:45.780 --> 00:39:49.260 William Cheng: Okay, so therefore anonymous saga is also a memory management object. 300 00:39:49.710 --> 00:39:58.890 William Cheng: Okay. So this guy is going to end up with three different kinds of memory I matters object, the anonymous object, the one that's inside the fall object and also the shadow object. There are three different kinds of 301 00:39:59.190 --> 00:40:04.350 William Cheng: Memory. That is an object, okay. The job or the memory management object is to manage these frames for you. 302 00:40:05.370 --> 00:40:11.730 William Cheng: Okay, so now we have a more complete picture. Whenever you get a peaceful, you're going to walk down this linear list of VM area and then 303 00:40:12.120 --> 00:40:21.300 William Cheng: When you get a pace while you're gonna have a virtual address you find out which one it belongs to over here. So once you determine that already, but also this one over here. Right. And this guy, maybe, maybe this one over here. 304 00:40:21.540 --> 00:40:29.970 William Cheng: This one is the one that say with, you know, with think kilobytes over here. And then what you find out is that these objects over here is going to happen your pace red X Y AMP z and then you 305 00:40:30.180 --> 00:40:40.080 William Cheng: You you talk to these object to find out which one actually has the object that you want. Okay, so we need to perform copy all right you know where to copy from by by talking to all these objects. Okay. 306 00:40:43.620 --> 00:40:52.380 William Cheng: Alright, so let's take a look at our example over here and to see you know how to actually implement this right. The first example over here. We're going to see the one that doesn't require shout object. 307 00:40:52.800 --> 00:41:00.180 William Cheng: So if you're using a shadow mapping over here, then the point over here will point directly to the follow up Django pointed anonymous object this example we are going to 308 00:41:00.600 --> 00:41:09.360 William Cheng: Fall out. Yeah. So again, as we point to the memory marriage object that inside of it. Right. So again, for simplicity we have something going to have a point to the object that 309 00:41:09.900 --> 00:41:16.740 William Cheng: So in this case, we're using a SharePoint over here. Sorry, SharePoint, so this one this memory segment is rewrite and shared over here. 310 00:41:17.010 --> 00:41:22.890 William Cheng: So in this case, when you try to perform the right operation, you would just write to the entities patron. What if you were up before the full cooperation. 311 00:41:23.220 --> 00:41:31.200 William Cheng: Guys are not gonna win a copy. Make a copy of the address space. So this guy want to create a child process over here process be over here. Here's a linguist of as 312 00:41:31.560 --> 00:41:37.320 William Cheng: A VM area. So we're going to make a copy of that that lingers over here we're going to end up with, you know, the this 313 00:41:37.920 --> 00:41:43.020 William Cheng: VM aerial view is going to be a copy. So in that case, they, you know, when you copy a pointer, they will point the same object. 314 00:41:43.860 --> 00:41:47.940 William Cheng: Okay, so in this case when we perform a fork operation, they will look like this. Okay, and we 315 00:41:48.480 --> 00:41:53.640 William Cheng: We saw before. This actually works perfectly well we don't have to do anything special. Okay. And also, we don't need a shadow on 316 00:41:54.210 --> 00:42:05.280 William Cheng: That all right. The second because over here we're going to look at private mapping. Right. And then we're going to, sort of, you know, we already know that if you are pretty you know if you actually if you fought for us. And then you to copy on write, then probably mapping 317 00:42:06.270 --> 00:42:14.460 William Cheng: Is going to work. Okay, so we only need to worry about the case where it doesn't work that we're going to perform. We're going to perform copy on write first and then we're going to perform the full cooperation. 318 00:42:14.730 --> 00:42:21.390 William Cheng: Okay, so let's take a look at that example over here. So first, wonderful one copy on right so in this case the parent process will look like this. Right. You have a link 319 00:42:21.690 --> 00:42:30.840 William Cheng: We have a link list over here have a VM area. One of them over years progress. So in this case you will point to an empty shadow object it's empty, because we haven't performed copy on write yet. 320 00:42:31.230 --> 00:42:35.160 William Cheng: That and then this point over here will point to the fall object right again inside 321 00:42:35.640 --> 00:42:48.030 William Cheng: Linux the remix it will point to the demo BJ that's inside the inside of objects. I don't know the actually Retired Colonel, Colonel to coat the inside your corner to go inside of objects. There's an object called mmm LBJ 322 00:42:48.690 --> 00:42:53.610 William Cheng: OK. So again, that's the one that's using that winnings now. But yeah, this picture. We're only going to draw the file object. 323 00:42:54.420 --> 00:43:01.440 William Cheng: Right. So now we're going to perform copy on write first. Okay. And then we're gonna perform the operation. Right. So in this case, I see what happened. Oh, yeah, yeah. 324 00:43:02.070 --> 00:43:16.530 William Cheng: Alright, so, so again, to be more complete over here, this XYZ over here are going to sort of combine the other pictures that we saw before. This is process. A. Here's the address space representation or the via the virtual memory map. It's a linear list of VM. 325 00:43:18.000 --> 00:43:29.370 William Cheng: VM area, the process. He also has their own pace table at the page table we here for the entry that correspond to X, Y, and Z. They point to these three physical page over here, x, y, and z. Again, all these entries over here are read only. 326 00:43:29.580 --> 00:43:36.690 William Cheng: So even though right now this memory segment is rewrite and private. But since we are doing copy on write we set all the three entries over here to read it. 327 00:43:37.680 --> 00:43:41.940 William Cheng: Okay, so that's how the original pictures over here is is sort of connected with a piece of them were drawn over here. 328 00:43:42.570 --> 00:43:52.470 William Cheng: Okay, so you can actually see that this page is going to get pretty full pretty. So I'm going to get simplify the picture, right. So right now what does it talk about the first case over here. We're going to perform copy on write first and then we're 329 00:43:53.850 --> 00:43:55.260 William Cheng: Going to perform a fork. Right. 330 00:43:57.030 --> 00:43:59.400 William Cheng: Alright, so let's see what. Well, what will happen over here. 331 00:44:00.000 --> 00:44:01.500 William Cheng: So in this case, 332 00:44:01.830 --> 00:44:12.690 William Cheng: We're going to perform a copyright, so x over here instead of motivating page Z on that. I have a month I paychecks. Okay. So, therefore, what do we do that over on the right operation over here for page x over here, try to change this why 333 00:44:12.870 --> 00:44:18.150 William Cheng: Since the right operation is incompatible with read only. What's going to happen right I'm trapped inside the Colonel. 334 00:44:18.330 --> 00:44:24.120 William Cheng: The Colonel is going to walk down this linear list IBM area and find out that over here. We're doing private magical doing copy. All right. 335 00:44:24.450 --> 00:44:32.610 William Cheng: Okay. So, therefore, what I would do is that I will ask the buddy system for four kilobytes page. Make a copy of in this example page. So this will be the new copy of page x over here. 336 00:44:32.790 --> 00:44:40.590 William Cheng: That and then it will change this point of the point of this wine changes. Why the rewrite over here and then it will return back to the user space and the user space going to modify this page over here. 337 00:44:41.070 --> 00:44:43.470 William Cheng: Okay, so what do we do, is that it will look like this. 338 00:44:44.190 --> 00:44:54.540 William Cheng: Okay, so when this was the this operation is done over here. This is going to be the new page x over here is going to be rewrite and now we need to put on copyright. There's one more thing that we have to do. Right. What is that one more thing. 339 00:44:55.800 --> 00:44:57.120 William Cheng: That so so 340 00:44:58.770 --> 00:45:03.690 William Cheng: You know, so, so since this page x over here. If we don't keep track of it. Pretty soon we're going to sort of 341 00:45:04.290 --> 00:45:12.030 William Cheng: lost track of where where this right because this page x over here is Keith, he took off by the by the fall object. The following day says pay taxes right here. 342 00:45:12.540 --> 00:45:22.470 William Cheng: Okay, this new page over here, we need to have some memory management object to point to her. So in this case, we need to make a reference of it inside the shadow object. So we're going to draw the picture light inside the shadow object. 343 00:45:22.770 --> 00:45:27.000 William Cheng: We're gonna say that this one is a reference to so that this will point to the new page right here. 344 00:45:28.050 --> 00:45:30.120 William Cheng: Okay, so we're done. It will look like this. 345 00:45:31.860 --> 00:45:36.690 William Cheng: Okay, so he's not a shout out to go over here is gonna is going to keep track off the copy of ads. 346 00:45:36.870 --> 00:45:42.330 William Cheng: And this is the one that has been modified. Right. So over here, you know, so, so, so for this particular memory segment over here. 347 00:45:42.510 --> 00:45:49.890 William Cheng: There are two page x, y, this here. One is here, the one on top over here that's inside a shuttle object. This one was originally copied all right but has been modify 348 00:45:50.100 --> 00:46:00.450 William Cheng: The one at the bottom over here. This is the original data. That's the one that look exactly the same as what sitting on the desk. Okay. So, therefore, this is the original x over here and this is the copier Erica. This one has been modified 349 00:46:01.770 --> 00:46:06.750 William Cheng: Alright, so this is how shadow object. Keep taco page friends that were originally copied on right and have been modified 350 00:46:09.120 --> 00:46:14.940 William Cheng: Alright, so let's see what happens over here he is going to fork and create a he's going to create process be over here. And then we need to remember, we need to 351 00:46:15.210 --> 00:46:24.180 William Cheng: We need to reset on copyright. Right. So again, that's why should we do right we're going to create process be right here. We're going to make a copy of the address. They were going to copy the entire linked lists. 352 00:46:24.420 --> 00:46:31.080 William Cheng: When we finish copying it over here. This one will be private privately map over here, we copy point there that will point to the same place over here. 353 00:46:31.860 --> 00:46:40.800 William Cheng: Okay, and also process be over here, we need to create a page table over here, we need to copy and paste table and we need to copy the entire page table from the parent and then we need to perform 354 00:46:41.220 --> 00:46:48.900 William Cheng: We said on copy on write. Okay, so in this case over here, x, y, and z x or point this way. Why will point this ways, you will find this way. 355 00:46:49.110 --> 00:46:57.750 William Cheng: And then we eat. We have a copyright. We do chances. Why the read only. Would you change this one to read on it. So, all these three entries over here will be read only. So when we have done the will look like this. 356 00:46:58.980 --> 00:47:10.380 William Cheng: So process be over here where you copy the point here that will point to the same thing over here, we create a choppy stable, we make all the copies over here. We resell for copyright. So this one is to go to read only. I just wanted to go reread on a 357 00:47:10.680 --> 00:47:19.200 William Cheng: There's one more thing that we need to do when we reset for copyright rights over here, we need to reset for copyright, we need to reset all these, you know, we need to go through every one of these 358 00:47:19.530 --> 00:47:25.830 William Cheng: You know, IBM area over here. Find out which one is private for all the private page table N G, we need to train them to read it. 359 00:47:26.670 --> 00:47:32.490 William Cheng: Okay, so again it's a really, really time consuming task we need to go through every one of these days go to every page. They weren't returned to read it. 360 00:47:33.480 --> 00:47:45.570 William Cheng: Okay well we're finished with doing that. Are we done right. So, so again, now we have reset for copy on write over here. So process. A and B. They haven't they haven't started copying. Right. Yeah, so therefore they need an empty shadow object. 361 00:47:47.340 --> 00:47:55.590 William Cheng: Okay, so. So in this case, you know, when they pointed this out after this technology is over here, we need to actually freeze page frame X over here, right. So this guy, we actually need to create two 362 00:47:55.980 --> 00:47:58.080 William Cheng: New shadow optical here and they're empty. 363 00:47:58.860 --> 00:48:10.560 William Cheng: Empty over here because as far as process and BS consider since we have we said if a copyright. They haven't performed copy on. Right. Yeah. So as far as process and BS answer everything below this line. They are frozen and they are read only. 364 00:48:11.520 --> 00:48:16.920 William Cheng: Okay. From this point on, if you want to modify any page all the modified pages over here need to go to the new chatter object. 365 00:48:18.030 --> 00:48:30.840 William Cheng: That. So in order for you to reset for copy on write over here, right, what you need to do is that you need to add an empty shadow object for these for the parent and child process. You also need to go to every page table entries over here that are private and change them to read only. 366 00:48:31.920 --> 00:48:37.200 William Cheng: Okay, and then you're done. They always have a copywriter. This one at this point. Now I'm going to copy on write all over again. Yeah. 367 00:48:39.420 --> 00:48:49.470 William Cheng: So, so there are. So there are many, many entries over years and one of one. You know, one of these objects will be hasn't been any page rain. You gotta go to every page table entries will be here change everything to read only. So that would take a very, very long time. 368 00:48:50.280 --> 00:48:53.970 William Cheng: As it turns out, you know, for weenies they actually do this in two steps. 369 00:48:54.840 --> 00:49:01.290 William Cheng: So it doesn't really change the pace that weren't you over here to read on it because it would take too long. Right. Every entries of you is going to actually, you can actually change it. 370 00:49:01.530 --> 00:49:08.910 William Cheng: Instead, what it will do is it will. I'm not the entire user space page table by setting the corresponding entry to be equal to zero. 371 00:49:10.080 --> 00:49:15.780 William Cheng: Okay, so what it will do is that, if this is the users portion of the page table, it will set everything in vivo zero 372 00:49:16.380 --> 00:49:25.800 William Cheng: Okay, was it. Forget about all these faces a bunch of their own invalid now. Okay, so the power over here the parallel do the same thing when you receive a copy and read the entire thing is gone. And then what you do is that you said equal to zero. 373 00:49:26.220 --> 00:49:37.200 William Cheng: Okay, so not the entire page table become to become the company become invalid. So from this point on any operation that you do, then this case, you can try things out a kernel. And then on the second time. 374 00:49:37.890 --> 00:49:44.850 William Cheng: On the next time the next time we get a pace fall in that case, what you can do is that you can actually set this one to read only, you know, 375 00:49:48.330 --> 00:49:50.970 William Cheng: If you try to riff on that page. Okay, so next time when 376 00:49:51.540 --> 00:49:58.680 William Cheng: We return back to the user space and the users user survey for I'm going to do something. Well, whatever the user sprint planning to do equal to zero. So, therefore, he's I'm sure he's out of Colonel 377 00:49:58.920 --> 00:50:10.470 William Cheng: At that time, you need to determine whether you're doing copy on write and where the copyright has already happened. But since we're resetting for copying or rifle for the entire process. A and B. So, therefore, in this case you haven't done any happier. Right. 378 00:50:11.430 --> 00:50:21.690 William Cheng: Okay. So, therefore, if you trapped inside the colonel because of the read operation, then in that case, all we need to do over here is fixed up this page. They were energy by setting the equals two, one and then again I said it back to read only. 379 00:50:22.320 --> 00:50:31.500 William Cheng: Okay. So this guy's got physical page number. You need to figure out where it is, or they will point to the right place. Okay. So in this case, you can actually figure out what if it turns out you're coming out of Colonel using a right 380 00:50:32.190 --> 00:50:42.300 William Cheng: Why, in that case, where you can do that. You can actually fix it up. The way that I just described what we hear change the center to read only going to back into the kernel of the second time. So going back to the user space. The second time. 381 00:50:42.480 --> 00:50:49.530 William Cheng: And not it will get another page. Well, I will you try these out a quarter for the third time. So this case you will change it back to rewrite and this is this is how you perform copying. All right. 382 00:50:50.580 --> 00:50:52.860 William Cheng: OK. So again, different operating system, but these are implemented. 383 00:50:53.580 --> 00:50:58.950 William Cheng: In a different way. But typically, what they would do is that he will actually a map the entire user space, space as well because they don't 384 00:50:59.250 --> 00:51:04.140 William Cheng: Want to go to all these entries over here and change every page. They weren't, you know, we're back to read only because that will be too much work. 385 00:51:05.130 --> 00:51:13.410 William Cheng: OK, so the typically what they would do is they will map the entire the user space. Space table by setting equal to zero for the patient where entry right that can be done very quickly. 386 00:51:15.450 --> 00:51:24.420 William Cheng: And then try to fix things up. You know what we're doing. The next thing that they're doing the next page Hall and we're doing a win eight and this is what you're supposed to do. Okay. 387 00:51:26.910 --> 00:51:34.590 William Cheng: All right. So, by the way, you know, this page is going to be really, really caught her so. So I'm going to stop drawing all these picture right now over here. So when you see x, y, and z, you need to imagine 388 00:51:34.830 --> 00:51:41.100 William Cheng: If this is object at the bottom over here could be a file object will be anonymous. So in this case, they will point that original page x y AMP z. 389 00:51:41.250 --> 00:51:49.320 William Cheng: And then any of the ones that are inside a shadow RJ again, they will be the one that were that were originally copied or but happy modified that 390 00:51:49.950 --> 00:52:00.870 William Cheng: So actually this is right now, it's a good time to actually take a break. So next time we're going to, sort of, you know, stop drawing these kind of stuff. And we're going to sort of make make the example, sort of a little more complicated. Yeah. Alright. So I'll see you in a bit.