Computer Organization and Architecture
Comprehensive exam revision notes for BCA-207N Unit 3 (Memory Organization, Hierarchy & Cache Architecture). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.
Computer Organization and Architecture
Memory Organization, Hierarchy & Cache Architecture
Core Definitions & Key Concepts
Illustrate the Memory Hierarchy with respect to speed, cost, and capacity
1 /\ Registers (Fastest, Smallest, Highest Cost/bit)2 / \ Cache Memory (L1, L2, L3 SRAM)3 / \ Main Memory (DRAM)4 / \ Solid-State Drives (NAND Flash)5 /________\ Magnetic Hard Disks / Optical (Slowest, Largest, Lowest Cost)Compare SRAM and DRAM memory cells
| Parameter | Static RAM (SRAM) | Dynamic RAM (DRAM) |
|---|---|---|
| Cell Structure | 6-transistor cross-coupled flip-flop. | 1 transistor and 1 capacitor. |
| Refresh Cycle | No refreshing needed as long as power is on. | Requires periodic electrical charge refreshing every few ms. |
| Speed & Density | Ultra-fast (sub-nanosecond); lower density. | Slower (20–50 ns); extremely high density. |
| Application | CPU L1/L2/L3 Cache memory. | Main System RAM. |
State the Principle of Locality of Reference and its two forms
The Principle of Locality of Reference states that memory references made by a processor over any short execution interval cluster around a localized region of memory.
- Temporal Locality: If a memory location is referenced once, it will likely be referenced again soon (e.g., loop variables, subroutine instructions).
- Spatial Locality: If a memory location is referenced, nearby memory locations will likely be referenced soon (e.g., sequential array iterations).
What is Associative Memory (Content Addressable Memory - CAM)
Associative Memory (CAM) is specialized high-speed memory accessed simultaneously by data content rather than physical numerical address. It compares input search data against all stored words in parallel in a single clock cycle, essential for TLBs and network routing tables.
Write-Through and Write-Back cache write policies
In Write-Through, every cache write immediately updates both the Cache and the Main Memory simultaneously, maintaining consistency at the cost of memory bus write traffic. In Write-Back, data is written only to the Cache block and a Dirty Bit is set to 1. The block is written back to main memory only when it is evicted from cache, dramatically reducing bus writes.
What is a Cache Hit and Cache Miss
A Cache Hit occurs when the processor references memory and the requested word is found in the cache. Hit Ratio ($H$) is the fraction of total references found in cache. A Cache Miss occurs when the requested word is absent in cache, forcing a stall while the missing block is retrieved from slower main memory.
Conceptual & Architectural Analysis
Compare Direct Mapping, Associative Mapping, and Set-Associative Cache Mapping
Cache Mapping Architectures Comparison
Direct Mapping: Fully Associative Mapping: K-Way Set Associative:
Block 'i' maps strictly Block 'i' can map to ANY Block 'i' maps to Set (i mod S)
to Frame (i mod NumLines) available line in cache. which contains 'K' lines.
+-----+-----+-------+ +---------------+-------+ +-----+-----+-------+
| Tag | Line| Offset| | Tag | Offset| | Tag | Set | Offset|
+-----+-----+-------+ +---------------+-------+ +-----+-----+-------+| Feature | Direct Mapping | Fully Associative | Set-Associative Mapping |
|---|---|---|---|
| Placement Rule | Line = Block_Num mod Total_Lines. Only 1 designated cache slot. | Any line can hold any block. | Set = Block_Num mod Num_Sets. Block can go into any of the K lines in that set. |
| Hardware Complexity | Lowest. Single comparator checks Tag at mapped line index. | Highest. N parallel comparators must match Tag across all lines simultaneously. | Balanced. K parallel comparators required per set. |
| Conflict Misses | High. Multiple active blocks competing for the same line evict each other. | Zero conflict misses. Only capacity and compulsory misses. | Minimal conflict misses. |
| Commercial Adoption | Rarely used for primary cache. | Small TLBs. | Standard for modern L1, L2, L3 caches (e.g., 8-way, 16-way). |
Calculate the Average Memory Access Time (AMAT) of a multi-level cache hierarchy
Average Memory Access Time (AMAT) Derivation
Mathematical Formula:
$AMAT = Hit Time_{L1} + (Miss Rate_{L1} × Miss Penalty_{L1})$
For a two-level cache system (L1 and L2): $Miss Penalty_{L1} = Hit Time_{L2} + (Miss Rate_{L2} × Main Memory Access Time)$
$AMAT = T_{L1} + M_{L1} × [T_{L2} + M_{L2} × T_{mem}]$
Example Problem:
Given:
- L1 Hit Time = 1 ns, L1 Miss Rate = 5\% (0.05)
- L2 Hit Time = 5 ns, L2 Miss Rate = 20\% (0.20)
- Main Memory Access Time = 100 ns
$Miss Penalty_{L1} = 5 + (0.20 × 100) = 5 + 20 = 25 ns AMAT = 1 + (0.05 × 25) = 1 + 1.25 = \mathbf{2.25 ns}$ (Demonstrating that the multi-level cache reduces effective memory latency from 100 ns to 2.25 ns!)
Cache Replacement Policies: LRU, FIFO, and Random Replacement
Cache Block Replacement Policies
When a cache miss occurs and the designated cache set/lines are completely full, the replacement logic must evict an existing block:
- Least Recently Used (LRU):
- Evicts the block that has not been referenced for the longest duration in the past.
- Exploits temporal locality. Yields lowest miss rates.
- Hardware Implementation: Requires age bits or an associative stack matrix (K(K-1)/2 bits for K-way set).
- First-In, First-Out (FIFO):
- Evicts the block that has resided in cache for the longest time, regardless of recent usage.
- Simple round-robin counter implementation.
- Can evict heavily used loop headers.
- Random Replacement:
- Evicts a randomly selected block.
- Zero state-tracking hardware overhead. Surprisingly competitive with FIFO under heavy loads.
In-Depth Analysis & Implementation
A digital computer has a main memory of 64K words of 16 bits each and a cache memory of 2K words. The cache block size is 16 words. Analyze and determine the address format (Tag, Index/Line, and Offset/Word bits) for: (a) Direct Mapping, (b) Associative Mapping, and (c) 4-Way Set-Associative Mapping. Draw neat diagrams of each address structure
Detailed Numerical Problem on Cache Address Decoding
Given System Specifications:
- Main Memory Size: 64K words = 64 × 1024 = 65,536 words = 2^{16} words.
- Main Memory Physical Address = 16 bits.
- Cache Memory Size: 2K words = 2048 words = 2^{11} words.
- Block Size (Line Size): 16 words = 2^4 words.
- Word / Offset field ($W$): \log_2(16) = \mathbf{4 bits}.
- Total Blocks in Main Memory: \frac{65,536}{16} = 4096 = 2^{12} blocks.
- Total Lines in Cache: \frac{2048}{16} = 128 = 2^7 lines.
(a) Direct Mapping Address Format
In Direct Mapping:
- Memory Address is split into:
[ Tag | Line Index | Word Offset ] - Total address bits = 16 bits.
- Word Offset = 4 bits.
- Line Index = \log_2(Total Cache Lines) = \log_2(128) = \mathbf{7 bits}.
- Tag bits = Total - (Line + Word) = 16 - (7 + 4) = \mathbf{5 bits}.
Diagram:
+---------------+-------------------+------------------+
| Tag (5) | Line Index (7) | Word Offset (4) |
+---------------+-------------------+------------------+
Bit 15 11 10 4 3 0(b) Fully Associative Mapping Address Format
In Fully Associative Mapping, any block can reside in any line, so there is no line index field.
- Memory Address is split into:
[ Tag | Word Offset ] - Word Offset = 4 bits.
- Tag bits = Total Address - Word Offset = 16 - 4 = \mathbf{12 bits}.
Diagram:
+-----------------------------------+------------------+
| Tag (12) | Word Offset (4) |
+-----------------------------------+------------------+
Bit 15 4 3 0(c) 4-Way Set-Associative Mapping Address Format
In a 4-Way Set-Associative Cache:
- Number of lines per set = K = 4 = 2^2.
- Number of Sets = \frac{Total Cache Lines}{K} = \frac{128}{4} = 32 = 2^5 sets.
- Set Index bits = \log_2(32) = \mathbf{5 bits}.
- Word Offset = 4 bits.
- Tag bits = Total - (Set Index + Word Offset) = 16 - (5 + 4) = \mathbf{7 bits}.
Diagram:
+---------------+-------------------+------------------+
| Tag (7) | Set Index (5) | Word Offset (4) |
+---------------+-------------------+------------------+
Bit 15 9 8 4 3 0Summary Table of Bit Allocations:
| Mapping Technique | Tag Bits | Line / Set Bits | Word Offset Bits | Total Bits |
|---|---|---|---|---|
| Direct Mapping | 5 | 7 (Line) | 4 | 16 |
| Fully Associative | 12 | 0 | 4 | 16 |
| 4-Way Set Associative | 7 | 5 (Set) | 4 | 16 |
Virtual Memory Address Translation using Paging. Describe the hardware implementation involving the Page Table Base Register (PTBR), Translation Lookaside Buffer (TLB), and explain how Protection and Inverted Page Tables function
Virtual Memory Address Translation and TLB Architecture
Virtual memory provides an illusion of an expansive, continuous physical memory space to each process by mapping virtual addresses to non-contiguous physical RAM page frames.
Virtual Address (from CPU)
+--------------------+--------------------+
| Page Number (p) | Page Offset (d) |
+--------------------+--------------------+
| |
v |
+---------------+ |
| TLB Lookup | |
+---------------+ |
/ \ |
TLB Hit TLB Miss |
| | |
| v |
| +---------------+ |
| | Page Table | |
| | (in RAM, PTBR)| |
| +---------------+ |
\ / |
v v |
+-----------------------+ |
| Physical Frame (f) | |
+-----------------------+ |
| |
+----------+----------+
|
v
Physical Address (f, d)Step-by-Step Translation Mechanics:
- CPU Address Generation: CPU generates virtual address split into Virtual Page Number ($p$) and Offset ($d$).
- TLB Associative Search: The MMU simultaneously searches all entries in the Translation Lookaside Buffer (TLB).
- TLB Hit: Physical frame number f is retrieved in <1 ns.
- TLB Miss: MMU reads the entry at
PTBR + p * sizeof(PTE)from RAM. The translation is retrieved, loaded into TLB, and cached for future accesses.
- Physical Address Construction: Physical address is formed by concatenating frame number f with original offset d.
Inverted Page Table (IPT) Architecture:
In 64-bit architectures, standard page tables become unmanageably large (millions of pages). An Inverted Page Table maintains one single entry for each physical frame in RAM rather than per virtual page:
- Entry contains:
[ Process ID (PID) | Virtual Page Number ]. - Lookups require hashing the
(PID, p)pair to obtain the physical frame index. - Saves massive amounts of RAM overhead at the cost of hash collision handling.
Important Exam Points & Quick Revision
Examiner Insights & University Exam Strategy:
- Guaranteed Numerical Problem: Cache address bit partition (Tag, Line/Set, Offset) for Direct, Associative, and Set-Associative mapping is one of the highest probability 10/15-mark questions on BCA-207N exams. Show all log2 powers clearly.
- SRAM vs DRAM: Write a structured comparison table with cell transistor count, speed, and refresh logic.
- AMAT Calculation: Memorize AMAT = Hit Time + Miss Rate × Miss Penalty.
100% left on this page — finishing it closes the gap for Memory Organization, Hierarchy & Cache Architecture.
Memory Organization, Hierarchy & Cache Architecture still counts as a weak topic until you finish this note and answer its questions.
Practise this unitTest Your Understanding
Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.