WEBVTT 1 00:00:02.040 --> 00:00:12.000 William Cheng: Okay, this is the second part of lecture nine. So we just finished chapter three, even though we skip that dynamic Lincoln and loading. We're going to leave that at the end of the semester. 2 00:00:12.570 --> 00:00:22.410 William Cheng: So now we're going to talk about the first part of chapter four. So we're gonna sort of talk about some high level overview of the operating system design. Okay. 3 00:00:27.450 --> 00:00:35.850 William Cheng: All right, so basically we're going to look at, you know, how other sort of the components inside the operating system are connected we saw before. 4 00:00:36.630 --> 00:00:41.940 William Cheng: There, you know, some of the subsystem. So, you know, maybe there's different ways to look at the operating system. 5 00:00:42.390 --> 00:00:51.270 William Cheng: So going to sort of look at a component these that are operating system, how are they related to each other. How are they connected with with each other. How do they you know how they interact with each other. 6 00:00:51.780 --> 00:01:04.560 William Cheng: And you know how, how is the software structure and how are those sort of the performance concerns they are you know they're being considered. I will mention before performance is important. But that's not the only thing that's that's important. 7 00:01:05.790 --> 00:01:11.610 William Cheng: We will introduce new components in some of the inside this chapter, even though 8 00:01:11.940 --> 00:01:18.930 William Cheng: You know, right now we're going to only talk about the beginning part of chapter four. And we're going to come back and talk about this. After we finish. 9 00:01:19.350 --> 00:01:24.300 William Cheng: You know, giving you everything that you need to do. Colonel one assignment and then we're going to start talking about the other 10 00:01:25.290 --> 00:01:37.890 William Cheng: The other part of chapter four. Now I'm going to, you know, start with a simple, you know, hardware configuration that will be the one that's used in sixth edition UNIX and then we're going to see what kind of operating system, you know, 11 00:01:39.060 --> 00:01:47.760 William Cheng: Sort of functionality is required to support that. So again, this is introductory operating system class. We're not going to get too fancy with all the advanced features. Yeah. 12 00:01:48.570 --> 00:01:58.620 William Cheng: The application. Look at the operating system as the computer, right, because the application they try to use the hardware and the only way they can use the hardware is to go through the operating system. 13 00:01:59.250 --> 00:02:03.060 William Cheng: So, so the operating system sort of needs to provide a sort of a convenient way. 14 00:02:03.630 --> 00:02:12.990 William Cheng: Over here says, you know, the audience's me to provide a consistent and the usable interface. So, so the interface will be here. We're not talking about a graphical user interface, but we're talking about a system called interface. 15 00:02:13.380 --> 00:02:19.350 William Cheng: Okay, the operating system just to provide you know some kind of an interface for the application to use the operating system. 16 00:02:19.800 --> 00:02:26.040 William Cheng: Okay, so it needs to be consistent and needs to be, you know, usable in the sense that no matter how hardware changes. 17 00:02:26.670 --> 00:02:33.630 William Cheng: Well, we're sort of hoping that once we come up with a good operating system design, we never really have to make major changes to the operating system. Right. Otherwise, if you 18 00:02:33.870 --> 00:02:39.570 William Cheng: Know, every time somebody come up with a new piece of hardware, you have to redesign the operating system. You have to redesign the operating system interface. 19 00:02:39.840 --> 00:02:44.130 William Cheng: Then the application programmer is gonna say forget it. This is too complicated. We're going to move to another operating system. 20 00:02:44.670 --> 00:02:55.410 William Cheng: Okay, so therefore the design is very important. And in chapter four. We're going to look at some of the very high level design issues. Yeah. And on top of everything. You also need to be secure. You also need to be efficient. So again, 21 00:02:56.010 --> 00:03:03.690 William Cheng: In the end, this is a very, very tall order. So that's why there's really not too many successful general purpose operating system out there. Okay. 22 00:03:04.980 --> 00:03:14.610 William Cheng: So, so, so the goal of this class is not to build a specialized operating system building a specialized albinism is actually pretty simple, right, especially if you open this is the only has to do one thing. 23 00:03:15.090 --> 00:03:21.210 William Cheng: Upon in that case is pretty simple to call with the appliances that does only one thing. Okay, we want to open this is him to do well in everything. 24 00:03:21.660 --> 00:03:27.990 William Cheng: Okay, so, so of course it's not possible to do to be watching everything. So again, you need to study design trade off. You need to choose, you know, 25 00:03:28.410 --> 00:03:35.940 William Cheng: Which design is better for what and and when you make that design decision. What are you losing in terms of, you know, other kind of functionality. 26 00:03:36.450 --> 00:03:42.720 William Cheng: OK. So again, there's no free lunch, you know, whatever design decision you make, it's going to gain something and you know, chances are, you know, 27 00:03:43.410 --> 00:03:50.100 William Cheng: You're going to lose somewhere else. Yeah, so the system that we that we that we truly have the general the general purpose often is this and what kind of system is that 28 00:03:50.640 --> 00:03:55.740 William Cheng: You know, it's, it's an interactive system their user using multiple different things have a graphical user interface. 29 00:03:56.280 --> 00:04:03.510 William Cheng: Use the network indication that use the file system, all these kinds of stuff that you enjoy when you use a laptop or you use your desktop. Yeah. 30 00:04:03.990 --> 00:04:13.260 William Cheng: It's like most of the general purpose organism that we have today, right, Linux, you know, free BST Solaris, which is the Unix operating system Mac OS X, you know, 31 00:04:14.160 --> 00:04:27.960 William Cheng: You know, Windows over here. It says, you know, chromium, yo. So, I mean, the Chrome computer. They're really, they don't really have a real operating system. So to have a funny operating system, even though the colonel is based on the Linux kernel. Okay, so, so I guess. 32 00:04:29.220 --> 00:04:35.850 William Cheng: That's what I do to do, I'll do, I'll pull up an assignment you know I don't recommend people using a Chrome, you know, system to to to our programming seven 33 00:04:37.020 --> 00:04:40.710 William Cheng: Right. But all the other ones they are regular, you know, general purpose operating system. 34 00:04:40.980 --> 00:04:46.500 William Cheng: And in a way, they all have same kind of features, even though, if you ask these operating these these audiences and designer. 35 00:04:46.770 --> 00:04:52.350 William Cheng: They all say that there are things is completely different from their competitors. They're all much better, but in reality they're pretty some pretty similar. 36 00:04:52.770 --> 00:05:01.920 William Cheng: They all support the concepts of processes and the processes are multi threaded. They all have file system, they all have the same kind of networking protocol is in TCP IP today. 37 00:05:02.400 --> 00:05:09.870 William Cheng: The user interface. These graphical user interface. They look a little different, but they're basically the same thing, right. They have a display of a mouse and keyboard. 38 00:05:10.620 --> 00:05:18.030 William Cheng: You know, all these kind of stuff. The last one over here is a little weird. It says the access control is based on file ownership that the file owner can control. 39 00:05:18.840 --> 00:05:29.100 William Cheng: Where the general purpose happens is that when you create a file. You get to decide who have access to this file. Okay, they are operating system out there. Once you create a file, you don't get access to this file. 40 00:05:29.520 --> 00:05:30.600 William Cheng: Right. So what kind of computer game. 41 00:05:31.050 --> 00:05:41.250 William Cheng: What kind of computer, something like that. Right. So if you think about like a military computer or like a, you know, CIA computer or something like that where you write a piece of document as soon as you follow it, you lose control of that particular file. 42 00:05:41.580 --> 00:05:49.920 William Cheng: Guys are the general operating system if I'm the owner of the file I get to decide who gets access to file, guys. Oh yeah, all these albinism. They all have very, very similar features. 43 00:05:51.270 --> 00:05:59.520 William Cheng: Right. So some of the criticism design issue is that, you know, the performance has to be good, right, the application has to run fast. They have the battery efficient. 44 00:05:59.790 --> 00:06:11.250 William Cheng: They also have to be efficient in the use of memory. So again, there are trade offs between speed a state your state space and time. So again, it's, it's kind of a hard choice to make the other one. So, so the first one kind of obvious. It needs to perform fast. 45 00:06:12.600 --> 00:06:18.300 William Cheng: What will you do that operating system. It's also nice to be modular right so if you take the software design, you know, software software. 46 00:06:21.360 --> 00:06:22.860 William Cheng: What is gonna software engineering class. 47 00:06:23.430 --> 00:06:29.850 William Cheng: So one of the things that you learn that you have to have modules and you need to cut things down into these little modules, you have to go through functional interface. 48 00:06:30.150 --> 00:06:36.330 William Cheng: When you go from one module to the other. So that's a nice design, but you know clearly this go against performance. 49 00:06:36.810 --> 00:06:43.200 William Cheng: Okay, every time when you go to a function, you're going to slow down, right, because when make a function we're going to push all the stuff onto the stack and then make a function call. 50 00:06:43.740 --> 00:06:52.620 William Cheng: It will be nicer if you can use global variable and things like that there'll be a lot faster. Okay. But again, so, so, so, so, so these two things actually go against each other guys. So if you like. 51 00:06:53.340 --> 00:07:02.130 William Cheng: You know modularity, you're going to end up losing performance, right. There are many systems out there that was designed by, you know, sort of a purist, they want to make the opposite. 52 00:07:02.640 --> 00:07:07.110 William Cheng: Module as possible. In the end, the performer was so bad that nobody actually use those operating system. 53 00:07:07.770 --> 00:07:17.490 William Cheng: Okay, so, so, so in the end you sort of have to strike a balance between performance and modularity. Okay, even though modularity is a good idea. Right. But you got to be very, very careful you don't want to kill your performance. 54 00:07:18.210 --> 00:07:25.260 William Cheng: Yeah. And also, you know, we want to have one the operating system to be device independent right so we need to design the operating system so that 55 00:07:25.500 --> 00:07:33.690 William Cheng: I mean, so again, what is the advice independent me as a typically when we talk about operating system is that we want the organization to be independent of future devices. 56 00:07:34.380 --> 00:07:39.360 William Cheng: Okay, so this way when some people come up with new devices in the future. We don't have to redesign our operating system. 57 00:07:39.720 --> 00:07:45.510 William Cheng: Right. So that will be the real goal. But again, I mean if you design optimism. You cannot predict the future. How do you make sure that 58 00:07:45.870 --> 00:07:53.730 William Cheng: You know, whatever you did over here it's guarantee that is going to work with future devices. Well, there's no guarantee. So you try to do your best right user experience or just whatever you learn 59 00:07:54.270 --> 00:08:02.850 William Cheng: To to, you know, to, to, to, to, to make sure that when when they're when there's a new device, there's a good chance that you don't have to, you know, change often system. 60 00:08:03.300 --> 00:08:12.390 William Cheng: Okay. And, and, again, that's one of the reason we have so few, you know, general purpose ordinances there because these operating system or the one that does that stood the test of time. 61 00:08:12.870 --> 00:08:21.630 William Cheng: Right. So, after all these years, they're still, you know, the they're still around. So, so that means that their design. It's actually pretty good, right, because otherwise they won't survive this law. 62 00:08:22.350 --> 00:08:25.620 William Cheng: Well, and also finally again. So in this console whenever we talk about us. 63 00:08:25.920 --> 00:08:33.510 William Cheng: Closer security, we're talking about isolation. We want to isolate the application from each other. Also weren't as isolated operating system on the application. 64 00:08:33.690 --> 00:08:40.170 William Cheng: Right. So yeah, those are important design issues right if application can actually peek into the operating system and nobody's going to use your operating system. 65 00:08:40.620 --> 00:08:49.080 William Cheng: OK. So again, the kind of make sure that well. So the configuration that we see in the simple operating system or your sixth edition Unix 66 00:08:49.590 --> 00:08:56.430 William Cheng: Sort of this picture sort of summarize what we have, we have a CPU again processor CPU core we use them interchangeably. 67 00:08:57.360 --> 00:09:04.080 William Cheng: primary storage refers to memory. Okay, so this is your physical memory right you have forkball you know four gigabyte egging by six and goodbye. 68 00:09:04.320 --> 00:09:10.170 William Cheng: That's your physical memory. So the terminology nominee system or in computer science that that's called primary storage. 69 00:09:10.740 --> 00:09:20.460 William Cheng: Okay, so will your pro any to store or something. Where do you store them. Well, primarily going to store them in memory. So, therefore, this primary storage, right. What about the secondary storage. The secondary storage storage is your desk. 70 00:09:20.790 --> 00:09:24.840 William Cheng: Right. So if you want to save someone through this and this guy's little you know it's going to take a little longer. 71 00:09:25.140 --> 00:09:30.120 William Cheng: Because save data onto the day. So you have to go through the bus, you have to use device driver for you to talk to the desk. 72 00:09:30.570 --> 00:09:42.120 William Cheng: Okay, so, so in this simple operating system. You know, we got to have physical memory. And we also got to have a desk and the way that we access physical memory over here is that we have to go through a memory map. 73 00:09:42.990 --> 00:09:50.490 William Cheng: Okay, so, so, you know, just in the first part of today's lecture, I mentioned that you know when you boot Linux in the middle of the boot process. 74 00:09:50.760 --> 00:09:59.730 William Cheng: You know, we're going to turn will address translation. Why don't you turn on address translation and the only way to access primary storage is through a memory map is is through the use of 75 00:10:00.420 --> 00:10:04.290 William Cheng: Of a page table right because once we turn will address translation that are 76 00:10:04.590 --> 00:10:12.780 William Cheng: Coming out the CPU is going to be virtual address and then you need to perform address translation to translate a virtual address into physical address before you can access memory. 77 00:10:13.500 --> 00:10:18.660 William Cheng: Okay, so in this case our sixth edition units are simple opportunity. So we are required to use virtual memory. 78 00:10:19.710 --> 00:10:27.690 William Cheng: Okay, so in the good old days when you know Microsoft com with dos. There's no virtual memory, there's, you know, you can only use physical memory. So again, those are those are those are not real operating system. 79 00:10:28.050 --> 00:10:36.540 William Cheng: Real operating system require us to use virtual memory. Now we need to use, you know, the computer is kind of useless today without the internet, right. So, therefore, they have to have an 80 00:10:37.230 --> 00:10:47.400 William Cheng: Interface that call to the internet. And then the sort of the basic interaction with the user is done using a terminal. Right. So what is the terminal. Terminal is that Google been to, you know, terminal that you run 81 00:10:48.240 --> 00:10:53.550 William Cheng: That so so when you're dealing with a terminal. That means that it's not a graphical display is actually a text display. 82 00:10:53.820 --> 00:11:02.490 William Cheng: Typical good display over here is at columns and characters y and 24 columns vertical the right whenever you start a terminal. That's what it looks like. Okay, so that's a terminal. 83 00:11:03.060 --> 00:11:07.080 William Cheng: So, so this terminal has a display can display one character at a time, and I mentioned before. 84 00:11:07.290 --> 00:11:12.600 William Cheng: Every character you put on the screen is going to generate interrupt and they inside Eve observers, wouldn't you put the next character onto the screen. 85 00:11:12.720 --> 00:11:22.770 William Cheng: Right, so it's a very, very slow device there, and also every key present you press on the people is also generate interrupt. So that's the kind of system that we're dealing with. Right. It's a very, very slow, you know, terminal device. 86 00:11:23.370 --> 00:11:28.320 William Cheng: There's also extra thing over here is the alarm clock. Okay, it's very, very important to have an alarm clock. 87 00:11:28.620 --> 00:11:36.330 William Cheng: Because, you know, if you don't have an alarm clock once a threat run inside a CPU. If this were refused to give up the CPU. How do you make this thread give up the CPU. 88 00:11:36.900 --> 00:11:38.190 William Cheng: Well, there's no way for you to do that. 89 00:11:39.030 --> 00:11:45.960 William Cheng: Because whatever we have to do is that we have to use something called a time slice scheduler right where you are threat guess start running out of CPU. 90 00:11:46.110 --> 00:11:52.500 William Cheng: We're going to set up an alarm clock for your time slides. So, time flies, you know, maybe it's one millisecond maybe 10 millisecond something around there. 91 00:11:52.830 --> 00:12:04.530 William Cheng: Okay, so if you're a threat give up the CPU voluntarily. Then we're going to stop the timer. But if your thread doesn't give up the CPU voluntarily when the timer goes off, we're going to yank your third of the CPU. We're going to give the CPU to somebody else. 92 00:12:04.980 --> 00:12:14.550 William Cheng: Or I. Why do we do that because if we don't do that. Some of the thread will starve. Okay, so if a threat. You know, if a thread inside your operating system can starve. Nobody's going to use your operating system. 93 00:12:15.180 --> 00:12:21.450 William Cheng: Okay, so, so, so you got to make sure that when you design your operating system, no threat can ever can ever start that 94 00:12:22.620 --> 00:12:33.210 William Cheng: So this is, you know, 1970 1980 operating system and this is the focus of our class. They don't even have support for bitmap display or a mouse in 19 you know 1980s. 95 00:12:33.690 --> 00:12:43.410 William Cheng: So generally, this is less efficient, but again we're sort of we're going to worry about efficiency, but we don't worry about the, you know, to, to be super fast. We just need to be sort of reasonably fast. 96 00:12:44.010 --> 00:12:49.560 William Cheng: Right, so, so we're gonna sort of talk about some of the issues to say, well, if you do this is going to be really, really slow and therefore it's not acceptable. 97 00:12:49.680 --> 00:12:57.480 William Cheng: So we need to improve that. But, you know, some of the stuff we don't need to be super efficient. We just need to be reasonably efficient, right. So, for example, using the first good memory alligator. 98 00:12:57.690 --> 00:13:02.160 William Cheng: We know that it's not the most efficient thing but it's acceptable. So therefore, we're going to keep that. Yeah. 99 00:13:03.960 --> 00:13:14.280 William Cheng: Alright, so go. We're going to see this picture, you know, multiple times right at the top over here is going to be the application. It's in the user space in the middle. Over here, we're going to have the operating system. It's in the it's in the kernel space. 100 00:13:14.700 --> 00:13:19.740 William Cheng: The bottom parts hardware. Right. So typically, you know. Now, we talked about audiences and design we typically don't draw the hallway. 101 00:13:20.040 --> 00:13:32.280 William Cheng: Right, so we know that's below this, and we know that between the Japanese descent and the hardware. There's a hardware abstraction layer. So this way, your organization can be just the opposite. You obviously in the kernel can also be hardware independent. Yeah. 102 00:13:35.070 --> 00:13:42.780 William Cheng: Alright, so we're going to, sort of, you know, discuss a bunch of stuff. So the first picture over here is that, you know, if you want to divide the audiences. 103 00:13:43.020 --> 00:13:49.620 William Cheng: Into different components. So again, this is completely inside of Colonel right we're not looking at user space anymore. So this is inside the operating system. 104 00:13:49.980 --> 00:13:56.160 William Cheng: Okay, there's a bunch of, you know, subsystem over here. Here's processor a management. Here's memory management. 105 00:13:56.400 --> 00:14:04.800 William Cheng: And as soon as you see this picture, you will see that you know that division over here is not very clean cut. Because clearly, there's something over here that can go across multiple you know 106 00:14:05.250 --> 00:14:06.660 William Cheng: multiple parties subsystem. 107 00:14:07.290 --> 00:14:12.990 William Cheng: OK. So again, the substance me just conceptual that you think about you know that they're sort of separate parties that Colonel 108 00:14:13.170 --> 00:14:18.870 William Cheng: Pretty reality they're really not completely separate right because their stuff that goes across both of them. So, therefore, they're not separate 109 00:14:19.050 --> 00:14:27.090 William Cheng: Okay, so we have process management memory management and I will management. So the reason that this is drawn into three different pieces over here is that because that's the focus of this 110 00:14:27.450 --> 00:14:37.140 William Cheng: Of the textbook. We're in chapter five. We're going to talk about process or management and chapter six. We're going to talk about. I will manage manage chapter seven. We're going to talk about memory management. 111 00:14:37.560 --> 00:14:46.890 William Cheng: Okay, so this is more all of them organization of the textbook as opposed to, you know, inside the Colonel, you're going to have these clear cut, you know, a pieces that are completely separate it. 112 00:14:47.070 --> 00:14:54.450 William Cheng: And again, I mentioned that long time ago, people try to do that. And in the end, the performance was so bad that the nobody want to open a system like that. 113 00:14:55.020 --> 00:15:03.300 William Cheng: Okay, so he reality when he's global variables. We're going to sort of shortcuts you know for one part to talk to the other part and this way we can have reasonable performance. Okay. 114 00:15:05.520 --> 00:15:15.660 William Cheng: Alright, so let's talk about some of the parts over here processors as threads over here. Again, they go across processor management also memory management because you know the program to only use virtual address space. 115 00:15:16.140 --> 00:15:18.930 William Cheng: While physical the OB here we're going to end up with physical memory now. 116 00:15:19.410 --> 00:15:32.340 William Cheng: So so so the basic assumption over here is that in sixth edition union they support multi threaded processes and every process has his own address space. Okay, and also in sixth edition Unix two processes can I share an address space. 117 00:15:33.060 --> 00:15:45.840 William Cheng: Okay, so you later on, you know, the more modern operating system. You can have to process issue in the same address space or have to process is sharing part of the address space. Okay, but in the 60s Unix would only have that. So, most of the time we're going to talk about six minutes. Yeah. 118 00:15:46.860 --> 00:16:00.750 William Cheng: By the way over here. There's a note again. Right, so, so, so we go, you know, in chapter four. I'm going to sort of start referring to the weaning circle problem means. Mmm. Then, so one reminder over here is that for the winnings programming assignments every process only has one threat. 119 00:16:02.010 --> 00:16:08.790 William Cheng: Okay, but somebody was in a while. So how do I create another 30. So the process. Well, I mean, if every process can only have one sec. Let me say, you can do it. Period. 120 00:16:10.110 --> 00:16:11.190 William Cheng: Okay, so how do I, you know, 121 00:16:12.360 --> 00:16:20.310 William Cheng: How do I give the threat to another process right so it's it's okay if you want to create another threat. First you have to create another process and create a thread inside of that process. 122 00:16:20.850 --> 00:16:31.530 William Cheng: Right, because that's what it means to say empty p zero multiple separate process equals zero. That means that every process has to have exactly one thread right if you want to create two three. What does that mean that means that you have two processes. 123 00:16:32.340 --> 00:16:34.440 William Cheng: Right, because otherwise it's not gonna work. Yeah. 124 00:16:36.000 --> 00:16:40.230 William Cheng: All right, you know. Okay, so again, you know, the only way to access virtual memory is 125 00:16:40.410 --> 00:16:50.100 William Cheng: The only way to access, you know, real memory is by going through the virtual memory map right so we'll be here. You know, so, so, so one of the requirement over here is that we have to use virtual memory system so 126 00:16:50.340 --> 00:17:00.270 William Cheng: You know when you write your program you'll program the address of your program has to be in the virtual address space, then the virtual address space for your program is four gigabytes for 32 CPU. 127 00:17:00.930 --> 00:17:08.070 William Cheng: And then we go to address translation to access it, you know, to access the physical memory and password again that's a requirement for system like that. Yeah. 128 00:17:09.390 --> 00:17:24.390 William Cheng: The scheduler over here. I mentioned before, it's a time size scheduler. Okay. Whenever you start running out of CPU. We're going to start a timer and we're going to go from there. Yeah, four weeks over here weenies over here. They do you know the the scheduler okay its first come first serve. 129 00:17:25.560 --> 00:17:29.220 William Cheng: Okay, so first come first serve. So what does it mean first come first serve rice. Oh, so 130 00:17:29.700 --> 00:17:37.710 William Cheng: You know, if you have a Q over here, right. You, you add a thread, you know, into the into the school over here and they are you going to serve you know you don't serve this you first come first serve. 131 00:17:38.220 --> 00:17:45.330 William Cheng: I mean, some people actually, you know, you know, as it turns out, you know, kernels. I meant if you don't implement first come first serve the critical hurdle still going to work. 132 00:17:46.500 --> 00:17:55.530 William Cheng: Okay, it's gonna work a little differently. But again, there's no you know i mean the idea over here is that you're supposed to be a first come first serve. But some people have bugs in here. They'll colonel in the end it's not first come first serve. 133 00:17:55.710 --> 00:18:04.980 William Cheng: But as it turns out to still work. Okay. But again, please understand that design of the Linux operating system is that you're supposed to do first come first serve neck right your implementation may vary. 134 00:18:07.290 --> 00:18:15.810 William Cheng: And the automatic system over here. So we talked about. I, oh, the first thing that comes to mind is the file system because the file system is very, very important. Right. The file system over here. 135 00:18:16.290 --> 00:18:25.800 William Cheng: It's layer on desk right this is this is hardware that is at the bottom over here and also in order for you to get to the days, you need to. You go to the controller in order for you to talk to this controller. 136 00:18:25.980 --> 00:18:30.660 William Cheng: You need to use the device driver. So again, this you know the file system over here is actually very complicated. 137 00:18:30.990 --> 00:18:37.620 William Cheng: Okay. In some textbooks. They will spend two or three chapter on file system in our textbook. We only spent one one chapter 138 00:18:38.460 --> 00:18:45.540 William Cheng: Okay, so, so, so, so again, you know, for, for the first introductory operating system cloud, they can they can go really complicated insight into the file system. 139 00:18:46.080 --> 00:18:55.710 William Cheng: So luckily for our class. We only spent one chapter on it. Okay, so, so again as fast as them as complicated typically there are many, many layers so if 140 00:18:56.370 --> 00:19:03.360 William Cheng: I guess in our class we sort of said that there are basically three layers. There's a file system over there. And then there's something called the logical IO management. 141 00:19:03.570 --> 00:19:12.870 William Cheng: That manage not only the file system, but also the networking substance em. And also, you know, talking to the keyboard on the device. They all use the same kind of logical Iowa management. 142 00:19:13.500 --> 00:19:17.460 William Cheng: Okay, so later on. Later on we're going to sort of see what this is right, but you know again. 143 00:19:17.730 --> 00:19:25.830 William Cheng: The fastest them. It's complicated. At the bottom over here where the device driver, the device driver can talk to the device controller and then the device controller can talk to the device. 144 00:19:26.160 --> 00:19:37.050 William Cheng: There. And then what we do is, I will do we will, we're going to use our we use our file system. But then in order for the system to get to the device driver. We're going to go over one layer of one layer of indirection. 145 00:19:37.860 --> 00:19:43.260 William Cheng: Okay. As we mentioned before, you know, whenever you have a, you know, the computer science people like to sell problem with one layer of indirection. 146 00:19:43.740 --> 00:19:50.670 William Cheng: So so so typically anyone Larry and direction, adding one layer of indirection is going to end up giving us a lot of flexibility. 147 00:19:51.630 --> 00:19:57.810 William Cheng: Okay, so later on. Towards the end of chapter, chapter six, or whatever. We're going to sort of take a look at what kind of flexibility that you can get 148 00:19:58.170 --> 00:20:06.570 William Cheng: By using this you know one layer of indirection. And again, once you start using one layer of indirection nobody can stop you from using two layer of indirection three very direct. 149 00:20:07.140 --> 00:20:15.510 William Cheng: Interaction. So in the end, you know, the file system can get very complicated. Okay. Alright. So anyways, you know what we've got to chapter six. We're going to see that a little more 150 00:20:17.070 --> 00:20:22.710 William Cheng: The human interface devices over here. Again, it's going to be the keyboard is going to be the mouse where I would call it the terminal. 151 00:20:23.250 --> 00:20:27.510 William Cheng: It has a touch interface typically 24 rows and 80 characters across 152 00:20:28.110 --> 00:20:33.480 William Cheng: Every character that you type on the keyboard or, you know, it's going to generate you know Rob's over here is that is sent to the processor 153 00:20:33.720 --> 00:20:41.220 William Cheng: How do you send to the process, right, because the device you generate in a Rob and then use that to interrupt service routine to see the CPU sort of pick up what kind of character was pressed 154 00:20:41.820 --> 00:20:46.440 William Cheng: Okay, so. So again, that's the kind of device that we have to deal with every character you put on the screen. 155 00:20:46.620 --> 00:20:50.640 William Cheng: We're going to generate, you know, Rob. And then when the you know when when the character finished display on the screen. 156 00:20:50.820 --> 00:21:00.000 William Cheng: Then you put the next character on the screen and then you put the so you put the screen character on the screen one character at a time. Okay, so again the human interface devices over here is a very, very small device that 157 00:21:00.690 --> 00:21:14.670 William Cheng: The network protocol we hear is TCP IP. So in this class we not going to talk about networking. Very often we are in chapter four. We're going to talk a little bit about TCP IP. Okay. But then we're going to sort of move on. Okay. And the reason for that is I, you know, in graduate 158 00:21:16.920 --> 00:21:24.150 William Cheng: Graduate school. They are networking class that's sort of talk about, you know, all these issues, they are you know security classes just all the security problem over here. 159 00:21:24.570 --> 00:21:32.190 William Cheng: So we're going to study. So if you're interested in those topics you should take those classes there. So we're here, we're going to briefly talk about TCP IP now. 160 00:21:32.460 --> 00:21:43.230 William Cheng: And also there's a note over here, said the winnings operating system actually doesn't have networking. OK. So again, the weaning softness to them. It's a toy abundances them as it turns out, the winnings, how it is that doesn't even have a timer. 161 00:21:44.520 --> 00:21:52.080 William Cheng: Okay, so we just mentioned that time is very, very important. So you can implement a time slice scheduler. So we need this first come first serve them. They don't have time slicing 162 00:21:52.680 --> 00:21:57.990 William Cheng: Okay, so if you have a threat that doesn't give up the CPU, guess what, no. No other so that gets to run 163 00:21:58.950 --> 00:22:11.430 William Cheng: OK. So again, when you try to, you know, sort implement your colonel colonel Simon, you got to keep that in mind if you're, say it doesn't give up the CPU voluntarily no other thread whatever running the CPU. OK. So again, very important consideration. Okay. 164 00:22:13.200 --> 00:22:23.190 William Cheng: All right, so you know some of the, you know, operating system concept again processes, then through a file system devices. Now we're all this kind of stuff. So, so 165 00:22:23.580 --> 00:22:29.220 William Cheng: The idea here is that we're going to sort of see how the operating system provide all these feature again. Chapter four is just introductory 166 00:22:29.580 --> 00:22:35.520 William Cheng: We're going to sort of talk about some of the high level concept in chapter five, six and seven. We're going to talk about implementation details. 167 00:22:35.850 --> 00:22:45.450 William Cheng: Okay, so again, chapter one and two. You got the introduction or what a process is what a threads in your program assignment. Use a process use multi threading, right, all these things I've done in the user space. 168 00:22:45.750 --> 00:22:49.290 William Cheng: Okay 567 we're going to see how they implement. Okay, so now we're in chapter four. 169 00:22:51.330 --> 00:22:55.680 William Cheng: All right, so. So again, the purpose of a process. The yeah so 170 00:22:56.850 --> 00:23:06.210 William Cheng: That was sort of mentioned that before, right, that, you know, sort of the fundamental abstraction of executing a program is that you need an address, you need to CPU and you need a context for execution. 171 00:23:06.630 --> 00:23:14.490 William Cheng: So again, everything sort of started out with the with the with the idea of a process. Okay, so, so, so the purpose of a process. Why do we need process is to 172 00:23:14.790 --> 00:23:22.710 William Cheng: hold an address space. Okay, so that's why every time when I think about a process I draw the address space, right, because when you think about a program or process is a running program. 173 00:23:22.890 --> 00:23:26.400 William Cheng: The program has an address space right so in so you probably have all these variables. 174 00:23:26.610 --> 00:23:34.890 William Cheng: You have code and all that kind of stuff in them. Right. And the purpose of running code is to manipulate all these global variables. And this way you know you probably know how to proceed. Yeah. 175 00:23:35.460 --> 00:23:41.430 William Cheng: Alright, so he's not a positive over here. And if you want to have multiple CPU, you want to take advantage of them. You're going to run out. Are you going to run a multi threaded 176 00:23:41.820 --> 00:23:48.990 William Cheng: multi threaded our program, so, so, so a process also holds a group of friends together and they will share the address space. 177 00:23:49.380 --> 00:23:57.810 William Cheng: Right, so. So again, you know, in the others way there's only one tech segment that's shared by all the threads. There's one data is one PSS there's one heap segment their shared by all the threads. 178 00:23:58.470 --> 00:24:03.480 William Cheng: But every thread has a separate stack space, right. So this way, they can all run in parallel, then 179 00:24:04.920 --> 00:24:12.600 William Cheng: They also hold a collection of references to open files and other execution context. Are we mentioned about you know how to say contacts, how to restore contacts. 180 00:24:12.840 --> 00:24:19.980 William Cheng: And here's an example. When you open the file. You also need to keep that kind of context, right. So there are all kinds of context of mission, you have to hold right. For example, if you 181 00:24:20.520 --> 00:24:27.870 William Cheng: If you change the the signal mass, the signal mass is also the cut the contents of your process. So again, we need to be able to save her. When you to be able to 182 00:24:28.800 --> 00:24:39.540 William Cheng: Restore all kinds of contacts you have to save you know for your program. Okay. And the operating system or together with the P3 library, you know, working together, they will be able to achieve all these kind of things right. 183 00:24:40.740 --> 00:24:51.960 William Cheng: So let's talk a little bit about address space, you know the address space over here. Again, what is the address space address may just means addressable memory location go from zero all the way to zero, x F, F, F, F, F, F, F, F. 184 00:24:52.290 --> 00:24:55.140 William Cheng: So it's just a collection of memory addresses that you allowed to use 185 00:24:55.410 --> 00:25:02.850 William Cheng: Right, so, so the basic concept is very, very simple right when you think about your program you have address ways that you can use that may but but we are already talked about. 186 00:25:03.210 --> 00:25:09.960 William Cheng: You know your user space program can only use the top three quarter of the address space while at the bottom one quarter of the address basis used by the current all 187 00:25:10.200 --> 00:25:17.820 William Cheng: Okay, so, so it's not like you can you can actually use the entire address space there. Alright, so also, we thought, I think about the the the address space was 188 00:25:18.390 --> 00:25:24.000 William Cheng: We should think about how does the address space hold these contents. Okay. So for example, you have a tech stack, man. 189 00:25:24.360 --> 00:25:32.040 William Cheng: How does it takes up. Where does the tech seven come from. Right. And we sort of mentioned that you know you executable file or executable files sitting under this this over here. 190 00:25:32.280 --> 00:25:40.170 William Cheng: The executable file has a tech segment has a data segment has a BSS like man, right, when we load your program that we create the space. 191 00:25:41.070 --> 00:25:51.870 William Cheng: Okay, so he's not the only way that, as it turns out that that's really not the only way right because when you fall off the trial process when you fork. You also get a copy of the address space, right, so, so, so again, this is not the only way 192 00:25:52.350 --> 00:25:56.880 William Cheng: So we need to sort of talk a little bit about address space right now to say, you know, how do you actually initial as an address space now. 193 00:25:57.120 --> 00:26:05.130 William Cheng: And again, the way we sort of VR address space is that the address space is consists of these memories segments where I will call them text document data segment the PSS segment. 194 00:26:05.370 --> 00:26:13.470 William Cheng: The heap segment and the stacks that grant. And then if you are doing multi 30 you can have multiple stacks, like, man, you know, here, over here at the bottom. Okay. 195 00:26:14.640 --> 00:26:19.380 William Cheng: All right, so. So again, the idea of a segment right is that, you know, the segment can 196 00:26:19.950 --> 00:26:30.420 William Cheng: Contain usable contiguous memory addresses. Okay, so when you have a memory segment over here. If this is a tech segment. Yeah, you know, every location is that in tech segment is something that's 197 00:26:31.020 --> 00:26:37.350 William Cheng: Something that you can use. Okay, so we are not allowed to take the tech segment and really breaking into multiple attack segments. 198 00:26:37.800 --> 00:26:45.780 William Cheng: Maybe in the more modern operating system we start doing that. But again, the sixth of June. So we'll only have one tech stack man, and they have contiguous memory addresses. 199 00:26:46.050 --> 00:26:52.350 William Cheng: There and then there you go to data segment over here. There might be a gap as we saw before, you know, at the end of 200 00:26:53.790 --> 00:27:00.900 William Cheng: A couple of lectures before between the text on the data side where there might be a gap right between them. Right. You know, because you know because we're doing paging 201 00:27:01.290 --> 00:27:08.760 William Cheng: So, therefore, you know, the you know the the the data segment has to start at a page boundary. So definitely this case, we could end up having a gap between the types that 202 00:27:09.030 --> 00:27:14.670 William Cheng: data segment now and now here we have data segment and and BSS come immediately after the data segment. 203 00:27:15.120 --> 00:27:21.540 William Cheng: As it turns out, you know the the heap segment again different audiences them. That is not what they want to do with the heats up, man, they can they can start 204 00:27:21.810 --> 00:27:26.610 William Cheng: That they can start right after the BSS like man, or they can start at a pace boundary 205 00:27:27.150 --> 00:27:35.640 William Cheng: So again, depending on the system. And finally, the stack segment the stack, said the world was sort of thinking about is that there's a stack space get inside the stack space. And there's a stack segment. 206 00:27:36.000 --> 00:27:40.230 William Cheng: Okay, so this next segment. Over here is your typical he started out to be smaller than this tax base. 207 00:27:40.920 --> 00:27:55.710 William Cheng: You know, but again it can grow as big as as as tax base right and the stack space. Typically, they start at a page boundary. OK. So again, the address space at the bottom over here or we try to create a static space. They start at, you know, multiples or four kilobytes. Yeah. All right. 208 00:27:58.110 --> 00:28:06.990 William Cheng: Okay, so some of these issues over here is that, you know, how do you initialize the address space of a program. So again, you know, for the Unix operating system again different offices me initialize the address as a little differently. 209 00:28:07.230 --> 00:28:10.830 William Cheng: For Unix and Linux operating system that typically do this in two steps. 210 00:28:11.490 --> 00:28:22.080 William Cheng: Okay, the first step is for writing. The second step is exactly. Okay, so will you. Will you make the food system call again the parent process, create a child process and the child process gets a copy of the parents address space. 211 00:28:22.710 --> 00:28:31.560 William Cheng: OK. So again, the use the parent process. Here's the child process. So again, whenever, whenever I think about a process I draw the address space right here is the address space of the parent 212 00:28:31.770 --> 00:28:40.590 William Cheng: And here's the address space of the child at the time when you create a child. I'm going to make a copy from the parent to the shop. So to tell us address space is going to be exactly the same as the parent 213 00:28:41.760 --> 00:28:48.330 William Cheng: Okay, so, so be on the on this is four gigabyte right four gigabytes over here is going to take a very long time to copy them. So, you know, 214 00:28:48.870 --> 00:28:54.480 William Cheng: In that case, if you have to copy four gigabytes of memory. The performance is going to be so slow. That's really not acceptable. 215 00:28:55.320 --> 00:29:06.540 William Cheng: Okay, so typically over here, we sort of need to worry about performance. We need to do a little faster. So as it turns out, what we can do that, we can actually share the address space. So what. So this is what can you share. Right. I mean, clearly you can share the tech segment. 216 00:29:06.900 --> 00:29:14.190 William Cheng: Right. So if I take my address space over here, I divide him to segment of the texts like me. I did. I said, My IPS is not the heat up the stack, like this. 217 00:29:14.430 --> 00:29:20.670 William Cheng: Right, the child processes, the child classes can easily share the tech segment right because the tech segment we mentioned before, it's read only. 218 00:29:21.660 --> 00:29:25.140 William Cheng: Right. If a segment is read only one, then that means that you can share or you want 219 00:29:25.620 --> 00:29:31.080 William Cheng: Right, just like the readers of the writers. If you only want to read. Can you can have as much as much Paolo ism as possible. 220 00:29:31.230 --> 00:29:40.200 William Cheng: So, therefore, what we should do is that when we copy the address space over here, we only need to copy the other memories that man and the text. I'm going over here, we can simply share it. 221 00:29:41.040 --> 00:29:44.730 William Cheng: Okay. So this guy is how much savings day we just have 222 00:29:45.210 --> 00:29:49.620 William Cheng: Whereas if you think about your this program is a Microsoft Word Microsoft PowerPoint or Microsoft Excel. 223 00:29:49.800 --> 00:29:56.550 William Cheng: Those are humongous program. So their tech segment is really, really big. Well, in this case, if you don't have to copy or that memory it while you're going to run a little faster. 224 00:29:57.120 --> 00:30:04.800 William Cheng: Okay, the data set one over here and the BS is over here. Typically they're much smaller than that they're much smaller than the text admin. 225 00:30:05.490 --> 00:30:14.040 William Cheng: Guy. So in this case, again, if you don't have to copy the text, man. You know, in this case, that will be a pretty pretty clever algorithm to still to to make this thing a little faster. 226 00:30:14.760 --> 00:30:19.800 William Cheng: Yeah, so, so, so, Linda. Linda is in two steps. The first is the fork over 12 hours as 227 00:30:20.100 --> 00:30:29.880 William Cheng: And also, you know, the, the, the other reason is that what is the child process. Just want to make an exact system called right so in that case, when you make all these copy and then you're going to get rid of the address space. So that would be a total waste. 228 00:30:30.240 --> 00:30:35.850 William Cheng: Okay, so remember the abstraction for the exhaust system call is that the child process will make a system called come inside. Colonel 229 00:30:36.030 --> 00:30:42.120 William Cheng: Why don't you come into the corner over here, you know, we're not using the address space. So we can wipe it off I delete the entire address space. 230 00:30:42.360 --> 00:30:53.550 William Cheng: And then we go to this. Take the new executable program and folded into memory build an address space for it and then again you start executing the math. You know, the startup function is a function will call me inside a new program. 231 00:30:55.140 --> 00:30:59.070 William Cheng: OK, so again this is dying to step and you want them to be as efficient as possible. 232 00:30:59.580 --> 00:31:06.780 William Cheng: Okay so well you fork. You try to share all you can and we try to exactly what we just tried to exact, what would you do so again we're going to take a look at how this is done. 233 00:31:07.590 --> 00:31:14.850 William Cheng: Okay, so remember this, this visual over here, right. We just talked about it in the last lecture. Right. So when you you know 234 00:31:15.270 --> 00:31:21.870 William Cheng: What will the example that we saw over here we have a program that only required 2020 kilobytes of memory. 235 00:31:22.380 --> 00:31:30.120 William Cheng: Okay 20 kilobytes of memory, right. So that's five pages. Okay. Three pages are for the tech segment is over here, one, two, and three for the tech side, man. 236 00:31:30.360 --> 00:31:39.000 William Cheng: The fourth one is what data plus BSS right and the fifth one is for stack. And that's all the way at the bottom. So when we use the pace table, only five entries over here. 237 00:31:39.210 --> 00:31:44.520 William Cheng: The first three entries over here. It's going to be read only. The next one over here is going to be rewriting what about the one for the staff. 238 00:31:44.730 --> 00:31:50.430 William Cheng: Or the stock is for reading and writing. So at the bottom will be is going to be rewriting all the other page table and you know all the other 239 00:31:50.820 --> 00:31:55.320 William Cheng: Other entries inside the page table. They all have no access rights over here is no sex. No, so 240 00:31:55.680 --> 00:32:06.090 William Cheng: So, so the entire and I mentioned before, the page table is going to have 1 million entries inside of her only five of them are valid all the other you know almost 1 million entries there or invalid. 241 00:32:06.810 --> 00:32:12.810 William Cheng: Okay, so this way when you try to access any other part of the outer space, you're going to get a segmentation fault and the opposite will kill your program. 242 00:32:12.930 --> 00:32:24.060 William Cheng: And again, the reason we do that is that we're going to use one level indirection. So this way you know for our program. We only have to allocate 20 kilobytes of physical memory instead of four gigabytes of physical memory. 243 00:32:24.840 --> 00:32:31.860 William Cheng: Okay, so this way. We're going to reduce the, the usage and also we can use the buddy system so we can allocate all these physical pages anywhere we want 244 00:32:32.160 --> 00:32:38.460 William Cheng: You know, wow, when we, when we, when we think about that means that our virtual address space. They are actually contiguous memory locations. 245 00:32:39.240 --> 00:32:48.990 William Cheng: Okay, so he's that virtual address over here and their continuous memory location. That's why they look like the memory segment in reality they all they all map all over the place in a physical memory four kilobytes at a time. 246 00:32:49.980 --> 00:33:00.450 William Cheng: Okay. As we mentioned again. This is really good idea. And we can have a lot of flexibility so I ok so now when you try to perform a fork of a job. Elsa, the child process is going to get a copy of your address space. 247 00:33:01.050 --> 00:33:02.910 William Cheng: That why don't we just share 248 00:33:03.240 --> 00:33:10.680 William Cheng: You know what, you know. So in this case, you know, one of the simple way to do is that, you know, when you create a child processes, the child policy is going to have their own process control bar. 249 00:33:10.860 --> 00:33:13.530 William Cheng: They're going to have their own memory. Mom, they don't have their own pace table. 250 00:33:13.950 --> 00:33:24.420 William Cheng: You know, because the page table here is PR process. Yeah, so therefore your child is going to get their own pace, they will be here for the child. But why don't we just make a copy of the parents page table to the child. 251 00:33:25.530 --> 00:33:28.740 William Cheng: Okay, if we do that, what's going to happen, right. So if we do that, don't look like this. 252 00:33:29.070 --> 00:33:38.940 William Cheng: Okay, here's a parent child other parents patient. Well, here's a chart a stable if we perform a meme copy from the parent to the child when you copy pointer. They point to exactly the same place. 253 00:33:39.480 --> 00:33:46.290 William Cheng: Okay. So this guy is all these access over here. I'm going to have rewrite rewrite rewrite and then at the bottom over here. Everything else is invalid. 254 00:33:46.770 --> 00:33:53.280 William Cheng: The last one over here for the stock is going to be rewrite. Okay. And also these pointer over here, they will point to exactly the same place. 255 00:33:53.970 --> 00:34:02.610 William Cheng: That. So, therefore, if the parent process over here. I tried to access. One of the functions over here. Can the child process. Use that memory location for you. The exactly the same code. 256 00:34:03.120 --> 00:34:11.160 William Cheng: Or the answer, of course, is yes. Right. You know, the example that we saw before, you know, I guess there they associate the system called right is right here. Right. There's a rice system called right here. 257 00:34:11.460 --> 00:34:16.230 William Cheng: Okay, when the child process called the racism car is going to be sitting at exactly the same address. Why is that 258 00:34:16.500 --> 00:34:24.210 William Cheng: Because it's a copy of the address space. So every function, they're all sitting exactly the same place. Okay, so if the parent can use this address 259 00:34:24.450 --> 00:34:31.440 William Cheng: To reach the racism cause of where's the racism. All right. You can follow the pointer over here the racism, called the code for the rest of us actually sitting right here. 260 00:34:32.610 --> 00:34:42.990 William Cheng: Okay, if the child process use exactly the same addresses right here. Also if you follow the point over here it's pointing to exactly the same place. So therefore, the chocolate also make exactly the same function call. 261 00:34:44.370 --> 00:34:47.940 William Cheng: Okay, so this will tell you it's really easy to share the tech segment. 262 00:34:48.240 --> 00:34:57.150 William Cheng: Right. All I have to do is to copy, you know, the parents data table into the child's play table and again when you copy point here. The point is in place. So now for the tech segment. 263 00:34:57.360 --> 00:35:02.190 William Cheng: They all point to exactly the same place. And now I don't have to make copy of these pages anymore. 264 00:35:03.180 --> 00:35:10.980 William Cheng: Okay, so yeah for Microsoft Word, there will be many, many of these pages, but in this case I can share them. I don't have to copy them at all. And all I do is copy pointers over here. 265 00:35:11.130 --> 00:35:21.840 William Cheng: So again, how many points do I have to copy or there's 1 million entries over here. There's 1 million pointer every entries over here. Maybe it's for by songs and this guy. You have to copy four megabytes, and not four gigabytes. 266 00:35:22.740 --> 00:35:27.600 William Cheng: Okay, copying four megabyte is 1000 times faster than copying four gigabytes. 267 00:35:28.620 --> 00:35:33.480 William Cheng: So now it looks really good. So you just you just speed things up by 1000 times 268 00:35:34.050 --> 00:35:37.590 William Cheng: Okay, because you only caught a copy pointers and you don't copy the actual memory content right 269 00:35:37.740 --> 00:35:41.880 William Cheng: If you have to allocate all these data, you can you call the buddy system and memory allocation is not so fast. 270 00:35:42.030 --> 00:35:48.840 William Cheng: So again, you're going to be, you're going to be really so and then you have a copy all this you know all these data blocks. Right. So in this case, you're actually going to say about part of it. 271 00:35:49.050 --> 00:35:59.850 William Cheng: Now in this example, we don't have three pages so so so you don't really, you know, save 1 million entries over here, you know, but. But in general, if you're a tech segment is really, really big cop, you know, being able to share 272 00:36:00.150 --> 00:36:04.770 William Cheng: You know the all the, all these physical physical pages is gonna is actually going to save quite a bit now. 273 00:36:05.400 --> 00:36:13.830 William Cheng: So yeah, this is the power of of indirection. If you have been direction or you have to do is to copy pointers and they will point to the same place. And now you don't have to copy the content. 274 00:36:14.730 --> 00:36:18.750 William Cheng: Then read about the data segment PSS. Are you allowed to share that 275 00:36:19.620 --> 00:36:27.660 William Cheng: Well, I see if you share them. I will be here at the point over your point of this page. Let me see clutter. This little bit by this point good point right here and now the Charles upon to the same place over here. 276 00:36:27.810 --> 00:36:32.940 William Cheng: So if the parent OB as a variable called x over here if the parent says x equals to five. 277 00:36:34.080 --> 00:36:43.830 William Cheng: Okay, the child also see that x equal to five because they're sharing over here, right, if a child it all says x equal the love and what love is. It changes memory location to deliver the parent process will be surprised. 278 00:36:44.370 --> 00:36:53.580 William Cheng: Okay, so this particular trick works really well for the, you know, for the tech segment, but it doesn't work for the data segment for the BSS. It also doesn't work for the stack. Second, 279 00:36:54.330 --> 00:37:03.660 William Cheng: Okay, so therefore we only see a partial solution. So we're going to continue to see what other solutions. You have to have in order for you to share the text other the data segment the BSS segment. Yeah. 280 00:37:06.240 --> 00:37:16.830 William Cheng: Alright, so what about the exact system call okay so will you make the exact system call right you come into the kernel and then one thing that you have to do is you have to wipe all your address space so address space again, there's a 281 00:37:17.040 --> 00:37:28.140 William Cheng: There's a data structure inside of Colonel know is the virtual memory map as it turns out that the virtual memory map is what you will use to represent or what the address face look like right so in that case you what they need that data structure. What about the page table. 282 00:37:29.190 --> 00:37:33.780 William Cheng: So every process has a page table. So if your child process over here called make the exact system call 283 00:37:33.990 --> 00:37:43.680 William Cheng: Then the previous page table over here will be invalid. Right. Why is it about right. So if you think about the other previous program over here to say I have all these functions. This is where all these pages are what are in that case, you know, 284 00:37:44.130 --> 00:37:53.340 William Cheng: You know, now you want to run a new program. So therefore, all these pointer over here will become invalid that. So in this case, what you would do is that you have zero out the entire page table. 285 00:37:53.790 --> 00:37:59.100 William Cheng: Okay, so again, there's four megabytes of the pace, they won't be here. So you just commence men set. And I said, I'm also zero. 286 00:37:59.700 --> 00:38:02.610 William Cheng: Okay, so now you got to end up with a, you know, the blue with empty chop. 287 00:38:02.940 --> 00:38:14.700 William Cheng: Chop a stable. And now what you need to do is that you need to. So since that exact system call you need to go to the executable program, right, because the first argument the excesses of course is the external whole program you're going to unfold it into memory. 288 00:38:15.120 --> 00:38:27.420 William Cheng: Okay. So in this example, this program over here, you know. Guess it's gonna be a similar program. The first three pages over here. It's going to be a text like man, followed by the data plus PSS or something like that. So if we need to, you know, take this. 289 00:38:28.830 --> 00:38:32.070 William Cheng: Take this program over here on folded into memory, what do we have to do. 290 00:38:32.610 --> 00:38:42.240 William Cheng: Okay, for every page inside his profile, we need to call the buddy system to allocate a new page or I'm going to allocate a new page over here and then depends on you know which page, it is then we're going to have the data point to point to it. 291 00:38:42.630 --> 00:38:52.980 William Cheng: Okay, so in this case in this program has 2000 pages over here. We're going to allocate 2000 pages over here. And then we're going to point. All over. All over that and then we're ready to execute our program. 292 00:38:54.330 --> 00:39:00.990 William Cheng: Okay, so that's going to be really slow. Right. So, you know, if you think about this one is Microsoft Word, you know that the tech segment. It's really, really big. 293 00:39:01.170 --> 00:39:06.720 William Cheng: So in that case, we're going to end up, you know, allocating all these memory, you know, have a stable point to it will take a very long time now. 294 00:39:06.900 --> 00:39:13.110 William Cheng: I mean, you know, we use Microsoft Word. Sometimes you just run the program make one modification or one word you say the program, you could your program. 295 00:39:13.680 --> 00:39:16.590 William Cheng: Because in that case, you know how much of the product. We actually use 296 00:39:17.370 --> 00:39:26.040 William Cheng: That we actually, we don't need the entire program. We only need part of part of the program. So in that case, if you load the entire tech segment into memory that will be a total waste. 297 00:39:27.030 --> 00:39:30.150 William Cheng: OK. So again, this will be a good place for some kind of optimization 298 00:39:30.390 --> 00:39:38.700 William Cheng: That. So one thing that you can do over here is going to use the memory mapping technique. Right. So again, which we'll talk about there's there's a virtual memory map data structure inside the Colonel. 299 00:39:38.850 --> 00:39:44.190 William Cheng: So that you can actually map part of your address space into memory and part of your address space on to the desk. 300 00:39:44.760 --> 00:39:50.220 William Cheng: Okay, so this way when you are trying to use your address space that not a physical memory over here if you use it directly. 301 00:39:50.490 --> 00:39:53.970 William Cheng: Okay, but will you try to use your address space that that map to this. 302 00:39:54.210 --> 00:40:00.630 William Cheng: Then in this case the operating system will kick into action. Right. You will drive into the kernel and the offices and will copy data from the distant memory. 303 00:40:00.870 --> 00:40:06.990 William Cheng: Change the memory map so that this will pull me into memory and then it will return back to the user space for about almost like a system called 304 00:40:07.590 --> 00:40:22.530 William Cheng: OK, so now your user space program can actually, you can use the data in memory. Okay, so, so the memory map data structure is very complicated. We're going to talk about in chapter seven. Okay, together with the pace table in the memory map they implement the so the virtual memory system. 305 00:40:23.580 --> 00:40:29.970 William Cheng: Okay, so, so getting them every member of yours pojar were operating system. You know, every program with thing that it has their own I go space. Okay. 306 00:40:30.180 --> 00:40:36.870 William Cheng: Pretty complicated, right now we're just introducing you the idea over here. So what we're gonna do is, I'm going to actually set up a memory map over here. 307 00:40:37.110 --> 00:40:41.640 William Cheng: So that you know when you start running your program. You don't have to copy all the data from the distant memory. 308 00:40:42.330 --> 00:40:47.640 William Cheng: There. So we're going to sort of draw a picture like this that. So we're going to use this technique known as mapping 309 00:40:48.240 --> 00:40:51.690 William Cheng: So, so what we can do is that we can map the fall into our address space. 310 00:40:52.500 --> 00:40:54.300 William Cheng: Because what does that mean, right. So basically what we 311 00:40:54.630 --> 00:41:03.390 William Cheng: What we need to do is that we need to make some notes inside the curtain and say, you know, this particular page over here now mapped to physical memory and this particular page over here about to this. 312 00:41:03.690 --> 00:41:14.100 William Cheng: Right, so this way you know when you when you pull that are running when he tried to access data on the desk, then this way, the offices and intervene and bring the data from a distant memory and then change the memory map so they can access physical memory. 313 00:41:15.090 --> 00:41:24.750 William Cheng: Okay so mapping is an important concept in the operating system over here mapping. Let the operating system pied a region of the address space to the file system so that accessing your 314 00:41:25.050 --> 00:41:27.960 William Cheng: accessing your address space. It's the same thing as accessing the file. 315 00:41:28.710 --> 00:41:36.480 William Cheng: Because in a way that's what we're doing when we describe an address space, right. What do we say that there is a tech segment accessing the tech stack that it's the same thing as accessing data on the desk. 316 00:41:37.080 --> 00:41:47.190 William Cheng: Okay, so, so do the way we do is we take the data on the desk copy them into memory and then we're going to use our page table two point to us or we can have access to it. OK. So again, all these tech is no as memory mapping 317 00:41:48.090 --> 00:41:58.980 William Cheng: Man, so the text region for all the processes running the program or set up, you know, using this, how're address translation table it using the memory map without technique over here and this type of mapping is no assured mapping 318 00:41:59.310 --> 00:42:07.170 William Cheng: Right, we have multiple processes that can actually share the same memory map. Okay, so we share the same every map. We also have the page table point to the same place. 319 00:42:07.920 --> 00:42:19.140 William Cheng: You guys okay the memory mattresses more complicated data structure the page table is a simple data structure that we saw already. Okay, so you can see that by using your memory map you can actually decide what to put inside 320 00:42:20.010 --> 00:42:26.940 William Cheng: You put inside the inside the page table. Okay, so again chapter several going to see on detail and now we're just sort of at the introductory stage. 321 00:42:27.540 --> 00:42:35.190 William Cheng: Right. So we're here, we're sort of draw this high level pictures to say the criticism over here. We're going to have a data structure noise memory map or virtual memory map. 322 00:42:35.430 --> 00:42:39.690 William Cheng: That will keep track of how to map the data from the desk into address face. 323 00:42:40.110 --> 00:42:44.310 William Cheng: Guys over here with showing the page tables. Again, the idea. And if you're there, the address space. 324 00:42:44.520 --> 00:42:50.160 William Cheng: And then, you know, you know, if we just translate virtual address to physical address, you're going to use the pace table. So again, all these things are tied together. 325 00:42:50.490 --> 00:42:57.420 William Cheng: Yeah. So in this example, what I would do is I will hide part of my address space over here to the desk. So, for example, page number one over here. 326 00:42:57.660 --> 00:43:07.920 William Cheng: I'm going to tie to the first page of this file on the desk. I'm going to tie page number to over here to the second page of this fall on the desk and when tie the third page over here to the third part of, you know, the 327 00:43:08.580 --> 00:43:15.510 William Cheng: To the third page on the power desk, and I'm going to keep track of all this inside the organism using this data structure know as memory map. 328 00:43:16.170 --> 00:43:27.930 William Cheng: Okay, without going too much detail just going to say that data structure exists in chapter seven, when I look at all the details. Yeah, so the colonel will use memory map to keep track of the mapping from virtual pages to fall pages. 329 00:43:28.410 --> 00:43:36.990 William Cheng: Okay, so we're going to divide our virtual address space into four kilobytes pages. We also need to think about our fall, we need to divide them into four kilobytes pages. So this way we can map. 330 00:43:37.170 --> 00:43:44.880 William Cheng: One page on the file to one page of the address space, right. So once we have done that accessing the address space is exactly the same as accessing the file. 331 00:43:45.420 --> 00:43:54.060 William Cheng: That are either the cloud also use this memory map. So again, it's complicated structure to keep track of the mapping between virtual pages and physical pages Razzle get 332 00:43:54.690 --> 00:43:59.880 William Cheng: The data structure that we use the over there is going to be the the page table the page table. I'll tell you how to translate 333 00:44:00.120 --> 00:44:06.570 William Cheng: A virtual page to a physical page, right. So on the left hand side over here, direct the inbox into the table is going to be the virtual paste number 334 00:44:06.780 --> 00:44:18.540 William Cheng: And you know the you know the the what's inside the physical address over here is going to contain a physical page number one. So by using this data structure this data storage is a mapping data structure let you map a virtual page to a physical page. 335 00:44:19.620 --> 00:44:24.420 William Cheng: Okay. So all these things together, you know, sort of help you to implement the virtual memory system. Yeah. 336 00:44:25.980 --> 00:44:28.770 William Cheng: Alright, so, so good. So, so, so, so 337 00:44:29.310 --> 00:44:34.560 William Cheng: So in that case, what would you would do is, is that you will use a memory mapping technique to map the fine to address space. 338 00:44:34.770 --> 00:44:47.130 William Cheng: And now when you need, you know, we try to access a particular page if the data is on the desk operating system is going to kick into action and bring the page into memory and then fix up the virtual memory map and now your program can can can can can use the memory. 339 00:44:47.610 --> 00:44:52.590 William Cheng: Yeah, but what about the data side man the BSS over here, right. So again, the example that I 340 00:44:53.250 --> 00:44:57.180 William Cheng: Mentioned before right over here. There's a variable called x x right now is equal to zero. 341 00:44:57.570 --> 00:45:05.670 William Cheng: when when when you for call which are process and they are sharing this variable be here if the parent says exit per executable line of code us as a sequel to five. 342 00:45:05.910 --> 00:45:10.350 William Cheng: If we change this one to five, the child will be surprised. As far as the child is concerned. 343 00:45:10.650 --> 00:45:19.470 William Cheng: At the time, will you forgive, get a copy of the address space, right, if it's a copy. Well then, when the parent modify the memory location inside the outer space. The child shouldn't see those 344 00:45:19.800 --> 00:45:26.340 William Cheng: She didn't see the changes, right, because that's what a copy is once you make a copy. If you change the original. Well, then the copy doesn't really change value. 345 00:45:26.730 --> 00:45:34.320 William Cheng: Okay. Similarly, the cellist says x equal to the love and war, the parents shouldn't see the changes because the chart is modifying the copy of its address face. 346 00:45:34.860 --> 00:45:37.860 William Cheng: Okay, so therefore, by sharing something over here that will be totally wrong. 347 00:45:38.580 --> 00:45:45.810 William Cheng: Okay, so what should be the solution, whereas over here, you know, we know that we can can save the share the tech segment, because we're using a share mapping 348 00:45:46.470 --> 00:45:52.560 William Cheng: Okay, so this one over here, it cannot be assured mapping. So the kind of mapping that we're going to use over here is no as a private mapping 349 00:45:53.370 --> 00:46:01.560 William Cheng: Okay, so what is the part of the mapping. Right. So that means that the parent of a child, they get a copy of the of the of this particular mapping. So this way, they get a private copy 350 00:46:02.220 --> 00:46:14.220 William Cheng: Right. Is there a shirt when it's not private guy, so therefore the skies over here is going to be another kind of mapping the tax region uses a share mapping for the data region over here. They're using the share mapping 351 00:46:15.090 --> 00:46:21.600 William Cheng: Yeah, right. So, so in this case. So how does that the original via the using a private mapping 352 00:46:22.140 --> 00:46:24.810 William Cheng: So, so in this case, what happened is that, when do you actually require 353 00:46:25.230 --> 00:46:32.850 William Cheng: A private copy of the data that. So if you go back to the previous slide over here if what the program wants to do over here is just to look at the value of x. 354 00:46:33.360 --> 00:46:41.700 William Cheng: Okay, so let's say that we're not changing the value of x, right, the parent process just want to see what the value is is you know for variable x. So, in that case does apparently the private happy to do that. 355 00:46:42.720 --> 00:46:48.480 William Cheng: Well, no, right, because this one is a shelf copy as long as you just want to read the data, you can actually share all you want. 356 00:46:49.050 --> 00:46:56.940 William Cheng: Okay, when the parents are to see what is the value of x, x equal to zero. The child was there, what's the value of actually also equal to zero. So if you just want the reader, you can share all you want. 357 00:46:57.420 --> 00:47:05.850 William Cheng: Okay, so you only have to get a private copy of this particular page or this particular variable when you try to, you know, change that variable. 358 00:47:06.060 --> 00:47:15.600 William Cheng: Right when the parent says x equal to 11 over here. What, what should you do. Right. So at this point, what you should do that. You should get a private copy of this particular page for the parent process. 359 00:47:15.900 --> 00:47:25.980 William Cheng: Okay, when the child processes going to set x equal to equal the lover at the time when child needs to modify their memory location. The child will have to get a copy of this page, and then the child will be 360 00:47:26.340 --> 00:47:33.300 William Cheng: Will will need to modify the copy was those. How would you do that. And so again, the audience's them and call up the buddy system allocate a new page. 361 00:47:33.540 --> 00:47:47.280 William Cheng: To a meme copy from this page to this page over here and then change the point at the point of this new page. And now we return back to the trial process and the chopper says over here will modify its own private page, while the parents still use the the previous page. 362 00:47:48.030 --> 00:47:54.060 William Cheng: Okay. Similarly, when the parent says x equals to five over here. And again, since we're using private nappy 363 00:47:54.270 --> 00:47:58.470 William Cheng: What we're gonna do is, I'm going to type into the ordinances and we're going to get a brand new page over here we're going to cut 364 00:47:58.770 --> 00:48:04.980 William Cheng: As the buddy system for new page. We're going to copy it when we copy it. When we finish copying. Now, x equal to zero, right. 365 00:48:05.700 --> 00:48:12.390 William Cheng: Okay, and then we modify this point over your department, this one and then we go back to the application program to say hey you know now the mapping has been fixed. 366 00:48:12.630 --> 00:48:19.890 William Cheng: Why don't you try it again. So now the application is going to try x equal to five again and now it's pointing to a private page so therefore it will change it to a five. 367 00:48:20.700 --> 00:48:28.830 William Cheng: Okay, so this way, the parent and child. Both of them are happy. The child will see x equal to 11 four point on and the parent will see x equal to 5.1 point of this point. 368 00:48:29.880 --> 00:48:34.950 William Cheng: Okay, so, so, so, so this particular way of doing things. This is no as copy on right 369 00:48:35.670 --> 00:48:46.800 William Cheng: Guys. So again, I'm going to read the definition of copyright right here, a process gets a private copy of the page after a threat in the process. Perform copy performer right to that page for the first time. 370 00:48:47.760 --> 00:48:58.200 William Cheng: Okay, so, so every page over here is four kilobytes long right so when you try to modify one location, instead of four kilobytes a page for the first time. What you would do is that you will make a copy and you right into the copy 371 00:49:00.000 --> 00:49:03.660 William Cheng: Okay, so, and also you only do this only do this for 372 00:49:04.950 --> 00:49:11.220 William Cheng: For, for the first time, because now you have a private copy from this point on, if you want to modify other data on your private copy 373 00:49:11.820 --> 00:49:17.520 William Cheng: You know, in that case, do you have to worry about the other process. Well, no, because you have a private copies of this point out, you can modify all you want. 374 00:49:18.270 --> 00:49:24.060 William Cheng: Okay, so only were the first time you modify that page you're going to do something special. From that point on, you can write that page, all you want. 375 00:49:24.600 --> 00:49:34.200 William Cheng: Guys that again this can be done very, very efficiently. They only when you write to it for the first time, then, then you have to, you have to you know make sure this is done correctly. Yeah. 376 00:49:36.180 --> 00:49:40.410 William Cheng: So, so what is the part of the mapping for copy on write for the data and the BSS like man. 377 00:49:40.890 --> 00:49:50.640 William Cheng: What do you do, you also have a huge segment. What if you also have a stack segment what they, you know, they also cover using the same principle. Right. Well, the parent process for coffee shop is as the child processes going to get 378 00:49:51.600 --> 00:49:58.530 William Cheng: The get the trial process get to share the heat sideman and get to show that the stock segment on a walk. 379 00:49:58.980 --> 00:50:06.870 William Cheng: Okay, until you know it's also just want to read it. That's perfectly fine. Okay. But as soon as they try to write to the the heat segment or the data segment so 380 00:50:07.140 --> 00:50:12.960 William Cheng: The stacks up before the first time in that case you will go to that page. Make a copy of that page and you write to your own copy 381 00:50:14.370 --> 00:50:20.940 William Cheng: Okay, so this is what color the province. I'm happy means. So whenever we talk about private IP. We're talking about copying right 382 00:50:21.360 --> 00:50:28.140 William Cheng: Okay, and then you can copy. All right. The only needs to have that. Will you write to that particular page for the first time from, from that point on. Once you get 383 00:50:28.620 --> 00:50:36.960 William Cheng: Once you get once you have already made a copy that all your future, right. We'll go into the copy and then you don't have to copy all right anymore that alright 384 00:50:38.040 --> 00:50:44.580 William Cheng: So over here, there's a little note to say for Linux that you know the dynamic range or the Hebrew. Yeah. And the stock region over here. 385 00:50:45.090 --> 00:50:53.430 William Cheng: All those pages are actually initialize they are filled with zeros. They are set up to be copy on write and these pages are known as anonymous pages. 386 00:50:53.820 --> 00:51:02.250 William Cheng: Why are they called anonymous pages, right, because they don't have a name. What about the other memory segment. Now the tech segment that sucks. It actually has a name. What kind of name is that 387 00:51:02.790 --> 00:51:15.150 William Cheng: The tech segments name is, you know, when you move them from the, you know, from a file into memory. Well, you know, the following location. So therefore, the file system path that points to the executable file that's the name for those pages. 388 00:51:16.560 --> 00:51:21.870 William Cheng: Okay, because you're mapping of funding to address space. So you can you can actually use the phone name as the name of the memory segment. 389 00:51:22.470 --> 00:51:28.560 William Cheng: Okay, so in that case, they, they will have nice. Well, you know, as we mentioned before, the executable file only has tech segment data segment BSS 390 00:51:28.860 --> 00:51:38.100 William Cheng: For the heathen for the stock. They don't come from the executable file. So therefore, for the heap and the stack or they come from no name right so that's why they are no as anonymous pages, right. 391 00:51:38.910 --> 00:51:47.220 William Cheng: Right, so if we can implement copy on write at the right time. Okay, then it's perfectly okay for the processes to share the address space initially 392 00:51:48.330 --> 00:51:58.650 William Cheng: Okay, so, so we're not going to. So we're going to talk about the detail in chapter seven for right now, we just see that, oh, you know, we're going to map the the tech segment and the data segment and VSS differently. The tech segment we're going to use share mapping 393 00:51:59.280 --> 00:52:02.520 William Cheng: Okay, so therefore you never have to do copy on write because you're just, you're just reading 394 00:52:03.240 --> 00:52:13.920 William Cheng: Okay, before the data segment and the BSS what to do copy or I will use private mapping, so that if you just want to refund these memory segment. You can read all your wine can read the share data. But as soon as you write to a page. 395 00:52:14.220 --> 00:52:22.140 William Cheng: You know, in that memory segment for the first time we're going to make a copy of that page. And now you have a private page and all your modification will go into the private page. 396 00:52:22.530 --> 00:52:29.250 William Cheng: Okay, and that mechanism is known as copy on write and we're going to use private a private mapping to signify that you have to do copy. All right. 397 00:52:32.730 --> 00:52:45.510 William Cheng: All right. Um, okay. I guess this is kind of a good point to break. So, you know, so we're done with the second part of the video and then we're going to sort of finish the first part of chapter four and the third part of 398 00:52:45.900 --> 00:52:50.490 William Cheng: You know lecture night. Then after that, for lecture town. We're going to go into chapter five. Yeah.