Operating Systems: Internals and Design Principles - podcast episode cover

Operating Systems: Internals and Design Principles

Mar 03, 202616 min
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

A comprehensive textbook on operating system internals, covering the fundamental principles of computer architecture and software management. It explains the core objectives of an operating system, specifically highlighting its role in ensuring efficiency, convenience, and hardware abstraction. Key technical topics include process description and control, multithreading, and the complexities of concurrency, such as mutual exclusion and deadlock prevention. The source also examines specific management strategies for virtual memory, I/O functions, and file systems across diverse platforms like Linux, Windows, and Android. Additionally, the material addresses modern computing challenges including symmetric multiprocessing, virtual machine architecture, and system security. Specialized environments are also explored, ranging from embedded systems and real-time scheduling to distributed processing in client-server clusters.

You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary

Get the Book now from Amazon:
https://www.amazon.com/Operating-Systems-Internals-Design-Principles/dp/0133805913?&linkCode=ll2&tag=cvthunderx-20&linkId=9a0f93409d160d8e7ff6e79ff74b6adc&language=en_US&ref_=as_li_ss_tl

Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy

Transcript

Speaker 1

Welcome back to the deep dive. You know, I was looking at the stack of notes for today we are tackling William Stallings's massive text Operating Systems, internals and design principles, and it really hit me. We spend all this money on faster processors, better ram but the thing that actually decides if we have a good experience is this invisible layer we almost never talk about.

Speaker 2

It's the ghost in the machine, literally.

Speaker 1

And Stallings makes this comparison right out of the gate that to stop me. He doesn't compare the operating system to a brain or you know, an engine. He compares it to a.

Speaker 2

Government, which, depending on your political views, might make you a little nervous about turning on your laptop.

Speaker 1

It definitely gives you pause. But when you dig into the book the analogy it fits surprisingly well. The OS doesn't actually produce anything, does it.

Speaker 2

No, it doesn't write your email or edit your photo. It just it creates the environment where those things can happen. That's the core function. It paves the roads, polices the intersectctions, and it collects taxes in the form of memory and processing power.

Speaker 1

And like a government, it's constantly fighting this sort of three way war with itself. Stallings lays these out really clearly. Convenience, efficiency, and the ability to evolve, and.

Speaker 2

Those three things do not naturally go together.

Speaker 1

Not at all. In fact, they seem like they would actively sabotage each other.

Speaker 2

They absolutely do. I mean, think about convenience. That's you, the user. You want a beautiful desktop, you want transparent windows, plug and plate devices. You do not want to see the wiring.

Speaker 1

I definitely do not want to see the wiring. I just want to click the button and have it work.

Speaker 2

But hiding the wiring is expensive. Yeah, that eats up system resources, which fights against objective number two efficiency. The hardware just wants to run raw code as fast as possible, not paint pretty pictures for you. Every cycle spent drawing a drop shadow on a window is a cycle not spent calculating a spreadsheet.

Speaker 1

So the OS is basically stuck in the middle trying to make me happy without making the CPU quit in frustration, while.

Speaker 2

Also handling objective three evolution. It has to be built in a way that allows it to change completely next year without breaking all the software you bought five years ago. It's a juggling act.

Speaker 1

An unbelievable juggling.

Speaker 2

App billions of times a second.

Speaker 1

So let's get into the mechanics of this. Stallings breaks it down to the instruction cycle. Fetch, execute, fetch execute. It sounds so simple.

Speaker 2

It is. It's the heartbeat of the machine. But there's a massive physiological problem with this computer body. Okay, the brain, the CPU is moving at the speed of light, but the hands and feet, the input output devices like your hard drive or your Wi Fi card are moving through molasses.

Speaker 1

Stalling's had a stat on this that just blew my mind. The speed difference isn't a little bit, it's orders of magnitude.

Speaker 2

It's astronomical. If the CPU's a Ferrari driving it at two hundred miles an hour, the hard drive is a tractor. No, that gives a hard drive too much credit.

Speaker 1

It's a snail.

Speaker 2

It's a snail exactly.

Speaker 1

So you didn't have a smart operating system and you told the computer to save file that Ferrari effectively has to slam on the brakes and just idle for what feels like one hundred years while the snail writes the data.

Speaker 2

That's the polling method. CPU just sits there, asking the drive Are you done yet? Are you done yet? Are you done yet?

Speaker 1

What a waste.

Speaker 2

It's a massive waste, a billion dollar hardware. You have the world's smartest mathematician sitting there waiting for a printer to warm up.

Speaker 1

So they invented interrupts. And I love this term because it sounds rude, but it's actually the most polite thing the hardware can do.

Speaker 2

It's save computing with interrupts. The Ferrari sends the save command to the snail and then immediately peels out and goes to do something else.

Speaker 1

Okay, so it goes off and runs a spreadsheet, plays music, whatever. But wait, how does it know when the snail is done?

Speaker 2

The snail has a direct line to the CPU. When it's finished, it sends an electrical signal and interrupt. It forces the CPU to pause whatever it's doing to acknowledge that the task is complete.

Speaker 1

See that's the part that stresses me out. If I'm in the middle of a complex math problem and you interrupt me, I lose my place. I have to start over.

Speaker 2

And that is the magic trick. Yeah, the OS performs a context switch. Okay, imagine you're reading a really dense novel and the doorbell rings, You don't just throw the book on the floor, right, you put a bookmark in. You write down exactly which line you were on, maybe even the thought you were having in that split second.

Speaker 1

So that's the state of the process.

Speaker 2

Correct, the program counter, the register values. Everything gets pushed onto a control stack. It's a snapshot of reality frozen in time. Wow, you go answer the door, handle the big job, and when you come back, you pop that snapshot back off the stack. The software doesn't even know it was passed, so.

Speaker 1

To me, it looks like everything happened at once exactly.

Speaker 2

It completely decouples the user's perception of time from the computer's reality.

Speaker 1

But what happens if the doorbell rings while I'm already on the phone?

Speaker 2

Ah, the nightmare scenario multiple.

Speaker 1

Interrupts, is the system just crash?

Speaker 2

Depends on how it's designed. You can disable interrupts basically take the phone off the hook while you answer the door, or you can have nested interrupts.

Speaker 1

Which implies a hierarchy. Some things are more important.

Speaker 2

Precisely, if your network card says incoming data that's urgent. If your printer says I'm out of paper, that can wait The OS prioritizes the urgent interrupt handles it then goes back to the less urgent one, and finally back to your program.

Speaker 1

And all of this happens so fast that I just see a smooth mouse cursor.

Speaker 2

Well underneath, it's just controlled chaos.

Speaker 1

So we have the CPU maximizing its time with interrupts. But there's another bottleneck, right memory. We all want terabytes of storage that's instantly accessible. But Stallings points out the iron triangle of memory capacity, speed, and cost.

Speaker 2

And you can pick two because you cannot have all three. Fast memory like the registers right inside the CPU, is incredibly expensive and tiny. Big memory like your hard drive is cheap but slow.

Speaker 1

So the OS has to lie to us again. It has to create the illusion that we have unlimited, super fast memory.

Speaker 2

And it does that through the memory hierarchy. It's a pyramid. Data is constantly moving up and down. But the secret sauce, the thing that makes the lie convincing is this concept of locality of reference.

Speaker 1

This is essentially the OS gambling right. It's betting on what I'm going to do next.

Speaker 2

It's a rigorous statistical gamble. They are two types. First, temporal locality Okay, if you looked at a photo five seconds ago, the odds are really high you'll look at it again in the next five seconds. Think about a loop and a piece of code.

Speaker 1

It's the same instructions over and over, so you keep that data close exactly.

Speaker 2

And then there's spatial locality. If you're reading a document at line ten, there is a ninety nine percent chance you're going to need line eleven next.

Speaker 1

You almost never jump from line ten to line five thousand.

Speaker 2

Right, So the OSCs you're reading line ten and quietly in the background, it runs down to the slow warehouse, grabs lines eleven through twenty and puts them on the fast on the top, right next to the CPU that's cashing. That's cashing, and it works surprisingly well. A well toned o S can get a hit on that cash maybe ninety percent of the.

Speaker 1

Time, which explains why when I open a huge app for the very first time, it sometimes chugs for a second.

Speaker 2

That's a miss, right. The chef reached for the salt, but it wasn't on the counter. He had to run to the pantry. But once he brings it out, it stays on the counter. It stays on the counter. The next time you click. It's instant.

Speaker 1

It's fascinating to think about this because it means my computer is constantly trying to predict the future based on the immediate past.

Speaker 2

And when a guess is right, you feel like you have a supercomputer. When a guess is wrong, you get the spinning wheel of death.

Speaker 1

It's so easy to take this for granted. Now we have casing, we have interrupts. Everything feels instant. But Stallings takes us back to the nineteen forties and fifties to show us the dark Ages.

Speaker 2

It really was the dark Ages. No operating system, no mouse, no screen. It's a clipboard, a literal clipboard outside the computer room. You signed up for a thirty minute block. You walked in with your deck of punch cards. You loaded them into the machine, and you prayed.

Speaker 1

And if you had a typo, a light.

Speaker 2

Flashed, the machine stopped, and your thirty minutes were up. You had to go back to your desk and debug by just staring at holes in paper.

Speaker 1

The inefficiency is painful to even think about. While you were walking around loading cards, checking the lights, this million dollar machine was just sitting.

Speaker 2

There burning electricity, doing nothing. That idle time is what drove the invention of the OS. It wasn't about user comfort, it was about money. They needed batch processing to keep the machine.

Speaker 1

Fed, and this is where we see the first monitor programs.

Speaker 2

Yes, you'd hand your cards to an operator. The operator fed them to the machine one after another. The monitor was a simple program that just said Okay, job one is done, load job two.

Speaker 1

But even then, if a job had to wait for a tape to rewind, the CPU starped again.

Speaker 2

Which led to the biggest leap inefficiency multi programming, the idea that you could hold multiple job and memory at once.

Speaker 1

So if job A waits for a.

Speaker 2

Tape, the OS switches to Joe B.

Speaker 1

Stallings mentions that uniprogramming had something like what three percent CPU utilization? Multiprogramming just blew that away.

Speaker 2

It changed the economics of computing, but it was still impersonal. You submitted a job and came back hours later for the print.

Speaker 1

Out, which brings us to the moment the computer became personal time sharing.

Speaker 2

This is the MIT system CTSS. Before this, the goal was always maximized the CPU. With time sharing, the goal shifted to maximize the user.

Speaker 1

And this is where we get the concept of time slicing right.

Speaker 2

Yes. Imagine a chess master playing fifty games at once. He walks to board one, makes a move, walks to board two, makes a.

Speaker 1

Move, and if he moves fast enough.

Speaker 2

Every player feels like they have his full attention.

Speaker 1

So the OS is the chess master. It runs my browser for a fraction of a second, then switches to your music player, then the system clock and back to my browser.

Speaker 2

Every point two seconds in those early systems. Now it's much much faster. It creates the illusion of concurrency.

Speaker 1

You think you're multitasking, but the computer is actually just panic switching.

Speaker 2

Panic switching between tasks fast enough to fool your eyes.

Speaker 1

This required a huge leap in software architecture, though Stallings really emphasizes the concept of the process.

Speaker 2

It sounds abstract, but it's so vital. A program is just a static set of instructions on a disc. It's dead. A process is that program in execution. It's alive.

Speaker 1

It has baggage, it has.

Speaker 2

Context, it has ownership of memory, it has security clearance, it has a priority level. By treating running programs as processes, the OS could finally manage them safely.

Speaker 1

It could isolate them.

Speaker 2

Isolate them, so if one process crashes, it doesn't necessarily kill the others.

Speaker 1

And this ties into virtual memory too, because if you have fifty processes running, they can't all fit in the physical RAM.

Speaker 2

Virtual memory is the ultimate illusion. The OS breaks a process into these fixed sized blocks called pages. It can scatter them those pages anywhere, some in RAM, some on the desk.

Speaker 1

With the program thinks it's all in one continuous piece.

Speaker 2

The program sees a continuous, beautiful block of memory. It uses virtual addresses. The hardware, specifically, the memory management unit translates those virtual desks into physical addresses.

Speaker 1

On the fly, so a developer can write a program that uses four gigabytes of RAM even if the machine only has two gigabytes free. It's basically gas lighting the software. Oh yeah, you totally have all the space while frantically shuffling data in and out of the back door.

Speaker 2

Gas Lighting is a harsh word for it, but technically accurate. It's abstraction. You abstract the harsh reality of the hardware to create a better reality for the software.

Speaker 1

Speaking of harsh reality, let's talk about the hardware we use today. We aren't just using single processors anymore.

Speaker 2

We have SMP and multi core Symmetric multiprocessing. SMP was the first step. You plug two or four separate CPUs into one motherboard.

Speaker 1

They share everything, they.

Speaker 2

Share memory IO. The US has to schedule tasks across all of them.

Speaker 1

Which is great for real life liability. If one burns out, the other keeps going.

Speaker 2

But multi core is where we are now putting multiple brains on a single chip. It's faster, more efficient, but it creates a huge headache for the OS designer called cash coherence.

Speaker 1

Because each core has its own little cash right, its own little countertop of ingredients exactly.

Speaker 2

So Core A changes the value, you say, updates your bank balance in its private cache, but COREB tries to read that balance from its own cash.

Speaker 1

COREB has old information. You have a synchronization nightmare.

Speaker 2

So the OS and the hardware have to constantly gossip with each other. Hey, I changed this value, invalidate your copy. It has a lot of complexity.

Speaker 1

It's fascinating that all these tricks interrupts caching, time slicing. They're universal, but how they're packaged differs. Stallings compares the big three Windows, Linux, and Android, and they have very different personalities.

Speaker 2

They do take Windows. Windows is the ultimate corporate manager. It's highly modular. It has this thing called the HL, the Hardware abstraction.

Speaker 1

Layer, which sounds like the villain from two thousand and one A Space Odyssey.

Speaker 2

Fortunately it's helpful. The HAL is a translator. It means the core of Windows does need to know if you're running an Intel chip or an AMD chip, or what motherboard you have. AHL handles the specifics.

Speaker 1

It isolates the kernel.

Speaker 2

From the messiness of the real world. This is why you can build a PC out of random parts and Windows generally just boots up.

Speaker 1

It prioritizes compatibility, compatibility, and portability.

Speaker 2

It uses a client server model. Even internally, different parts of Windows talk to each other by sending messages, almost like they're on a network.

Speaker 1

Now contrast that with Linux. Stallings calls it monolithic. That sounds heavy.

Speaker 2

It is, but in a good way. In Linux, the kernel is one giant, highly optimized brain. All the drivers, the file systems, the memory management, it's all living in the same address space.

Speaker 1

Isn't that dangerous If the audio driver crashes, doesn't it take down the whole brain?

Speaker 2

Historically, yes, that was the big criticism, but Linux got clever. They added loadable.

Speaker 1

Modules like Lego bricks sort of.

Speaker 2

It means you can plug in a new device driver or a file system while the kernel is running. You don't have to shut down and rebuild the whole LOS just to add support for a new webcam.

Speaker 1

So you get the raw speed of a monolithic kernel with.

Speaker 2

The flexibility of a modular one. It's the Borg approach, adapt and assimilate without stopping.

Speaker 1

And then Android is basically Linux putting on a hiking backpack.

Speaker 2

It is Linux optimizing for survival power management on a server. Linux assumes it has a wall socket. It runs tasks whenever it wants. On a phone, Android has to be ruthless. It uses wayclocks to prevent apps from keeping the CPU awake.

Speaker 1

It kills background processes.

Speaker 2

Aggressively because the dead battery makes the smartest OS completely useless.

Speaker 1

True.

Speaker 2

Android also uses a unique software stack for apps. It doesn't run standard Linux programs. It runs apps inside a virtual.

Speaker 1

Machine, which creates a sandbox.

Speaker 2

Right, so if an angry bird crashes, it doesn't crash your phone dialer.

Speaker 1

It really highlights that the OS is the unsung hero. We've talked about efficiency, convenience, evolution, but stallings leaves us with one final, slightly terrifying concept, fault tolerance.

Speaker 2

It's the realization that hardware will fail, not might will.

Speaker 1

It's the law of large numbers. If you have billions of transistors, one of them is going to flake out.

Speaker 2

Eventually, a cosmic ray is going to hit your hard drive. So the OS has to be paranoid. It relies on redundancy.

Speaker 1

Redundancy in what sense.

Speaker 2

Three senses actually spatial redundancy, having backup hardware like raid discs. If one fails, the other takes over. Temporal redundancy. If a calculation looks weird or fails, run it.

Speaker 1

Again, just turn it off and on again at the microchip level basically.

Speaker 2

And information redundancy using air correcting codes to check if a one accidentally flipped to a zero.

Speaker 1

So the OS isn't just a manager. It is a disaster prevention team.

Speaker 2

Ideally, yes, it's managing a constant state of low level crisis. It's masking the chaos of the physical world so that you can exist in the pristine world of software. If the OS does its job right, you never know how close he came to a crash.

Speaker 1

Well, on that comforting note. Next time your phone buzzes with a notification, just remember that's an interrupt signal, saving you from staring at a frozen screen. And that smooth scrolling, that's a gamble that paid off. Thanks for listening to the deep dive.

Speaker 2

We'll catch on the next one.

Transcript source: Provided by creator in RSS feed: download file
For the best experience, listen in Metacast app for iOS or Android