UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 4.5 Free with a free account
Why Memory Management Matters
Introduction to Operating Systems · Chapter 4: Memory ManagementSection 4.5 · lesson 29 of 837 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Address Spaces →← The History of Data StorageNext lesson: Address Spaces →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
Why the OS must protect, share and allocate RAM among programs.
- Name the four jobs of memory management: protection, sharing, efficient use and multiprogramming
- Explain why memory protection matters for ordinary bugs as well as attacks
- Calculate CPU utilization with the 1 minus p to the n model
- Describe the balance between multiprogramming and memory overload
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (994 words). Read along, or search it.
Opening Scene
A Shared Bookshelf With No Rules
Picture a shared bookshelf in a classroom, with no rules at all. One student pushes the others' books aside to make room for a project. Another drops a stack right on top of someone's work. By lunch, nobody can find anything. A computer's RAM is that bookshelf, and many programs want it at once. Somebody has to keep order. That somebody is the operating system.
Early Computers
One Program Owning All Memory
The earliest computers ran one program at a time, and gave it all of memory. That's simple, but it wastes the machine. While the program waits for a slow drive, or for a person typing, the CPU sits idle. The fix is to keep several programs in RAM at once, and switch between them, as lesson 2.4 showed.
Definition
What Memory Management Tracks
The moment two programs share RAM, new problems appear. A bug in one program could overwrite the memory of another, or of the operating system itself. Each program needs its own piece, with no pieces overlapping and no space wasted in gaps. And when a program ends, its piece must be taken back for the next one. Memory management is the part of the OS that tracks memory: which parts are in use, and by whom. It hands memory out, takes it back, and keeps programs out of each other's space.
Jobs One and Two
Protection and Planned Sharing
Memory management has four jobs. The first is protection. One process must not read or change another's memory, or the operating system's. If it tries, the hardware stops it, and the OS ends that process. Lesson 4.6 shows the check. The second job is sharing, done on purpose. Say two windows run the same editor. The editor's code never changes while it runs, so it can sit in RAM just once, shared by both. Only each window's own data is kept separate. Shared memory between cooperating processes, from lesson 3.7, is another planned kind of sharing.
Common Mistake
Protection Guards Against Honest Bugs
A common mistake is to think protection is only about viruses. Most of the time, it protects programs from honest bugs. Picture a loop that runs one step too far, and writes past the end of its array. Without protection, that one extra write could land in the order list of Sam, who runs a small online bakery. With it, only the faulty program ends. Security, in lesson 9.7, builds on these same walls.
Jobs Three and Four
Efficient Use and Multiprogramming
The third job is efficient use. RAM is costly and limited, so none of it should be wasted. The OS hands out only what's needed, and takes it back when a program ends. When RAM runs short, it moves rarely used data out to the drive, as lesson 4.7 explains. And it tries not to leave many small, useless gaps, the subject of lesson 4.11. The fourth job is multiprogramming: keeping several programs in RAM at once, so that when one waits, the CPU runs another.
Utilization Model
A Formula for CPU Busy Time
How much does multiprogramming help? Programs spend much of their time waiting: for the drive, the network, or a person. Say each program waits for input and output a fraction p of the time. Alone, it keeps the CPU busy only 1 minus p of the time. With n independent programs in memory, the CPU is idle only when all of them wait at once. The chance of that is p to the power n. So the CPU is busy about 1 minus p to the n of the time. It's a simple model: real programs aren't perfectly independent.
Worked Example
Programs That Wait 80 Percent
Try it with programs that wait 80 percent of the time. With one program, the CPU is busy just 20 percent of the time. Two programs: 36 percent. Three: almost 49. Four programs: 59 percent. Six: about 74. Eight: about 83. Every program you add fills more of the CPU's idle time.
Balance
Too Many Programs Overload RAM
So why not load as many programs as possible? Because every program needs its own RAM. Add too many, and RAM runs out. Then the OS must push data out to the drive, which is far slower, as lesson 4.1 showed. So memory management has to balance: enough programs to keep the CPU busy, but not so many that memory is overloaded. Lesson 4.7 shows what happens when it is.
Chapter Roadmap
The Tools of Memory Management
The rest of this chapter gives memory management its tools. Address spaces, with base and limit registers, give each program its own range, and block any step outside it. That's lesson 4.6. Virtual memory lets programs use more memory than the RAM installed. Paging cuts memory into equal pieces, so any free piece can be used. Caches, and keeping them coherent, keep copies fast and consistent. And allocation and garbage collection hand out pieces, and take them back.
Quick Check
Three Programs Waiting Half the Time
Quick check. A school's file server runs programs that each wait for the disk half of the time. Three of them sit in memory at once. Using the model, about how busy is the CPU? About 50 percent, about 75 percent, or about 88 percent? Pause, and decide. Eighty-eight percent. The CPU idles only when all three wait at once: a half, times a half, times a half, which is one eighth. One minus one eighth is seven eighths, or 87.5 percent. Fifty percent is one program alone, and seventy-five is two. Each program added fills more of the idle time.
Real Case
Twenty Browser Tabs on an Old Laptop
The balance shows up on ordinary laptops too. Sam once had the order list, a music player and twenty browser tabs open. The old laptop felt sluggish. Ivy, who looks after the computers at a school, opened the task manager and sorted by memory. RAM was nearly all used, so the OS kept shuffling pieces out to the drive. Close the tabs you don't need, she said. Sam closed ten of them, and the stutter stopped.
Key Takeaways
Four Jobs and a Balance
To recap. Memory management keeps order in RAM, which many programs share. Its four jobs are protection, sharing, efficient use, and multiprogramming. More programs in memory keep the CPU busier: about 1 minus p to the n. But too many overload RAM, so the OS has to balance.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Why Memory Management Matters
What are the main goals of memory management in an operating system?
How do you calculate CPU utilization with multiprogramming?
Is memory protection only about stopping viruses?
Why does running only one program at a time waste the CPU?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →