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

LevelMemory TypeSpeedCostCapacity
1RegistersVery HighVery HighVery Small
2Cache MemoryHighHighSmall
3Main Memory (RAM)MediumMediumMedium
4Secondary MemoryLowLowVery 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)

FeatureSRAMDRAM
SpeedVery fastSlower
RefreshNot requiredRequired
CostHighLow
DensityLowHigh
UsageCacheMain 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:

  1. Block selection bits
  2. Row selection bits
  3. Column selection bits

Advantages:

  • Reduced decoder complexity
  • Better scalability
  • Used for large memory systems

Comparison: 2D vs 2½D

Feature2D Organization2½D Organization
StructureRows & ColumnsBlocks + Rows + Columns
Decoder complexityMediumLow
ScalabilityLimitedHigh
UsageSmall/medium memoryLarge 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

TypeDescription
Mask ROMProgrammed during manufacturing
PROMProgrammable only once
EPROMErased using UV light
EEPROMElectrically erasable
Flash ROMBlock-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:

  1. Temporal locality – recently accessed data is likely to be accessed again
  2. 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

Hit Ratio=Number of Cache HitsTotal Memory Accesses​

Miss Penalty

Time required to fetch data from main memory when a miss occurs.

Effective Memory Access Time (EMAT)

EMAT=Hit Time+(Miss Rate×Miss Penalty)

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:

| Tag | Line | Word |

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:

| Tag | Word |

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:

| Tag | Set | Word |

Advantages:

  • Balance between cost and performance

Disadvantages:

  • Slightly complex

Mapping Comparison (Very Important)

FeatureDirectFully AssociativeSet-Associative
Hardware costLowHighMedium
SpeedVery fastSlowerMedium
Miss rateHighLowMedium
ComplexityLowHighMedium

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

PolicyPerformanceComplexity
LRUBestHigh
FIFOMediumLow
RandomLowVery 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

  1. Define cache memory and explain its working principle.
  2. Explain cache mapping techniques with diagrams.
  3. What is hit ratio? Derive EMAT formula.
  4. Compare direct, associative, and set-associative mapping.
  5. 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:

  1. Seek Time – time to move head to correct track
  2. Rotational Latency – waiting for sector to reach head
  3. 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

TypeDescription
CD-ROMRead only
CD-RWrite once
CD-RWRewritable
DVDHigher capacity
Blu-rayVery high capacity

Advantages

  • Portable
  • Durable
  • Low cost

Disadvantages

  • Slower than hard disk
  • Limited rewrite cycles

Comparison of Auxiliary Memories (Important Table)

FeatureMagnetic DiskMagnetic TapeOptical Disk
Access TypeRandomSequentialRandom
SpeedMediumVery SlowSlow
CostLowVery LowLow
UsageOS, data storageBackupMedia 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:

  1. OS detects page fault
  2. Required page is loaded from disk
  3. Page table is updated
  4. 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

  1. Explain magnetic disk structure and access time.
  2. Compare magnetic disk, tape, and optical disk.
  3. Define virtual memory and explain its implementation using paging.
  4. What is a page fault? Explain its handling