Why Memory Management Matters

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

← 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 →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

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.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
Memory management has four main jobs: protection, sharing, efficient use and multiprogramming. Protection stops one process from reading or changing another's memory or the operating system's. Sharing lets processes use the same memory on purpose, such as one copy of an editor's code. Efficient use hands out only what is needed and takes it back. Multiprogramming keeps several programs in RAM so the CPU stays busy.
How do you calculate CPU utilization with multiprogramming?
A simple model gives CPU utilization as 1 minus p to the power n, where p is the fraction of time each program waits for input and output, and n is the number of programs in memory. The CPU idles only when all n wait at once. With p equal to 0.5 and three programs, utilization is 1 minus one eighth, or 87.5 percent.
Is memory protection only about stopping viruses?
No, memory protection mostly guards against honest bugs. A loop that runs one step too far can write past the end of its array. Without protection, that stray write could corrupt another program's data or the operating system itself. With hardware-enforced protection, the faulty access is stopped and only the buggy program is ended, while everything else keeps running.
Why does running only one program at a time waste the CPU?
Running one program at a time wastes the CPU because the program often waits for a slow drive, the network or a person typing, and the CPU sits idle during every wait. The earliest computers worked this way, giving one program all of memory. Keeping several programs in RAM lets the CPU switch to another one whenever one waits. Loading too many, though, runs RAM short and forces slow trips to the drive.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Introduction to Operating Systems
3 credits · NCCRS
Enroll →