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
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: RAID →← 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 →
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.
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 Flash Memory
How does flash memory keep data without power?
What is the difference between SLC, MLC, TLC and QLC flash?
What does wear leveling do in an SSD?
What does the TRIM command do for an SSD?
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 →