Unit 2
Memory Hierarchy and Storage Devices¶
Memory Hierarchy¶
The memory hierarchy in computer systems is organized to optimize the trade-offs between speed, cost, and capacity. Different memory types are arranged in a pyramid structure, with the fastest and most expensive memory at the top and the slowest but cheapest at the bottom.
Registers¶
Registers are the fastest and smallest memory units in the CPU. They are directly accessible by the processor and store data being processed by the CPU.
General Purpose Registers:
- These registers can be used for any temporary storage of data or instructions.
- Common types include accumulator (ACC), data register (DR), address register (AR), and general-purpose registers like R0, R1, etc.
- Size: Typically 16, 32, or 64 bits depending on the architecture
- Access time: 1 CPU cycle
Special Purpose Registers:
- These registers have dedicated functions in the operation of the CPU.
- Examples include:
- Program Counter (PC): Stores the address of the next instruction to be executed
- Instruction Register (IR): Holds the instruction currently being executed
- Stack Pointer (SP): Points to the top of the stack in memory
- Status Register (FLAGS): Contains status bits indicating the outcome of previous operations
Types of Memory¶
Primary vs Secondary Memory¶
Primary Memory (Main Memory):
- Directly accessible by the CPU
- Volatile memory (loses data when power is off)
- Faster but more expensive than secondary memory
- Examples: RAM, ROM
- Capacity: Typically 4GB to 64GB in modern systems
Secondary Memory (Auxiliary Memory):
- Not directly accessible by the CPU
- Non-volatile memory (retains data when power is off)
- Slower but cheaper than primary memory
- Examples: Hard drives (HDD), solid state drives (SSD), optical disks
- Capacity: Typically 500GB to several TB in modern systems
Volatile vs Non-volatile Memory¶
Volatile Memory:
- Requires constant power to maintain stored data
- Faster access time
- Higher cost per bit
- Examples: SRAM, DRAM,Cache memory
- Used for main memory and cache
Non-volatile Memory:
- Retains data even when power is turned off
- Slower access time
- Lower cost per bit
- Examples: ROM, Flash memory, HDD, SSD
- Used for secondary storage and firmware storage
Semiconductor Memory¶
SRAM (Static RAM):
- Uses flip-flops to store each bit
- Does not need to be refreshed
- Faster than DRAM
- More expensive per bit
- Lower density (takes more space)
- Lower power consumption (not refreshed)
- Used for CPU cache and small memory buffers
DRAM (Dynamic RAM):
- Uses capacitors to store each bit
- Requires constant refreshing
- Slower than SRAM
- Cheaper per bit
- Higher density (takes less space)
- Higher power consumption (due to refreshing)
- Used for main system memory (RAM)
ROM Types:
- Mask ROM: Programmed during manufacturing, cannot be modified
- PROM (Programmable ROM): Can be programmed once by the user
- EPROM (Erasable PROM): Can be erased with UV light and reprogrammed
- EEPROM (Electrically Erasable PROM): Can be erased and reprogrammed electrically
- Flash Memory: A type of EEPROM that can be erased and reprogrammed in blocks
Storage Devices¶
Magnetic Storage Devices¶
Hard Disk Drives (HDD):
- Consists of spinning magnetic platters and read/write heads
- Data is stored magnetically on the platter surfaces
- Access time: Typically 5-10 milliseconds
- Capacity: From 500GB to several TB
- Advantages: Low cost per GB, good capacity
- Disadvantages: Mechanical parts make them slower and less durable than SSDs
Magnetic Tape:
- Sequential access storage medium
- Used for backup and archival purposes
- Capacity: From hundreds of GB to several TB per cartridge
- Advantages: Very low cost per GB, long archival life
- Disadvantages: Very slow access time (sequential only)
Optical Storage Devices¶
CD (Compact Disc):
- Capacity: 700MB
- Types: CD-R (write once), CD-RW (rewritable)
- Access time: ~100-200ms
DVD (Digital Versatile Disc):
- Capacity: 4.7GB (single layer), 8.5GB (dual layer)
- Types: DVD-R, DVD+R, DVD-RW, DVD+RW
- Access time: ~100-150ms
Blu-ray:
- Capacity: 25GB (single layer), 50GB (dual layer)
- Uses blue laser (shorter wavelength than DVD's red laser)
- Higher data density than DVD
- Access time: ~80-100ms
Solid-State Devices¶
Flash Memory:
- Non-volatile memory
- Types:
- NOR Flash: Random access, faster read, used for firmware/code storage
- NAND Flash: Sequential access, higher density, used for USB drives, SSDs
- No moving parts, faster than HDD
- More expensive per GB than HDD
- Limited write cycles (wear leveling extends life)
Solid State Drives (SSD):
- Use NAND flash memory
- No moving parts
- Much faster than HDD (access time ~0.1ms)
- More resistant to physical shock
- Lower power consumption
- Higher cost per GB than HDD
- Used as primary storage in many modern systems
Storage Evaluation Criteria¶
Capacity
- The amount of data that can be stored
- Measured in bytes (KB, MB, GB, TB, PB)
Access Time
- Time taken to read/write a specific location
- Critical for system performance
- Register: 1 CPU cycle
- Cache: 2-10 CPU cycles
- Main Memory: 100-300 CPU cycles
- SSD: ~0.1ms
- HDD: ~5-10ms
Data Transfer Rate
- Amount of data that can be transferred per unit time
- Measured in bits per second (bps) or bytes per second (Bps)
- Factors: interface (SATA, NVMe), rotational speed (HDD), channel width
Cost per Unit of Storage
- Measured in $/GB or $/TB
- Generally decreases over time
- Hierarchy: Registers > Cache > RAM > SSD > HDD > Tape
Reliability
- Mean Time Between Failures (MTBF)
- Resistance to physical shock
- Environmental factors (temperature, humidity)
- Flash memory has write endurance limitations
Power Consumption
- Important for mobile and embedded systems
- SSDs consume less power than HDDs
- Sleep/hibernation modes
Form Factor
- Physical dimensions and interface connections
- Affects compatibility with systems
- Examples: 2.5", 3.5", M.2, PCIe
Latency vs Throughput
- Latency: Time to start transferring data
- Throughput: Amount of data transferred over time
- Different storage systems optimize for different factors
[insert image on memory hierarchy pyramid diagram here]
[insert image on SRAM vs DRAM structure comparison here]
[insert image on SSD vs HDD internal structure comparison here]