WEBVTT

1
00:00:00.080 --> 00:00:02.879
<v Speaker 1>Welcome back to the deep dive. You know, I was

2
00:00:02.919 --> 00:00:05.599
<v Speaker 1>looking at the stack of notes for today we are

3
00:00:05.639 --> 00:00:12.960
<v Speaker 1>tackling William Stallings's massive text Operating Systems, internals and design principles,

4
00:00:13.640 --> 00:00:16.440
<v Speaker 1>and it really hit me. We spend all this money

5
00:00:16.519 --> 00:00:20.879
<v Speaker 1>on faster processors, better ram but the thing that actually

6
00:00:20.879 --> 00:00:24.079
<v Speaker 1>decides if we have a good experience is this invisible

7
00:00:24.160 --> 00:00:25.960
<v Speaker 1>layer we almost never talk about.

8
00:00:26.120 --> 00:00:28.679
<v Speaker 2>It's the ghost in the machine, literally.

9
00:00:28.600 --> 00:00:30.800
<v Speaker 1>And Stallings makes this comparison right out of the gate

10
00:00:30.800 --> 00:00:33.479
<v Speaker 1>that to stop me. He doesn't compare the operating system

11
00:00:33.520 --> 00:00:36.600
<v Speaker 1>to a brain or you know, an engine. He compares

12
00:00:36.640 --> 00:00:37.000
<v Speaker 1>it to a.

13
00:00:36.920 --> 00:00:40.079
<v Speaker 2>Government, which, depending on your political views, might make you

14
00:00:40.119 --> 00:00:41.840
<v Speaker 2>a little nervous about turning on your laptop.

15
00:00:41.960 --> 00:00:44.159
<v Speaker 1>It definitely gives you pause. But when you dig into

16
00:00:44.159 --> 00:00:48.200
<v Speaker 1>the book the analogy it fits surprisingly well. The OS

17
00:00:48.359 --> 00:00:50.240
<v Speaker 1>doesn't actually produce anything, does it.

18
00:00:50.320 --> 00:00:52.399
<v Speaker 2>No, it doesn't write your email or edit your photo.

19
00:00:52.479 --> 00:00:55.600
<v Speaker 2>It just it creates the environment where those things can happen.

20
00:00:56.119 --> 00:01:00.439
<v Speaker 2>That's the core function. It paves the roads, polices the intersectctions,

21
00:01:00.679 --> 00:01:03.000
<v Speaker 2>and it collects taxes in the form of memory and

22
00:01:03.079 --> 00:01:03.920
<v Speaker 2>processing power.

23
00:01:04.079 --> 00:01:08.640
<v Speaker 1>And like a government, it's constantly fighting this sort of

24
00:01:08.680 --> 00:01:15.120
<v Speaker 1>three way war with itself. Stallings lays these out really clearly. Convenience, efficiency,

25
00:01:15.239 --> 00:01:17.400
<v Speaker 1>and the ability to evolve, and.

26
00:01:17.359 --> 00:01:20.120
<v Speaker 2>Those three things do not naturally go together.

27
00:01:20.079 --> 00:01:22.159
<v Speaker 1>Not at all. In fact, they seem like they would

28
00:01:22.200 --> 00:01:23.560
<v Speaker 1>actively sabotage each other.

29
00:01:23.599 --> 00:01:27.439
<v Speaker 2>They absolutely do. I mean, think about convenience. That's you,

30
00:01:27.560 --> 00:01:31.359
<v Speaker 2>the user. You want a beautiful desktop, you want transparent windows,

31
00:01:31.359 --> 00:01:33.760
<v Speaker 2>plug and plate devices. You do not want to see

32
00:01:33.760 --> 00:01:34.239
<v Speaker 2>the wiring.

33
00:01:34.319 --> 00:01:35.920
<v Speaker 1>I definitely do not want to see the wiring. I

34
00:01:35.959 --> 00:01:37.719
<v Speaker 1>just want to click the button and have it work.

35
00:01:37.959 --> 00:01:41.040
<v Speaker 2>But hiding the wiring is expensive. Yeah, that eats up

36
00:01:41.079 --> 00:01:46.239
<v Speaker 2>system resources, which fights against objective number two efficiency. The

37
00:01:46.280 --> 00:01:49.239
<v Speaker 2>hardware just wants to run raw code as fast as possible,

38
00:01:49.599 --> 00:01:53.400
<v Speaker 2>not paint pretty pictures for you. Every cycle spent drawing

39
00:01:53.400 --> 00:01:55.920
<v Speaker 2>a drop shadow on a window is a cycle not

40
00:01:56.040 --> 00:01:57.920
<v Speaker 2>spent calculating a spreadsheet.

41
00:01:58.159 --> 00:02:00.760
<v Speaker 1>So the OS is basically stuck in the middle trying

42
00:02:00.760 --> 00:02:04.079
<v Speaker 1>to make me happy without making the CPU quit in frustration, while.

43
00:02:03.879 --> 00:02:08.879
<v Speaker 2>Also handling objective three evolution. It has to be built

44
00:02:08.919 --> 00:02:11.120
<v Speaker 2>in a way that allows it to change completely next

45
00:02:11.199 --> 00:02:14.439
<v Speaker 2>year without breaking all the software you bought five years ago.

46
00:02:14.879 --> 00:02:15.759
<v Speaker 2>It's a juggling act.

47
00:02:15.840 --> 00:02:18.240
<v Speaker 1>An unbelievable juggling.

48
00:02:17.800 --> 00:02:19.520
<v Speaker 2>App billions of times a second.

49
00:02:19.719 --> 00:02:22.280
<v Speaker 1>So let's get into the mechanics of this. Stallings breaks

50
00:02:22.319 --> 00:02:27.039
<v Speaker 1>it down to the instruction cycle. Fetch, execute, fetch execute.

51
00:02:27.080 --> 00:02:27.960
<v Speaker 1>It sounds so simple.

52
00:02:28.080 --> 00:02:30.400
<v Speaker 2>It is. It's the heartbeat of the machine. But there's

53
00:02:30.479 --> 00:02:35.919
<v Speaker 2>a massive physiological problem with this computer body. Okay, the brain,

54
00:02:36.080 --> 00:02:38.400
<v Speaker 2>the CPU is moving at the speed of light, but

55
00:02:38.479 --> 00:02:41.719
<v Speaker 2>the hands and feet, the input output devices like your

56
00:02:41.759 --> 00:02:44.960
<v Speaker 2>hard drive or your Wi Fi card are moving through molasses.

57
00:02:45.039 --> 00:02:47.319
<v Speaker 1>Stalling's had a stat on this that just blew my mind.

58
00:02:47.439 --> 00:02:51.000
<v Speaker 1>The speed difference isn't a little bit, it's orders of magnitude.

59
00:02:50.439 --> 00:02:53.439
<v Speaker 2>It's astronomical. If the CPU's a Ferrari driving it at

60
00:02:53.439 --> 00:02:56.240
<v Speaker 2>two hundred miles an hour, the hard drive is a tractor. No,

61
00:02:56.240 --> 00:02:57.599
<v Speaker 2>that gives a hard drive too much credit.

62
00:02:57.680 --> 00:02:58.240
<v Speaker 1>It's a snail.

63
00:02:58.319 --> 00:02:59.520
<v Speaker 2>It's a snail exactly.

64
00:02:59.560 --> 00:03:02.719
<v Speaker 1>So you didn't have a smart operating system and you

65
00:03:02.840 --> 00:03:06.759
<v Speaker 1>told the computer to save file that Ferrari effectively has

66
00:03:06.800 --> 00:03:09.120
<v Speaker 1>to slam on the brakes and just idle for what

67
00:03:09.199 --> 00:03:12.199
<v Speaker 1>feels like one hundred years while the snail writes the data.

68
00:03:12.719 --> 00:03:15.719
<v Speaker 2>That's the polling method. CPU just sits there, asking the

69
00:03:15.800 --> 00:03:18.199
<v Speaker 2>drive Are you done yet? Are you done yet? Are

70
00:03:18.199 --> 00:03:18.680
<v Speaker 2>you done yet?

71
00:03:18.719 --> 00:03:19.439
<v Speaker 1>What a waste.

72
00:03:19.560 --> 00:03:22.800
<v Speaker 2>It's a massive waste, a billion dollar hardware. You have

73
00:03:22.840 --> 00:03:25.599
<v Speaker 2>the world's smartest mathematician sitting there waiting for a printer

74
00:03:25.680 --> 00:03:26.159
<v Speaker 2>to warm up.

75
00:03:26.560 --> 00:03:30.280
<v Speaker 1>So they invented interrupts. And I love this term because

76
00:03:30.319 --> 00:03:33.479
<v Speaker 1>it sounds rude, but it's actually the most polite thing

77
00:03:33.560 --> 00:03:34.520
<v Speaker 1>the hardware can do.

78
00:03:34.800 --> 00:03:38.879
<v Speaker 2>It's save computing with interrupts. The Ferrari sends the save

79
00:03:38.960 --> 00:03:41.879
<v Speaker 2>command to the snail and then immediately peels out and

80
00:03:41.879 --> 00:03:42.639
<v Speaker 2>goes to do something else.

81
00:03:42.680 --> 00:03:45.960
<v Speaker 1>Okay, so it goes off and runs a spreadsheet, plays music, whatever.

82
00:03:46.120 --> 00:03:48.280
<v Speaker 1>But wait, how does it know when the snail is done?

83
00:03:48.280 --> 00:03:51.280
<v Speaker 2>The snail has a direct line to the CPU. When

84
00:03:51.319 --> 00:03:54.919
<v Speaker 2>it's finished, it sends an electrical signal and interrupt. It

85
00:03:55.000 --> 00:03:58.919
<v Speaker 2>forces the CPU to pause whatever it's doing to acknowledge

86
00:03:59.080 --> 00:04:00.439
<v Speaker 2>that the task is complete.

87
00:04:00.680 --> 00:04:02.919
<v Speaker 1>See that's the part that stresses me out. If I'm

88
00:04:02.919 --> 00:04:04.800
<v Speaker 1>in the middle of a complex math problem and you

89
00:04:04.840 --> 00:04:08.159
<v Speaker 1>interrupt me, I lose my place. I have to start over.

90
00:04:08.280 --> 00:04:11.240
<v Speaker 2>And that is the magic trick. Yeah, the OS performs

91
00:04:11.319 --> 00:04:14.560
<v Speaker 2>a context switch. Okay, imagine you're reading a really dense

92
00:04:14.599 --> 00:04:17.319
<v Speaker 2>novel and the doorbell rings, You don't just throw the

93
00:04:17.319 --> 00:04:19.680
<v Speaker 2>book on the floor, right, you put a bookmark in.

94
00:04:19.959 --> 00:04:22.319
<v Speaker 2>You write down exactly which line you were on, maybe

95
00:04:22.399 --> 00:04:24.319
<v Speaker 2>even the thought you were having in that split second.

96
00:04:24.560 --> 00:04:26.319
<v Speaker 1>So that's the state of the process.

97
00:04:26.319 --> 00:04:29.839
<v Speaker 2>Correct, the program counter, the register values. Everything gets pushed

98
00:04:29.879 --> 00:04:33.759
<v Speaker 2>onto a control stack. It's a snapshot of reality frozen

99
00:04:33.800 --> 00:04:37.000
<v Speaker 2>in time. Wow, you go answer the door, handle the

100
00:04:37.040 --> 00:04:40.160
<v Speaker 2>big job, and when you come back, you pop that

101
00:04:40.199 --> 00:04:43.120
<v Speaker 2>snapshot back off the stack. The software doesn't even know

102
00:04:43.160 --> 00:04:44.319
<v Speaker 2>it was passed, so.

103
00:04:44.360 --> 00:04:46.759
<v Speaker 1>To me, it looks like everything happened at once exactly.

104
00:04:46.920 --> 00:04:50.680
<v Speaker 2>It completely decouples the user's perception of time from the

105
00:04:50.720 --> 00:04:51.720
<v Speaker 2>computer's reality.

106
00:04:51.800 --> 00:04:53.800
<v Speaker 1>But what happens if the doorbell rings while I'm already

107
00:04:53.800 --> 00:04:54.319
<v Speaker 1>on the phone?

108
00:04:54.600 --> 00:04:57.839
<v Speaker 2>Ah, the nightmare scenario multiple.

109
00:04:57.560 --> 00:04:59.600
<v Speaker 1>Interrupts, is the system just crash?

110
00:05:00.000 --> 00:05:03.560
<v Speaker 2>Depends on how it's designed. You can disable interrupts basically

111
00:05:03.720 --> 00:05:05.680
<v Speaker 2>take the phone off the hook while you answer the door,

112
00:05:06.240 --> 00:05:08.639
<v Speaker 2>or you can have nested interrupts.

113
00:05:08.160 --> 00:05:11.160
<v Speaker 1>Which implies a hierarchy. Some things are more important.

114
00:05:10.759 --> 00:05:14.920
<v Speaker 2>Precisely, if your network card says incoming data that's urgent.

115
00:05:15.519 --> 00:05:18.240
<v Speaker 2>If your printer says I'm out of paper, that can

116
00:05:18.319 --> 00:05:22.040
<v Speaker 2>wait The OS prioritizes the urgent interrupt handles it then

117
00:05:22.120 --> 00:05:24.240
<v Speaker 2>goes back to the less urgent one, and finally back

118
00:05:24.279 --> 00:05:25.120
<v Speaker 2>to your program.

119
00:05:25.160 --> 00:05:26.920
<v Speaker 1>And all of this happens so fast that I just

120
00:05:26.959 --> 00:05:28.279
<v Speaker 1>see a smooth mouse cursor.

121
00:05:28.480 --> 00:05:30.720
<v Speaker 2>Well underneath, it's just controlled chaos.

122
00:05:30.879 --> 00:05:34.040
<v Speaker 1>So we have the CPU maximizing its time with interrupts.

123
00:05:34.360 --> 00:05:39.480
<v Speaker 1>But there's another bottleneck, right memory. We all want terabytes

124
00:05:39.519 --> 00:05:43.279
<v Speaker 1>of storage that's instantly accessible. But Stallings points out the

125
00:05:43.399 --> 00:05:47.040
<v Speaker 1>iron triangle of memory capacity, speed, and cost.

126
00:05:46.839 --> 00:05:49.319
<v Speaker 2>And you can pick two because you cannot have all three.

127
00:05:49.839 --> 00:05:53.600
<v Speaker 2>Fast memory like the registers right inside the CPU, is

128
00:05:53.639 --> 00:05:57.079
<v Speaker 2>incredibly expensive and tiny. Big memory like your hard drive

129
00:05:57.360 --> 00:05:58.560
<v Speaker 2>is cheap but slow.

130
00:05:58.759 --> 00:06:01.120
<v Speaker 1>So the OS has to lie to us again. It

131
00:06:01.160 --> 00:06:03.759
<v Speaker 1>has to create the illusion that we have unlimited, super

132
00:06:03.759 --> 00:06:04.839
<v Speaker 1>fast memory.

133
00:06:04.759 --> 00:06:07.959
<v Speaker 2>And it does that through the memory hierarchy. It's a pyramid.

134
00:06:08.600 --> 00:06:12.240
<v Speaker 2>Data is constantly moving up and down. But the secret sauce,

135
00:06:12.879 --> 00:06:15.839
<v Speaker 2>the thing that makes the lie convincing is this concept

136
00:06:15.839 --> 00:06:17.160
<v Speaker 2>of locality of reference.

137
00:06:17.759 --> 00:06:20.120
<v Speaker 1>This is essentially the OS gambling right. It's betting on

138
00:06:20.160 --> 00:06:21.079
<v Speaker 1>what I'm going to do next.

139
00:06:21.120 --> 00:06:24.920
<v Speaker 2>It's a rigorous statistical gamble. They are two types. First,

140
00:06:25.319 --> 00:06:29.120
<v Speaker 2>temporal locality Okay, if you looked at a photo five

141
00:06:29.160 --> 00:06:32.040
<v Speaker 2>seconds ago, the odds are really high you'll look at

142
00:06:32.040 --> 00:06:33.920
<v Speaker 2>it again in the next five seconds. Think about a

143
00:06:33.920 --> 00:06:35.040
<v Speaker 2>loop and a piece of code.

144
00:06:35.120 --> 00:06:37.720
<v Speaker 1>It's the same instructions over and over, so you keep

145
00:06:37.759 --> 00:06:39.040
<v Speaker 1>that data close exactly.

146
00:06:39.160 --> 00:06:41.759
<v Speaker 2>And then there's spatial locality. If you're reading a document

147
00:06:41.759 --> 00:06:44.639
<v Speaker 2>at line ten, there is a ninety nine percent chance

148
00:06:44.680 --> 00:06:46.199
<v Speaker 2>you're going to need line eleven next.

149
00:06:46.480 --> 00:06:50.160
<v Speaker 1>You almost never jump from line ten to line five thousand.

150
00:06:49.959 --> 00:06:53.160
<v Speaker 2>Right, So the OSCs you're reading line ten and quietly

151
00:06:53.519 --> 00:06:56.399
<v Speaker 2>in the background, it runs down to the slow warehouse,

152
00:06:56.839 --> 00:06:59.600
<v Speaker 2>grabs lines eleven through twenty and puts them on the

153
00:06:59.600 --> 00:07:02.800
<v Speaker 2>fast on the top, right next to the CPU that's cashing.

154
00:07:03.040 --> 00:07:06.040
<v Speaker 2>That's cashing, and it works surprisingly well. A well toned

155
00:07:06.079 --> 00:07:08.360
<v Speaker 2>o S can get a hit on that cash maybe

156
00:07:08.439 --> 00:07:09.240
<v Speaker 2>ninety percent of the.

157
00:07:09.240 --> 00:07:12.199
<v Speaker 1>Time, which explains why when I open a huge app

158
00:07:12.240 --> 00:07:15.160
<v Speaker 1>for the very first time, it sometimes chugs for a second.

159
00:07:15.160 --> 00:07:18.319
<v Speaker 2>That's a miss, right. The chef reached for the salt,

160
00:07:18.600 --> 00:07:20.319
<v Speaker 2>but it wasn't on the counter. He had to run

161
00:07:20.319 --> 00:07:23.040
<v Speaker 2>to the pantry. But once he brings it out, it

162
00:07:23.120 --> 00:07:24.959
<v Speaker 2>stays on the counter. It stays on the counter. The

163
00:07:25.000 --> 00:07:26.639
<v Speaker 2>next time you click. It's instant.

164
00:07:26.800 --> 00:07:29.000
<v Speaker 1>It's fascinating to think about this because it means my

165
00:07:29.040 --> 00:07:32.439
<v Speaker 1>computer is constantly trying to predict the future based on

166
00:07:32.480 --> 00:07:33.560
<v Speaker 1>the immediate past.

167
00:07:33.720 --> 00:07:35.839
<v Speaker 2>And when a guess is right, you feel like you

168
00:07:35.839 --> 00:07:38.800
<v Speaker 2>have a supercomputer. When a guess is wrong, you get

169
00:07:38.800 --> 00:07:40.120
<v Speaker 2>the spinning wheel of death.

170
00:07:40.279 --> 00:07:42.399
<v Speaker 1>It's so easy to take this for granted. Now we

171
00:07:42.480 --> 00:07:47.399
<v Speaker 1>have casing, we have interrupts. Everything feels instant. But Stallings

172
00:07:47.439 --> 00:07:49.800
<v Speaker 1>takes us back to the nineteen forties and fifties to

173
00:07:49.920 --> 00:07:51.639
<v Speaker 1>show us the dark Ages.

174
00:07:51.839 --> 00:07:55.439
<v Speaker 2>It really was the dark Ages. No operating system, no mouse,

175
00:07:55.879 --> 00:07:59.519
<v Speaker 2>no screen. It's a clipboard, a literal clipboard outside the

176
00:07:59.519 --> 00:08:02.240
<v Speaker 2>computer room. You signed up for a thirty minute block.

177
00:08:02.480 --> 00:08:04.360
<v Speaker 2>You walked in with your deck of punch cards. You

178
00:08:04.519 --> 00:08:07.160
<v Speaker 2>loaded them into the machine, and you prayed.

179
00:08:06.920 --> 00:08:08.680
<v Speaker 1>And if you had a typo, a light.

180
00:08:08.600 --> 00:08:11.839
<v Speaker 2>Flashed, the machine stopped, and your thirty minutes were up.

181
00:08:12.600 --> 00:08:14.279
<v Speaker 2>You had to go back to your desk and debug

182
00:08:14.600 --> 00:08:16.839
<v Speaker 2>by just staring at holes in paper.

183
00:08:17.000 --> 00:08:20.360
<v Speaker 1>The inefficiency is painful to even think about. While you

184
00:08:20.360 --> 00:08:24.079
<v Speaker 1>were walking around loading cards, checking the lights, this million

185
00:08:24.120 --> 00:08:25.839
<v Speaker 1>dollar machine was just sitting.

186
00:08:25.480 --> 00:08:30.000
<v Speaker 2>There burning electricity, doing nothing. That idle time is what

187
00:08:30.079 --> 00:08:33.360
<v Speaker 2>drove the invention of the OS. It wasn't about user comfort,

188
00:08:33.440 --> 00:08:36.639
<v Speaker 2>it was about money. They needed batch processing to keep

189
00:08:36.679 --> 00:08:37.519
<v Speaker 2>the machine.

190
00:08:37.200 --> 00:08:40.039
<v Speaker 1>Fed, and this is where we see the first monitor programs.

191
00:08:40.240 --> 00:08:42.679
<v Speaker 2>Yes, you'd hand your cards to an operator. The operator

192
00:08:42.720 --> 00:08:45.399
<v Speaker 2>fed them to the machine one after another. The monitor

193
00:08:45.440 --> 00:08:47.679
<v Speaker 2>was a simple program that just said Okay, job one

194
00:08:47.759 --> 00:08:48.960
<v Speaker 2>is done, load job two.

195
00:08:49.279 --> 00:08:51.240
<v Speaker 1>But even then, if a job had to wait for

196
00:08:51.279 --> 00:08:53.799
<v Speaker 1>a tape to rewind, the CPU starped again.

197
00:08:54.000 --> 00:08:58.000
<v Speaker 2>Which led to the biggest leap inefficiency multi programming, the

198
00:08:58.120 --> 00:09:01.440
<v Speaker 2>idea that you could hold multiple job and memory at once.

199
00:09:01.440 --> 00:09:03.120
<v Speaker 1>So if job A waits for a.

200
00:09:03.080 --> 00:09:04.879
<v Speaker 2>Tape, the OS switches to Joe B.

201
00:09:05.559 --> 00:09:09.080
<v Speaker 1>Stallings mentions that uniprogramming had something like what three percent

202
00:09:09.159 --> 00:09:12.600
<v Speaker 1>CPU utilization? Multiprogramming just blew that away.

203
00:09:12.799 --> 00:09:16.240
<v Speaker 2>It changed the economics of computing, but it was still impersonal.

204
00:09:16.559 --> 00:09:19.000
<v Speaker 2>You submitted a job and came back hours later for

205
00:09:19.039 --> 00:09:19.720
<v Speaker 2>the print.

206
00:09:19.440 --> 00:09:22.320
<v Speaker 1>Out, which brings us to the moment the computer became

207
00:09:22.360 --> 00:09:24.039
<v Speaker 1>personal time sharing.

208
00:09:24.320 --> 00:09:28.000
<v Speaker 2>This is the MIT system CTSS. Before this, the goal

209
00:09:28.080 --> 00:09:31.960
<v Speaker 2>was always maximized the CPU. With time sharing, the goal

210
00:09:32.000 --> 00:09:34.240
<v Speaker 2>shifted to maximize the user.

211
00:09:34.360 --> 00:09:36.080
<v Speaker 1>And this is where we get the concept of time

212
00:09:36.120 --> 00:09:36.919
<v Speaker 1>slicing right.

213
00:09:37.159 --> 00:09:40.200
<v Speaker 2>Yes. Imagine a chess master playing fifty games at once.

214
00:09:40.519 --> 00:09:43.559
<v Speaker 2>He walks to board one, makes a move, walks to

215
00:09:43.600 --> 00:09:44.919
<v Speaker 2>board two, makes a.

216
00:09:44.919 --> 00:09:46.879
<v Speaker 1>Move, and if he moves fast enough.

217
00:09:46.879 --> 00:09:49.159
<v Speaker 2>Every player feels like they have his full attention.

218
00:09:49.559 --> 00:09:51.919
<v Speaker 1>So the OS is the chess master. It runs my

219
00:09:51.960 --> 00:09:54.200
<v Speaker 1>browser for a fraction of a second, then switches to

220
00:09:54.240 --> 00:09:56.879
<v Speaker 1>your music player, then the system clock and back to

221
00:09:56.879 --> 00:09:57.799
<v Speaker 1>my browser.

222
00:09:57.600 --> 00:10:00.679
<v Speaker 2>Every point two seconds in those early systems. Now it's

223
00:10:00.840 --> 00:10:03.519
<v Speaker 2>much much faster. It creates the illusion of concurrency.

224
00:10:03.639 --> 00:10:06.559
<v Speaker 1>You think you're multitasking, but the computer is actually just

225
00:10:06.600 --> 00:10:07.759
<v Speaker 1>panic switching.

226
00:10:07.559 --> 00:10:10.440
<v Speaker 2>Panic switching between tasks fast enough to fool your eyes.

227
00:10:10.840 --> 00:10:14.600
<v Speaker 1>This required a huge leap in software architecture, though Stallings

228
00:10:14.679 --> 00:10:17.320
<v Speaker 1>really emphasizes the concept of the process.

229
00:10:17.679 --> 00:10:21.120
<v Speaker 2>It sounds abstract, but it's so vital. A program is

230
00:10:21.200 --> 00:10:24.480
<v Speaker 2>just a static set of instructions on a disc. It's dead.

231
00:10:25.320 --> 00:10:28.559
<v Speaker 2>A process is that program in execution. It's alive.

232
00:10:28.759 --> 00:10:30.080
<v Speaker 1>It has baggage, it has.

233
00:10:29.960 --> 00:10:33.600
<v Speaker 2>Context, it has ownership of memory, it has security clearance,

234
00:10:33.799 --> 00:10:37.799
<v Speaker 2>it has a priority level. By treating running programs as processes,

235
00:10:38.240 --> 00:10:40.200
<v Speaker 2>the OS could finally manage them safely.

236
00:10:40.320 --> 00:10:41.360
<v Speaker 1>It could isolate them.

237
00:10:41.279 --> 00:10:44.559
<v Speaker 2>Isolate them, so if one process crashes, it doesn't necessarily

238
00:10:44.639 --> 00:10:45.279
<v Speaker 2>kill the others.

239
00:10:45.519 --> 00:10:48.559
<v Speaker 1>And this ties into virtual memory too, because if you

240
00:10:48.639 --> 00:10:51.399
<v Speaker 1>have fifty processes running, they can't all fit in the

241
00:10:51.440 --> 00:10:52.360
<v Speaker 1>physical RAM.

242
00:10:52.480 --> 00:10:55.919
<v Speaker 2>Virtual memory is the ultimate illusion. The OS breaks a

243
00:10:55.960 --> 00:10:59.440
<v Speaker 2>process into these fixed sized blocks called pages. It can

244
00:10:59.480 --> 00:11:01.879
<v Speaker 2>scatter them those pages anywhere, some in RAM, some on

245
00:11:01.919 --> 00:11:02.440
<v Speaker 2>the desk.

246
00:11:02.279 --> 00:11:04.559
<v Speaker 1>With the program thinks it's all in one continuous piece.

247
00:11:04.639 --> 00:11:07.600
<v Speaker 2>The program sees a continuous, beautiful block of memory. It

248
00:11:07.720 --> 00:11:11.919
<v Speaker 2>uses virtual addresses. The hardware, specifically, the memory management unit

249
00:11:12.240 --> 00:11:15.399
<v Speaker 2>translates those virtual desks into physical addresses.

250
00:11:14.960 --> 00:11:17.360
<v Speaker 1>On the fly, so a developer can write a program

251
00:11:17.399 --> 00:11:20.279
<v Speaker 1>that uses four gigabytes of RAM even if the machine

252
00:11:20.279 --> 00:11:24.000
<v Speaker 1>only has two gigabytes free. It's basically gas lighting the software.

253
00:11:24.039 --> 00:11:26.759
<v Speaker 1>Oh yeah, you totally have all the space while frantically

254
00:11:26.799 --> 00:11:28.799
<v Speaker 1>shuffling data in and out of the back door.

255
00:11:29.039 --> 00:11:32.440
<v Speaker 2>Gas Lighting is a harsh word for it, but technically accurate.

256
00:11:32.480 --> 00:11:36.120
<v Speaker 2>It's abstraction. You abstract the harsh reality of the hardware

257
00:11:36.159 --> 00:11:39.039
<v Speaker 2>to create a better reality for the software.

258
00:11:39.240 --> 00:11:41.519
<v Speaker 1>Speaking of harsh reality, let's talk about the hardware we

259
00:11:41.600 --> 00:11:44.399
<v Speaker 1>use today. We aren't just using single processors anymore.

260
00:11:44.440 --> 00:11:49.440
<v Speaker 2>We have SMP and multi core Symmetric multiprocessing. SMP was

261
00:11:49.480 --> 00:11:52.519
<v Speaker 2>the first step. You plug two or four separate CPUs

262
00:11:52.519 --> 00:11:53.480
<v Speaker 2>into one motherboard.

263
00:11:53.559 --> 00:11:54.960
<v Speaker 1>They share everything, they.

264
00:11:54.879 --> 00:11:58.480
<v Speaker 2>Share memory IO. The US has to schedule tasks across

265
00:11:58.519 --> 00:11:59.200
<v Speaker 2>all of them.

266
00:11:59.039 --> 00:12:01.360
<v Speaker 1>Which is great for real life liability. If one burns out,

267
00:12:01.399 --> 00:12:02.320
<v Speaker 1>the other keeps going.

268
00:12:02.559 --> 00:12:05.480
<v Speaker 2>But multi core is where we are now putting multiple

269
00:12:05.519 --> 00:12:08.960
<v Speaker 2>brains on a single chip. It's faster, more efficient, but

270
00:12:09.039 --> 00:12:11.320
<v Speaker 2>it creates a huge headache for the OS designer called

271
00:12:11.639 --> 00:12:13.240
<v Speaker 2>cash coherence.

272
00:12:12.799 --> 00:12:15.519
<v Speaker 1>Because each core has its own little cash right, its

273
00:12:15.559 --> 00:12:18.200
<v Speaker 1>own little countertop of ingredients exactly.

274
00:12:18.240 --> 00:12:21.200
<v Speaker 2>So Core A changes the value, you say, updates your

275
00:12:21.200 --> 00:12:24.799
<v Speaker 2>bank balance in its private cache, but COREB tries to

276
00:12:24.840 --> 00:12:26.440
<v Speaker 2>read that balance from its own cash.

277
00:12:26.559 --> 00:12:30.519
<v Speaker 1>COREB has old information. You have a synchronization nightmare.

278
00:12:30.840 --> 00:12:33.200
<v Speaker 2>So the OS and the hardware have to constantly gossip

279
00:12:33.240 --> 00:12:36.720
<v Speaker 2>with each other. Hey, I changed this value, invalidate your copy.

280
00:12:36.879 --> 00:12:38.320
<v Speaker 2>It has a lot of complexity.

281
00:12:38.559 --> 00:12:42.559
<v Speaker 1>It's fascinating that all these tricks interrupts caching, time slicing.

282
00:12:42.720 --> 00:12:48.120
<v Speaker 1>They're universal, but how they're packaged differs. Stallings compares the

283
00:12:48.120 --> 00:12:52.120
<v Speaker 1>big three Windows, Linux, and Android, and they have very

284
00:12:52.159 --> 00:12:53.320
<v Speaker 1>different personalities.

285
00:12:53.399 --> 00:12:57.000
<v Speaker 2>They do take Windows. Windows is the ultimate corporate manager.

286
00:12:57.080 --> 00:12:59.600
<v Speaker 2>It's highly modular. It has this thing called the HL,

287
00:13:00.039 --> 00:13:01.440
<v Speaker 2>the Hardware abstraction.

288
00:13:01.120 --> 00:13:03.240
<v Speaker 1>Layer, which sounds like the villain from two thousand and

289
00:13:03.320 --> 00:13:04.840
<v Speaker 1>one A Space Odyssey.

290
00:13:04.960 --> 00:13:08.240
<v Speaker 2>Fortunately it's helpful. The HAL is a translator. It means

291
00:13:08.279 --> 00:13:09.840
<v Speaker 2>the core of Windows does need to know if you're

292
00:13:09.879 --> 00:13:12.000
<v Speaker 2>running an Intel chip or an AMD chip, or what

293
00:13:12.120 --> 00:13:14.799
<v Speaker 2>motherboard you have. AHL handles the specifics.

294
00:13:14.840 --> 00:13:16.159
<v Speaker 1>It isolates the kernel.

295
00:13:15.879 --> 00:13:18.120
<v Speaker 2>From the messiness of the real world. This is why

296
00:13:18.200 --> 00:13:20.159
<v Speaker 2>you can build a PC out of random parts and

297
00:13:20.480 --> 00:13:22.200
<v Speaker 2>Windows generally just boots up.

298
00:13:22.320 --> 00:13:25.639
<v Speaker 1>It prioritizes compatibility, compatibility, and portability.

299
00:13:26.039 --> 00:13:29.639
<v Speaker 2>It uses a client server model. Even internally, different parts

300
00:13:29.639 --> 00:13:32.279
<v Speaker 2>of Windows talk to each other by sending messages, almost

301
00:13:32.279 --> 00:13:33.240
<v Speaker 2>like they're on a network.

302
00:13:33.320 --> 00:13:37.279
<v Speaker 1>Now contrast that with Linux. Stallings calls it monolithic. That

303
00:13:37.440 --> 00:13:38.519
<v Speaker 1>sounds heavy.

304
00:13:38.720 --> 00:13:41.039
<v Speaker 2>It is, but in a good way. In Linux, the

305
00:13:41.120 --> 00:13:45.720
<v Speaker 2>kernel is one giant, highly optimized brain. All the drivers,

306
00:13:45.759 --> 00:13:48.960
<v Speaker 2>the file systems, the memory management, it's all living in

307
00:13:49.000 --> 00:13:50.039
<v Speaker 2>the same address space.

308
00:13:50.200 --> 00:13:53.840
<v Speaker 1>Isn't that dangerous If the audio driver crashes, doesn't it

309
00:13:53.840 --> 00:13:54.879
<v Speaker 1>take down the whole brain?

310
00:13:55.519 --> 00:13:59.440
<v Speaker 2>Historically, yes, that was the big criticism, but Linux got clever.

311
00:13:59.679 --> 00:14:01.639
<v Speaker 2>They added loadable.

312
00:14:01.240 --> 00:14:03.360
<v Speaker 1>Modules like Lego bricks sort of.

313
00:14:03.480 --> 00:14:05.200
<v Speaker 2>It means you can plug in a new device driver

314
00:14:05.360 --> 00:14:07.399
<v Speaker 2>or a file system while the kernel is running. You

315
00:14:07.440 --> 00:14:09.600
<v Speaker 2>don't have to shut down and rebuild the whole LOS

316
00:14:10.000 --> 00:14:11.600
<v Speaker 2>just to add support for a new webcam.

317
00:14:11.799 --> 00:14:14.840
<v Speaker 1>So you get the raw speed of a monolithic kernel with.

318
00:14:14.840 --> 00:14:17.519
<v Speaker 2>The flexibility of a modular one. It's the Borg approach,

319
00:14:17.720 --> 00:14:19.480
<v Speaker 2>adapt and assimilate without stopping.

320
00:14:19.639 --> 00:14:23.240
<v Speaker 1>And then Android is basically Linux putting on a hiking backpack.

321
00:14:23.360 --> 00:14:28.159
<v Speaker 2>It is Linux optimizing for survival power management on a server.

322
00:14:28.720 --> 00:14:31.480
<v Speaker 2>Linux assumes it has a wall socket. It runs tasks

323
00:14:31.519 --> 00:14:35.080
<v Speaker 2>whenever it wants. On a phone, Android has to be ruthless.

324
00:14:35.440 --> 00:14:39.000
<v Speaker 2>It uses wayclocks to prevent apps from keeping the CPU awake.

325
00:14:39.159 --> 00:14:41.480
<v Speaker 1>It kills background processes.

326
00:14:40.960 --> 00:14:46.320
<v Speaker 2>Aggressively because the dead battery makes the smartest OS completely useless.

327
00:14:46.440 --> 00:14:46.840
<v Speaker 1>True.

328
00:14:47.039 --> 00:14:50.840
<v Speaker 2>Android also uses a unique software stack for apps. It

329
00:14:50.879 --> 00:14:54.440
<v Speaker 2>doesn't run standard Linux programs. It runs apps inside a virtual.

330
00:14:54.200 --> 00:14:56.000
<v Speaker 1>Machine, which creates a sandbox.

331
00:14:56.080 --> 00:14:58.639
<v Speaker 2>Right, so if an angry bird crashes, it doesn't crash

332
00:14:58.639 --> 00:14:59.360
<v Speaker 2>your phone dialer.

333
00:14:59.480 --> 00:15:02.120
<v Speaker 1>It really highlights that the OS is the unsung hero.

334
00:15:02.759 --> 00:15:07.360
<v Speaker 1>We've talked about efficiency, convenience, evolution, but stallings leaves us

335
00:15:07.360 --> 00:15:11.600
<v Speaker 1>with one final, slightly terrifying concept, fault tolerance.

336
00:15:11.879 --> 00:15:15.960
<v Speaker 2>It's the realization that hardware will fail, not might will.

337
00:15:16.039 --> 00:15:18.279
<v Speaker 1>It's the law of large numbers. If you have billions

338
00:15:18.320 --> 00:15:20.000
<v Speaker 1>of transistors, one of them is going to flake out.

339
00:15:20.000 --> 00:15:22.279
<v Speaker 2>Eventually, a cosmic ray is going to hit your hard drive.

340
00:15:22.600 --> 00:15:25.440
<v Speaker 2>So the OS has to be paranoid. It relies on redundancy.

341
00:15:25.519 --> 00:15:27.000
<v Speaker 1>Redundancy in what sense.

342
00:15:26.919 --> 00:15:31.519
<v Speaker 2>Three senses actually spatial redundancy, having backup hardware like raid discs.

343
00:15:31.840 --> 00:15:35.240
<v Speaker 2>If one fails, the other takes over. Temporal redundancy. If

344
00:15:35.279 --> 00:15:37.799
<v Speaker 2>a calculation looks weird or fails, run it.

345
00:15:37.759 --> 00:15:40.039
<v Speaker 1>Again, just turn it off and on again at the

346
00:15:40.039 --> 00:15:41.960
<v Speaker 1>microchip level basically.

347
00:15:41.679 --> 00:15:45.799
<v Speaker 2>And information redundancy using air correcting codes to check if

348
00:15:45.879 --> 00:15:47.679
<v Speaker 2>a one accidentally flipped to a zero.

349
00:15:47.840 --> 00:15:50.000
<v Speaker 1>So the OS isn't just a manager. It is a

350
00:15:50.159 --> 00:15:51.679
<v Speaker 1>disaster prevention team.

351
00:15:51.960 --> 00:15:56.240
<v Speaker 2>Ideally, yes, it's managing a constant state of low level crisis.

352
00:15:56.679 --> 00:15:59.799
<v Speaker 2>It's masking the chaos of the physical world so that

353
00:15:59.840 --> 00:16:02.720
<v Speaker 2>you can exist in the pristine world of software. If

354
00:16:02.759 --> 00:16:05.240
<v Speaker 2>the OS does its job right, you never know how

355
00:16:05.240 --> 00:16:06.519
<v Speaker 2>close he came to a crash.

356
00:16:06.559 --> 00:16:09.120
<v Speaker 1>Well, on that comforting note. Next time your phone buzzes

357
00:16:09.120 --> 00:16:12.679
<v Speaker 1>with a notification, just remember that's an interrupt signal, saving

358
00:16:12.679 --> 00:16:16.159
<v Speaker 1>you from staring at a frozen screen. And that smooth scrolling,

359
00:16:16.480 --> 00:16:18.639
<v Speaker 1>that's a gamble that paid off. Thanks for listening to

360
00:16:18.679 --> 00:16:19.200
<v Speaker 1>the deep dive.

361
00:16:19.279 --> 00:16:20.279
<v Speaker 2>We'll catch on the next one.
