Flash Memory, Explained | Introduction to Operating Systems

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 5.11 Free with a free account

Flash Memory

Introduction to Operating Systems · Chapter 5: Peripheral Devices and I/O SystemsSection 5.11 · lesson 46 of 838 min · free with a free account

← Optical StorageNext lesson: RAID →

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

How flash cells store charge and SSD controllers hide erase-before-write.

  • Explain how a floating-gate cell stores a bit as trapped charge
  • Relate bits per cell to the number of charge levels in SLC, MLC, TLC and QLC flash
  • Describe the erase-before-write rule for pages and blocks
  • Explain how mapping, garbage collection, wear leveling and TRIM keep an SSD fast and durable

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,120 words). Read along, or search it.

Opening Puzzle

Memory With No Moving Parts

Your phone has no spinning disk, no laser, and no tape. Yet it remembers your photos for years, even with the battery dead. How can a chip with no moving parts hold a memory? And here's the odd part. A flash chip can write a tiny piece of data, but it can't erase just that piece. To change one photo's note, it must wipe a whole neighborhood first. Controllers have clever tricks to hide this, and those tricks explain many quirks of every SSD and flash drive.

How It Works

Charge Trapped in a Floating Gate

Flash memory stores bits in tiny cells made of transistors, small electronic switches. Each cell has a part called a floating gate: a pocket of insulated material that can trap electrons, which carry electric charge. Trapped charge stays there with no power at all, because the pocket is walled in by insulation. Trapped charge is a stored zero, and no trapped charge is a stored one, or the other way round, depending on the design. Reading just checks whether the cell lets current through.

Cell Types

NAND Flash and Bits per Cell

The common kind is called NAND flash, named for the way its cells are wired together in chains, like a NAND logic gate. It packs cells densely, which is why SSDs and USB drives can be large and cheap. And a cell can hold more than one bit, by trapping different amounts of charge. Two levels store one bit. That's SLC, for single-level cell. Four levels store two bits: MLC. Eight levels store three bits: TLC. Each extra bit doubles the levels the chip must tell apart. More bits per cell means more data on the same chip. The cost is that it's slower, and wears out faster.

Quick Check

Charge Levels in a QLC Cell

Quick check. A QLC cell, quad-level, stores four bits. How many charge levels must the chip tell apart in that one cell? Pause, and work it out. Sixteen. Each extra bit doubles the levels: two, four, eight, sixteen. Four bits need two to the fourth levels. Four is the tempting answer, because the cell holds four bits. But levels grow by doubling, not by counting bits. That's why packing more bits makes a cell harder to read, and quicker to wear.

Key Rule

Write Pages, Erase Whole Blocks

Cells are grouped. A page is a group of cells, a few kilobytes in size, and it's the smallest piece you can read or write. A block is a group of many pages, and it's the smallest piece you can erase. That gives a strange rule that shapes everything. Writing, which the chip calls programming, can only fill a page that's empty. A page that holds data can't be overwritten in place. To make pages empty again, the whole block must be erased at once. This is called erase-before-write.

Worked Example

Updating a Toy Flash Block

Here's a toy flash block with four pages. Page zero holds a price list. Now try to update that page in place. The toy refuses: page zero is not erased; erase the whole block first. So erase the block, and write version two. Now page zero holds the new price list, and the other three pages are empty. But notice: wiping a whole block also wipes its other pages. A real drive has to rescue those first. So naive in-place updates are slow, and wasteful.

SSD Controller

Mapping, Garbage Collection and Error Correction

An SSD hides all this from the operating system. To the OS, it looks like a plain drive of numbered storage spots, just like a hard disk. Inside, a small computer called the SSD controller manages the flash chips. It has four main jobs. Mapping: it keeps a map linking the numbers the OS uses to the pages where the data really sits. An update goes to an empty page, the old copy becomes stale, and only the map changes. The OS never notices. Garbage collection: it copies the live pages out of a block full of stale ones, then erases the block. Wear leveling, which comes next. And error correction: extra check data so flipped bits can be fixed. That idea, parity, comes back in lesson 5.12.

Wear Leveling

Spreading Erase Cycles Across Blocks

Each erase-and-rewrite cycle slightly damages a cell's insulation. After a limited number of cycles, which depends on the type of flash, a block stops holding charge reliably. If one popular file were always stored in the same block, that block would die long before the others. Wear leveling spreads the wear. The controller moves writes around, so every block ages evenly. In a toy with four blocks, one hundred updates to the same file erase one block a hundred times if the file stays put. With wear leveling, each block is erased only twenty-five times.

TRIM Command

Telling the Drive Which Pages Are Unused

There's one more problem. When you delete a file, the OS only removes it from its own list, which lesson 6.2 explains. The SSD controller doesn't know those pages are now useless. So it keeps copying them during garbage collection. The fix is TRIM: a command the OS sends to say, these pages are no longer in use. In a toy block of four pages, where a deleted file used three, the controller copies four pages before erasing, without TRIM. With TRIM, it copies just one. Less copying means faster writes, and less wear.

Common Mistake

Deleting a File Does Not Erase It

A common mistake is thinking that deleting a file erases it from an SSD right away. Deleting only removes the file's name from the OS's list. The pages are marked stale, or reported by TRIM, and physically erased later, when their block is cleaned. Truly secure erasing needs special tools. Lesson 9.5 returns to protecting data. Sam, who runs a small online bakery, once worried because the shop laptop's log file was rewritten every few seconds. Will the SSD burn out? Ivy, who looks after the computers at a school, shrugged. The controller moves that log around, so no single block takes all the wear. Your drive will outlive the laptop. Just keep a backup, because anything can fail.

Quick Check

Cleaning a Block Without TRIM

Quick check. An old school laptop's SSD never receives TRIM. Someone deletes a six-page file. Later, the controller cleans the block that holds those six pages. What happens to them? Pause, and decide. They're copied, as if still in use. Without TRIM, the controller can't tell deleted pages from live ones, so it rescues them before erasing the block: wasted copying, and extra wear. Erased at deletion is the tempting answer, but deleting only changes the OS's list. And the OS can't erase flash pages itself: only the controller erases, a whole block at a time.

Key Takeaways

Cells, Pages, Blocks and the Controller

To recap. A flash cell stores a bit as charge trapped behind insulation, and more levels per cell hold more bits. You read and write a page, but you erase a whole block. The SSD controller maps pages, collects garbage, and levels wear. And TRIM tells it which pages are no longer in use.

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 Flash Memory

How does flash memory keep data without power?
Flash memory keeps data by trapping electric charge in an insulated pocket inside each cell, such as a floating gate. Because the insulation holds the electrons in place, the charge stays even when power is off. Reading a cell checks whether it lets current through, which tells the chip whether charge is trapped there and so which bit the cell stores.
What is the difference between SLC, MLC, TLC and QLC flash?
They differ in how many bits each cell stores: one for SLC, two for MLC, three for TLC and four for QLC. Each extra bit doubles the charge levels the chip must tell apart, from two levels up to sixteen. More bits per cell fit more data on the same chip, but the cells become slower and wear out faster.
What does wear leveling do in an SSD?
Wear leveling spreads writes and erases evenly across an SSD's blocks so no single block wears out early. Each erase cycle slightly damages a cell's insulation, and a block survives a limited number of cycles. The controller moves frequently updated data around, so a file rewritten 100 times across four blocks costs each block about 25 erases instead of one block taking all 100.
What does the TRIM command do for an SSD?
TRIM lets the operating system tell the SSD which pages no longer hold useful data, usually after files are deleted. Without it, the controller cannot tell deleted pages from live ones, so it keeps copying them during garbage collection. With TRIM, the controller skips those pages, which means less copying, faster writes and less wear on the flash.

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 →