Storage
1. What is Storage?
Storage is the hardware and software system used to store data, programs, files, and information so they can be used now or in the future.
In an operating system, storage management deals with how data moves between:
CPU ↓ RAM ↓ Storage
Examples of storage:
- HDD
- SSD
- USB flash drive
- Memory card
- Optical disc
- External hard drive
- Network storage
2. Why Do We Need Storage?
RAM is fast but usually volatile.
That means:
Power ON ↓ Data available Power OFF ↓ RAM data lost
Storage is generally non-volatile:
Power ON ↓ Data available Power OFF ↓ Data remains
For example:
Your computer │ ├── RAM → temporary working data │ └── SSD → OS, applications, documents, videos
3. Storage Hierarchy
A computer doesn't use only one type of memory/storage.
It uses a hierarchy:
Fastest ↑ ┌──────────────┐ │ CPU Registers│ ├──────────────┤ │ Cache │ ├──────────────┤ │ RAM │ ├──────────────┤ │ SSD │ ├──────────────┤ │ HDD │ ├──────────────┤ │ Backup/Cloud │ └──────────────┘ ↓ Slowest
Generally:
The faster the storage, the more expensive it is per unit of capacity.
4. Primary vs Secondary Storage
Primary Storage
Used directly by the CPU for active processing.
Examples:
- Registers
- Cache
- RAM
Characteristics:
- Very fast
- Limited capacity
- RAM is volatile
- Closely connected to CPU execution
Secondary Storage
Used for long-term data storage.
Examples:
- HDD
- SSD
- USB drive
- Memory card
- Optical disc
Characteristics:
- Larger capacity
- Usually non-volatile
- Slower than RAM
- Used for files and programs
5. Primary vs Secondary Storage
| Feature | Primary Storage | Secondary Storage |
|---|---|---|
| Examples | RAM, cache | SSD, HDD |
| Speed | Very high | Lower |
| Capacity | Smaller | Larger |
| Cost/GB | Higher | Lower |
| Volatility | RAM is volatile | Usually non-volatile |
| CPU access | Direct/very close | Through I/O system |
| Purpose | Active execution | Long-term storage |
6. HDD — Hard Disk Drive
An HDD stores data using magnetic recording.
Basic structure:
HDD │ ├── Platters ├── Spindle ├── Read/Write Heads ├── Actuator └── Controller
Conceptually:
Read/Write Head ↓ ┌───────────┐ / \ | Platter | \ / └───────────┘ ↑ Spindle
7. How HDD Stores Data
Data is magnetically represented on the platter.
The platter contains:
Tracks ↓ Sectors ↓ Data
The head moves to the required track and waits for the required sector.
Therefore HDD performance is affected by:
- seek time
- rotational latency
- transfer time
8. Advantages of HDD
- High capacity
- Low cost per GB
- Good for bulk storage
- Suitable for backups and large archives
9. Disadvantages of HDD
- Mechanical moving parts
- Slower random access
- Noise
- Heat
- Mechanical failure risk
- Sensitive to physical shock compared with SSDs
10. SSD — Solid-State Drive
An SSD stores data using flash memory.
Unlike HDD:
HDD → Mechanical disk + moving head SSD → Flash memory + controller
SSD has no mechanical disk head.
11. SSD Structure
Simplified:
SSD │ ├── NAND Flash ├── Controller ├── Firmware ├── Cache └── Interface
Data is stored in NAND flash memory cells.
12. How SSD Works
Conceptually:
Application ↓ Operating System ↓ SSD Controller ↓ NAND Flash
The controller manages things such as:
- logical-to-physical address mapping
- wear leveling
- garbage collection
- error correction
- bad-block management
13. Advantages of SSD
- Very fast random access
- No moving parts
- Low latency
- Silent
- Lower mechanical failure risk
- Lower power consumption in many scenarios
14. Disadvantages of SSD
- Higher cost per GB than HDD in many markets
- Flash cells have finite write endurance
- Data recovery can be more complicated in some failure scenarios
- Controller failure can make the drive inaccessible
Modern SSDs use sophisticated management to distribute writes and extend usable life.
15. HDD vs SSD
| Feature | HDD | SSD |
|---|---|---|
| Technology | Magnetic | NAND flash |
| Moving parts | Yes | No |
| Random access | Slower | Much faster |
| Noise | Possible | Silent |
| Shock resistance | Lower | Higher |
| Power consumption | Usually higher | Usually lower |
| Cost/GB | Usually cheaper | Usually more expensive |
| Capacity | Very high options | Very high options |
| Seek time | Important | No mechanical seek |
Memory trick
HDD = Head + Disk
SSD = Solid State
16. Flash Storage
Flash memory is a non-volatile semiconductor storage technology.
It is used in:
- SSDs
- USB drives
- SD cards
- microSD cards
- smartphones
- embedded systems
Example:
ESP32 ↓ Flash memory ↓ Firmware + stored data
17. NAND Flash
NAND flash is commonly used for mass storage.
Its hierarchy is conceptually:
NAND Flash ↓ Blocks ↓ Pages ↓ Cells
A simplified representation:
Block ├── Page ├── Page ├── Page └── Page
Reads and writes have different characteristics, and erasing is generally performed at the block level.
18. Flash Memory Cells
Flash cells can store different amounts of information.
Common categories:
SLC
Single-Level Cell
Stores:
1 bit/cell
Fast and durable, but expensive per GB.
MLC
Multi-Level Cell
Typically stores:
2 bits/cell
TLC
Triple-Level Cell
Typically:
3 bits/cell
QLC
Quad-Level Cell
Typically:
4 bits/cell
General trend:
SLC → MLC → TLC → QLC
As bits per cell increase, capacity improves, but performance/endurance characteristics generally become more challenging.
19. USB Flash Drive
A USB flash drive is portable flash-based storage.
Computer ↓ USB ↓ Flash Controller ↓ NAND Flash
Advantages:
- portable
- small
- no moving parts
- easy to connect
Used for:
- file transfer
- bootable installation media
- backups
- temporary storage
20. Memory Cards
Examples:
- SD
- microSD
- CompactFlash
Used in:
- smartphones
- cameras
- Raspberry Pi
- IoT devices
- embedded systems
For example:
ESP32/IoT device ↓ microSD card ↓ Sensor logs
21. Optical Storage
Optical storage uses lasers to read/write information.
Examples:
CD DVD Blu-ray
Conceptually:
Laser ↓ Disc surface ↓ Data
CD
Common capacity:
≈ 700 MB
DVD
Common single-layer capacity:
≈ 4.7 GB
Blu-ray
Common single-layer capacity:
≈ 25 GB
These are approximate standard capacities.
22. Advantages of Optical Storage
- Portable
- Inexpensive for some archival uses
- Can be useful for offline storage
- Not affected by magnetic fields in the same way as magnetic media
23. Disadvantages
- Lower capacity than modern HDDs/SSDs
- Slower
- Optical drives are becoming less common
- Physical discs can be scratched or damaged
24. Magnetic vs Solid-State vs Optical
| Feature | HDD | SSD | Optical |
|---|---|---|---|
| Technology | Magnetic | Flash | Laser/optical |
| Moving parts | Yes | No | Drive has moving mechanism |
| Speed | Medium/slow | Fast | Slow |
| Capacity | High | High | Lower |
| Random access | Slower | Very fast | Slow |
| Portability | Moderate | High | High |
| Common today | Yes | Yes | Less common |
25. Cache
A cache stores frequently or recently used data so it can be accessed faster.
Example:
CPU ↓ Cache ↓ RAM ↓ SSD
If requested data is already in cache:
Request ↓ Cache HIT ↓ Data returned quickly
If not:
Request ↓ Cache MISS ↓ Fetch from slower level
26. Storage Cache
Storage devices can also have cache.
Example:
Application ↓ OS cache ↓ SSD/HDD cache ↓ Storage media
The purpose is to reduce expensive storage operations and improve responsiveness.
27. Buffering
A buffer temporarily holds data during transfer.
Example:
Application ↓ Buffer ↓ Storage device
Suppose the application produces data faster than the storage device can consume it.
The buffer temporarily holds the excess data.
28. Caching vs Buffering
This is an important exam question.
| Cache | Buffer |
|---|---|
| Stores frequently/recently used data | Temporarily holds data during transfer |
| Main goal = faster repeated access | Main goal = handle speed/size mismatch |
| Improves access time | Smooths data transfer |
| Example: disk cache | Example: I/O buffer |
Memory trick
Cache = reuse
Buffer = transfer
29. Storage Interfaces
Storage devices communicate with the computer through interfaces.
Examples:
SATA
Common for:
- SATA HDD
- SATA SSD
SSD/HDD ↓ SATA ↓ Motherboard
NVMe
NVMe is a protocol designed for high-speed non-volatile memory storage, commonly using PCIe.
NVMe SSD ↓ PCIe ↓ CPU/Chipset
NVMe generally provides much lower latency and greater parallelism than legacy SATA/AHCI storage paths.
30. SATA vs NVMe
| Feature | SATA SSD | NVMe SSD |
|---|---|---|
| Common interface | SATA | PCIe |
| Protocol | AHCI/SATA | NVMe |
| Performance | High | Very high |
| Latency | Higher | Lower |
| Bandwidth | Lower | Higher |
| Typical form | 2.5-inch/SATA M.2 | M.2, PCIe cards |
Important:
M.2 is a physical form factor, not automatically NVMe.
An M.2 drive can use SATA or NVMe depending on the device.
31. Storage Capacity Units
Common units:
1 KB ≈ 1,000 bytes 1 MB ≈ 1,000 KB 1 GB ≈ 1,000 MB 1 TB ≈ 1,000 GB
Manufacturers commonly use decimal units.
Operating systems and memory calculations may also use binary units:
1 KiB = 1024 bytes 1 MiB = 1024 KiB 1 GiB = 1024 MiB 1 TiB = 1024 GiB
So:
GB ≠ GiB
This is why a drive marketed as 1 TB may appear somewhat smaller in the OS when displayed using binary-based units.
32. Storage Reliability
Storage management also considers reliability.
Important mechanisms include:
Error correction
Detects/corrects certain data errors.
Bad-block management
Prevents unreliable storage areas from being used normally.
Redundancy
RAID can provide redundancy.
Backup
Creates another copy of important data.
33. RAID
RAID combines multiple drives.
Multiple Drives ↓ RAID ↓ Performance / Redundancy
Important levels:
RAID 0 → Striping RAID 1 → Mirroring RAID 5 → Distributed parity RAID 6 → Dual parity RAID 10 → Mirroring + striping
Remember:
RAID is not a backup.
34. NAS
NAS = Network Attached Storage
It provides file storage over a network.
Example:
PC ─────┐ Laptop ─┼── Network ── NAS Phone ──┘ │ HDD/SSD
Users can access shared files over the network.
Common uses:
- file sharing
- backups
- media storage
- centralized storage
35. SAN
SAN = Storage Area Network
A SAN provides block-level storage over a specialized/high-speed network infrastructure.
Conceptually:
Servers │ ├────── Network ──────┐ │ │ └────────────────── SAN │ Storage
SANs are common in enterprise/data-center environments.
36. NAS vs SAN
| Feature | NAS | SAN |
|---|---|---|
| Storage access | File-level | Block-level |
| Network | IP/network protocols | Specialized storage networking or IP-based technologies |
| Common use | File sharing | Enterprise/server storage |
| User view | Shared files/folders | Disks/blocks/volumes |
| Complexity | Lower | Higher |
Memory trick
NAS = Network file storage
SAN = Storage network
37. Local vs Network Storage
Local storage
Connected directly to the computer:
PC → SSD
Network storage
Accessed through a network:
PC → Network → NAS
38. Storage Virtualization
Storage can be abstracted from the physical disks.
Example:
Physical disks ↓ Storage virtualization ↓ Logical volume ↓ Operating system
The OS/application doesn't necessarily need to know exactly which physical disk contains each block.
39. Logical Volume Management
Linux commonly uses LVM — Logical Volume Manager.
Conceptually:
Physical Disks ↓ Physical Volumes ↓ Volume Group ↓ Logical Volumes ↓ Filesystem
Example:
/dev/sda + /dev/sdb ↓ Volume Group ↓ ┌──────┴──────┐ ↓ ↓ Root LV Data LV
Benefits can include flexible resizing and combining storage resources.
40. Storage Security
Storage management also involves security.
Important mechanisms:
File permissions
Read Write Execute
Encryption
Protects data from unauthorized access.
Examples:
- full-disk encryption
- filesystem/file encryption
Access control
Controls who can access data.
Secure deletion considerations
Simply deleting a file doesn't always mean the underlying data is immediately physically erased.
The exact behavior depends on the filesystem and storage technology.
41. Storage Performance Factors
Storage performance depends on:
Capacity Speed Latency IOPS Bandwidth Queue depth Access pattern Cache Interface
IOPS
Input/Output Operations Per Second
Useful for measuring workloads involving many small I/O operations.
Bandwidth
Amount of data transferred per unit time.
For example:
500 MB/s
42. Latency vs Bandwidth
Latency
How long one operation takes to begin/complete.
Request ↓ Wait ↓ Data
Bandwidth
How much data can be transferred per unit time.
1 second ↓ 500 MB transferred
Memory trick:
Latency = How long you wait
Bandwidth = How much you can transfer
43. IOPS vs Throughput
IOPS
Number of I/O operations per second.
Useful for:
Database Operating system Small random reads/writes
Throughput
Amount of data transferred per second.
Useful for:
Large file transfer Video Backup
Example:
Drive A: 100,000 IOPS Drive B: 500 MB/s throughput
These measure different characteristics.
44. Storage Hierarchy Example
Imagine opening a program:
Program stored on SSD ↓ OS reads program ↓ RAM ↓ CPU Cache ↓ CPU Registers ↓ CPU executes
So data moves upward through the storage/memory hierarchy.
45. Complete Storage Architecture
CPU │ ↓ Registers │ ↓ Cache │ ↓ RAM │ ↓ Storage Controller │ ┌─────────┼──────────┐ ↓ ↓ ↓ SSD HDD USB │ ↓ Filesystem │ ↓ Files
46. Storage Management by the OS
The OS is responsible for coordinating many storage tasks:
Storage Management │ ├── Device detection ├── Partitioning support ├── Filesystem management ├── Free-space management ├── File allocation ├── Disk scheduling ├── Mounting ├── Caching ├── Buffering ├── Swap management ├── Storage protection └── I/O coordination
🧠 Exam Revision
Definition
Storage is the hardware and software infrastructure used to retain data and programs for temporary or long-term use. The operating system manages storage devices, storage allocation, access, caching, protection, and data organization.
Main types
Storage │ ├── Primary │ ├── Registers │ ├── Cache │ └── RAM │ └── Secondary ├── HDD ├── SSD ├── USB ├── Memory Card └── Optical
Important comparisons
HDD
Magnetic + mechanical + cheaper per GB + slower
SSD
Flash + no mechanical head + faster + lower latency
Cache
Stores data for faster reuse
Buffer
Temporarily holds data during transfer
NAS
Network file storage
SAN
Network block storage
RAID
Combines drives for performance and/or redundancy
Latency
Time to access
Bandwidth
Amount transferred per unit time
IOPS
Number of I/O operations per second
🧠 Storage hierarchy trick
Register → Cache → RAM → SSD → HDD → Backup
As you move downward:
Capacity ↑ Cost/GB ↓ Speed ↓ Latency ↑