UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 4.1 Free with a free account
How Computer Memory Works
Introduction to Operating Systems · Chapter 4: Memory ManagementSection 4.1 · lesson 25 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: Storage Technologies →← Cooperating ProcessesNext lesson: Storage Technologies →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
The memory hierarchy from CPU registers down to archival storage.
- List the five levels of the memory hierarchy in order of speed
- Explain the trade-off between speed, capacity and cost per byte
- Trace the route data takes from a disk to a CPU register
- Identify which levels the compiler, the hardware and the operating system manage
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 (1,025 words). Read along, or search it.
Opening Scene
A Spreadsheet That Slows to a Crawl
Sam, who runs a small online bakery, opens one giant spreadsheet on an old laptop: every order since the shop began. Everything slows to a crawl. Typing a single number takes seconds. Ivy, who looks after the computers at a school, takes one look. Nothing is broken, she says. The right data is just in the wrong place. What does that mean? Where can data even be, inside one computer?
Three Meanings
What People Mean by Memory
Ask people what memory means, and you'll get different answers. The gigabytes on a phone's spec sheet. The drive that holds their photos. Or something inside the processor itself. A computer has all of these, and each one has a different job.
Memory Hierarchy
Five Levels From Registers to Archives
Computer scientists arrange them in a memory hierarchy: levels ordered from the smallest and fastest at the top, to the largest and slowest at the bottom. At the top are registers: a handful of tiny slots inside the CPU. The CPU does its arithmetic on values held in registers. Next comes cache: a small, very fast memory on or beside the CPU. It keeps copies of data the CPU used recently, so it needn't wait for RAM again. Then main memory, called RAM: the computer's workspace. Every running program, and the data it's using, must be here. Below it is secondary storage: a solid state drive or a hard disk. Your files live here, and they stay when the power is off. And at the bottom, archival storage: tape, spare drives on a shelf, or the cloud. It holds backups and old records you rarely read.
Analogy
Pencil, Desk, Backpack, Locker, Attic
Why not build a computer from only the fastest kind? Picture a school day. The pencil in your hand is ready this instant. But you can hold only one or two. Your desk holds the book you're using. Your backpack carries the rest of today's books. Your locker down the hall holds more still. And last year's notes sit in a box in the attic. Each place holds more than the one before, and each is a longer walk away. So you keep what you use most close by. A computer does exactly this. Registers are the pencil, cache the desk, RAM the backpack, the drive your locker, and the archive is the attic. It works because programs use the same data again and again. That habit is called locality, and lesson 4.9 explains it.
Trade-Off
Speed, Capacity and Cost per Byte
Three things pull against each other: speed, capacity, and cost per byte. Fast memory needs special, costly circuits, placed close to the CPU. So there's only room for a little of it. Memory that holds terabytes must be cheap per byte, and that makes it slower to reach. No single technology wins all three. So computers combine several, and let each do what it does best.
Speed Gaps
Stretching Nanoseconds Into Human Time
How big are the gaps? These are rough sizes, and they vary from machine to machine. A register answers within about one tick of the CPU's clock. Cache takes a few ticks. RAM takes around a hundred billionths of a second. An SSD, tens of millionths. A hard disk, several thousandths, because a part must physically move. Those are hard to feel, so stretch time. If one register step took one second, a trip to RAM would take about five minutes. An SSD read would take about two days. And a hard disk, several months. That's why a laptop that runs out of RAM, and has to lean on its drive, feels like it hit a wall.
Volatility
RAM Forgets, Drives Remember
One more difference. Switch the power off, and RAM forgets everything. A drive remembers. So RAM is called volatile: it needs power to keep its contents. Drives are non-volatile. That's why unsaved work disappears in a crash. Lesson 4.2 shows how each kind holds its bits.
Who Manages What
Compiler, Hardware and the OS
So who decides what goes where? You don't pick what sits in a register, or in cache. The compiler and the CPU's hardware handle those, automatically. The operating system's big memory job is main memory. It decides which programs get which parts of RAM, and it keeps them apart. When RAM runs short, it moves data between RAM and the drive. Lessons 4.5 to 4.7 show how. The OS also organizes the drive into files, in chapter 6. Archives are handled by backup tools, and by the people who plan them.
Quick Check
From Disk to a Register
Quick check. A student in Ivy's lab runs a program. It needs a number that's stored only on the hard disk. Before the CPU can add anything to it, that number has to reach a register. Which route does it take? Disk, then cache, then RAM, then a register? Disk, then RAM, then cache, then a register? Or from the disk straight into a register? Pause, and decide. Disk, then RAM, then cache, then a register. A running program's data must be in RAM, so the number comes up from the disk into RAM first. When the CPU asks for it, a copy passes through cache on the way, and lands in a register, where the arithmetic happens. Cache can't come first: it only keeps copies of data from RAM. And nothing jumps from the disk straight into a register.
Real Case
Moving Old Orders to the Cloud
Back to Sam's spreadsheet. Every order since the shop began was open at once, so RAM filled up. With RAM full, the operating system kept pushing pieces out to the drive and pulling them back. That's the crawl Sam felt. Ivy moved the old years to a backup in the cloud, which is archival storage, and opened only this month's orders. The laptop felt new again. Nothing was added. The data just went to the right level.
Key Takeaways
Keep Reused Data Close
To recap. The memory hierarchy has five levels: registers, cache, RAM, secondary storage, and archival storage. Fast memory is small and costly per byte. Big memory is cheap and slow, so computers mix the levels. The compiler and the CPU hardware manage registers and cache. The operating system manages main memory. And because programs reuse the same data, keeping it close works.
Try It
Check Your Own RAM and Storage
Something to try. Look up your own phone or laptop, under About or Storage. How much RAM does it have, and how much storage? Which kind would you guess costs more per gigabyte?
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 How Computer Memory Works
What is the memory hierarchy in a computer?
Why don't computers use only the fastest type of memory?
How much slower is RAM than a CPU register?
Which parts of the memory hierarchy does the operating system manage?
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 →