How Computer Memory Works | Introduction to Operating Systems

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

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

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

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.

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 How Computer Memory Works

What is the memory hierarchy in a computer?
The memory hierarchy arranges a computer's storage from smallest and fastest to largest and slowest. At the top are CPU registers, then cache, then main memory or RAM, then secondary storage such as an SSD or hard disk, and finally archival storage such as tape or cloud backups. Each level down holds more and costs less per byte, but takes longer to reach.
Why don't computers use only the fastest type of memory?
Fast memory needs costly circuits placed close to the CPU, so only a small amount fits and each byte is expensive. Storage that holds terabytes must be cheap per byte, which makes it slower to reach. No single technology wins on speed, capacity and cost together, so computers combine several levels and rely on locality, the habit programs have of reusing the same data.
How much slower is RAM than a CPU register?
A RAM access takes a few hundred times longer than a register access. A register answers in about one clock tick, while RAM takes around a hundred nanoseconds. Scaled so that one register step lasts one second, a RAM trip would take about five minutes, an SSD read about two days, and a hard disk read several months. Exact figures vary from machine to machine.
Which parts of the memory hierarchy does the operating system manage?
The operating system's main memory job is managing RAM: deciding which programs get which parts, keeping them apart, and moving data between RAM and the drive when RAM runs short. It also organizes the drive into files. Registers and cache are handled automatically by the compiler and the CPU hardware, while archival storage is handled by backup tools and the people who plan them.

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 →