Unit 4: Memory
MEMORY
Memory is a storage unit of a computer system used to store:
- Data
- Instructions
- Intermediate results
- Final output
It allows the CPU to access information quickly during program execution.
Characteristics of Memory
- Capacity – amount of data it can store
- Access time – time to read/write data
- Cost – price per bit
- Volatility – whether data is lost on power off
Memory Hierarchy
Concept of Memory Hierarchy
Memory hierarchy is an arrangement of different memory types in a system based on:
- Speed
- Cost
- Storage capacity
Goal: To provide the CPU with fast access to data at minimum cost.
Levels of Memory Hierarchy
| Level | Memory Type | Speed | Cost | Capacity |
|---|---|---|---|---|
| 1 | Registers | Very High | Very High | Very Small |
| 2 | Cache Memory | High | High | Small |
| 3 | Main Memory (RAM) | Medium | Medium | Medium |
| 4 | Secondary Memory | Low | Low | Very Large |
Locality of Reference
Memory hierarchy works on:
- Temporal locality – recently used data is likely to be reused
- Spatial locality – nearby memory locations are likely to be accessed
Semiconductor RAM Memories
RAM (Random Access Memory)
RAM is a read/write memory where any location can be accessed in the same amount of time.
Types of Semiconductor RAM
(a) Static RAM (SRAM)
- Uses flip-flops
- No refresh required
- Very fast
- Low density
- Expensive
- Used in cache memory
(b) Dynamic RAM (DRAM)
- Uses capacitors
- Requires periodic refresh
- Slower than SRAM
- High density
- Cheaper
- Used as main memory
SRAM vs DRAM (Important for Exams)
| Feature | SRAM | DRAM |
|---|---|---|
| Speed | Very fast | Slower |
| Refresh | Not required | Required |
| Cost | High | Low |
| Density | Low | High |
| Usage | Cache | Main memory |
Memory Organization
Two-Dimensional (2D) Memory Organization
In 2D memory organization, memory cells are arranged in:
- Rows
- Columns
Components:
- Row decoder
- Column decoder
Working:
- Address is divided into row and column parts
- Row decoder selects a row
- Column decoder selects a column
Advantage:
- Fewer decoder lines
- Efficient for medium-size memories
Two and Half Dimensional (2½D) Memory Organization
In 2½D memory organization, memory is divided into:
- Blocks (or modules)
- Each block has its own 2D structure
Address Division:
- Block selection bits
- Row selection bits
- Column selection bits
Advantages:
- Reduced decoder complexity
- Better scalability
- Used for large memory systems
Comparison: 2D vs 2½D
| Feature | 2D Organization | 2½D Organization |
|---|---|---|
| Structure | Rows & Columns | Blocks + Rows + Columns |
| Decoder complexity | Medium | Low |
| Scalability | Limited | High |
| Usage | Small/medium memory | Large memory |
ROM Memories
ROM (Read Only Memory)
ROM is a non-volatile memory used to store permanent data.
Data is retained even when power is off.
Types of ROM
| Type | Description |
|---|---|
| Mask ROM | Programmed during manufacturing |
| PROM | Programmable only once |
| EPROM | Erased using UV light |
| EEPROM | Electrically erasable |
| Flash ROM | Block-wise erase, faster |
Uses of ROM
- BIOS programs
- Booting instructions
- Firmware in embedded systems
Conclusion (Exam-Ready)
- Memory stores data and instructions required by the CPU.
- Memory hierarchy balances speed, cost, and capacity.
- Semiconductor RAM includes SRAM and DRAM.
- 2D and 2½D memory organizations improve addressing efficiency.
- ROM provides permanent storage for system programs.
CACHE MEMORY
Cache memory is a small, high-speed semiconductor memory placed between:
- CPU and
- Main Memory (RAM)
Purpose of Cache Memory
- Reduce average memory access time
- Improve CPU performance
- Bridge the speed gap between CPU and main memory
Principle Used
Cache memory works on the principle of locality of reference:
- Temporal locality – recently accessed data is likely to be accessed again
- Spatial locality – nearby memory locations are likely to be accessed soon
Cache Design Issues
While designing cache memory, the following important issues are considered:
Cache Size
- Larger cache → higher hit ratio
- But increases cost and access time
Mapping Technique
- Determines how main memory blocks are placed in cache
- Direct, Associative, or Set-Associative
Replacement Policy
-
Decides which block to remove when cache is full
Write Policy
- Write-through
- Write-back
Cache Organization
- Unified cache
- Split cache (Instruction & Data cache)
Cache Performance
Cache Hit and Miss
- Cache Hit: Data found in cache
- Cache Miss: Data not found in cache
Hit Ratio
Miss Penalty
Time required to fetch data from main memory when a miss occurs.
Effective Memory Access Time (EMAT)
This formula is very important for exams.
Cache Address Mapping Techniques
Address mapping defines how a main memory block is mapped to a cache line.
Direct Mapping
- Each memory block maps to only one cache line
- Simple and fast
Address Format:
Advantages:
- Simple hardware
- Fast access
Disadvantages:
-
High conflict misses
Fully Associative Mapping
- A block can be placed in any cache line
- Uses associative memory (CAM)
Address Format:
Advantages:
-
Lowest miss rate
Disadvantages:
- Expensive hardware
- Slower than direct mapping
Set-Associative Mapping
- Cache divided into sets
- Block maps to a specific set but can go to any line within that set
Address Format:
Advantages:
-
Balance between cost and performance
Disadvantages:
-
Slightly complex
Mapping Comparison (Very Important)
| Feature | Direct | Fully Associative | Set-Associative |
|---|---|---|---|
| Hardware cost | Low | High | Medium |
| Speed | Very fast | Slower | Medium |
| Miss rate | High | Low | Medium |
| Complexity | Low | High | Medium |
Cache Replacement Policies
Replacement policy decides which cache block is replaced during a cache miss.
Least Recently Used (LRU)
- Replaces the block not used for the longest time
- Best performance
- High overhead
First In First Out (FIFO)
- Oldest block is replaced
- Simple implementation
- Not always optimal
Random Replacement
- Randomly selects a block
- Easy to implement
- Unpredictable performance
Comparison of Replacement Policies
| Policy | Performance | Complexity |
|---|---|---|
| LRU | Best | High |
| FIFO | Medium | Low |
| Random | Low | Very Low |
Exam-Ready Summary Points
- Cache memory improves CPU speed by reducing memory access time.
- It works on the principle of locality of reference.
- Cache performance is measured using hit ratio and EMAT.
- Mapping techniques decide block placement in cache.
- Replacement policies decide which block to remove.
Frequently Asked Exam Questions
- Define cache memory and explain its working principle.
- Explain cache mapping techniques with diagrams.
- What is hit ratio? Derive EMAT formula.
- Compare direct, associative, and set-associative mapping.
- Explain cache replacement policies
AUXILIARY MEMORIES & VIRTUAL MEMORY
Auxiliary Memory (Secondary Storage)
Meaning of Auxiliary Memory
Auxiliary memory is non-volatile storage used to store large amounts of data permanently.
It is slower than main memory but has very high capacity and low cost per bit.
Examples:
- Magnetic Disk
- Magnetic Tape
- Optical Disk
Magnetic Disk
A magnetic disk stores data on rotating circular platters coated with magnetic material.
Examples: Hard Disk Drive (HDD)
Structure of Magnetic Disk
- Platters – circular disks
- Tracks – concentric circles on a platter
- Sectors – divisions of tracks
- Read/Write Head – accesses data
- Cylinder – set of tracks at same position on all platters
Disk Access Time
Disk access time consists of:
- Seek Time – time to move head to correct track
- Rotational Latency – waiting for sector to reach head
- Transfer Time – time to read/write data
Advantages of Magnetic Disk
- Random access
- Large storage capacity
- Low cost
Disadvantages of Magnetic Disk
- Mechanical parts → slower than SSD
- Prone to physical damage
Magnetic Tape
A magnetic tape is a sequential access storage device where data is stored in a long magnetic strip.
Used mainly for:
- Backup
- Archiving
Characteristics
- Sequential access only
- Very low cost
- High storage capacity
Advantages
- Cheapest storage
- Suitable for large backups
- Long data retention
Disadvantages
- Very slow access
- Not suitable for real-time data access
Optical Disks
Optical disks store data using laser technology.
Examples:
- CD (Compact Disk)
- DVD (Digital Versatile Disk)
- Blu-ray Disk
Types of Optical Disks
| Type | Description |
|---|---|
| CD-ROM | Read only |
| CD-R | Write once |
| CD-RW | Rewritable |
| DVD | Higher capacity |
| Blu-ray | Very high capacity |
Advantages
- Portable
- Durable
- Low cost
Disadvantages
- Slower than hard disk
- Limited rewrite cycles
Comparison of Auxiliary Memories (Important Table)
| Feature | Magnetic Disk | Magnetic Tape | Optical Disk |
|---|---|---|---|
| Access Type | Random | Sequential | Random |
| Speed | Medium | Very Slow | Slow |
| Cost | Low | Very Low | Low |
| Usage | OS, data storage | Backup | Media distribution |
VIRTUAL MEMORY
Virtual memory is a memory management technique that allows execution of programs larger than physical main memory.
It creates an illusion of a large main memory by using secondary storage.
Need for Virtual Memory
- Programs are large
- Physical RAM is limited
- Better memory utilization
- Supports multitasking
Implementation of Virtual Memory
Paging (Most Common Method)
- Main memory divided into frames
- Virtual memory divided into pages
- Page table maps pages to frames
Page Table
-
Stores mapping of virtual pages to physical frames
Contains:
- Frame number
- Valid/Invalid bit
- Protection bits
Page Fault
Occurs when:
-
Required page is not present in main memory
Steps:
- OS detects page fault
- Required page is loaded from disk
- Page table is updated
- Execution resumes
Performance Issues in Virtual Memory
Thrashing
- Excessive page faults
- System spends more time swapping than executing
Page Replacement Algorithms
- FIFO
- LRU
- Optimal (theoretical)
Advantages of Virtual Memory
- Efficient RAM utilization
- Large programs can run
- Improved system performance
Disadvantages of Virtual Memory
- Page fault overhead
- Slower than physical memory
- Complex OS design
Exam-Ready Conclusion
- Auxiliary memory provides permanent storage at low cost.
- Magnetic disks offer random access and are widely used.
- Magnetic tape is best for backup and archiving.
- Optical disks are portable storage media.
- Virtual memory extends main memory using disk storage and paging.
Most Important Exam Questions
- Explain magnetic disk structure and access time.
- Compare magnetic disk, tape, and optical disk.
- Define virtual memory and explain its implementation using paging.
- What is a page fault? Explain its handling