COMPUTER ORGANIZATION & ARCHITECTURE
106401Module 4: Memory Organization
Q1(b). A direct mapped cache memory with n blocks is nothing but which of the following set associative cache memory originations (i) 0-way set associative (ii) 1-way set associative (iii) 2-way set associative (iv) n-way set associative20232m
Module 4: Memory Organization
View this question on its own page →A direct mapped cache memory with blocks is nothing but which of the following set
associative cache memory originations(i) 0-way set associative
(ii) 1-way set associative
(iii) 2-way set associative
(iv) n-way set associativeWorked SolutionAnswer: (ii) 1-way set associative
Direct-mapped cache is equivalent to 1-way set associative: each block maps to exactly one set (n blocks = n sets, 1 block per set). n-way would be fully associative.
Q1(d). A computer with cache access time of 100\,ns, a main memory access time of 1000\,ns, and a hit ratio of 0.9 produces an average access time of (i) 250\,ns (ii) 200\,ns (iii) 190\,ns (iv) None of these20232m
Module 4: Memory Organization
View this question on its own page →A computer with cache access time of , a main memory access time of , and a hit ratio of produces an average access time of
(i)
(ii)
(iii)
(iv) None of theseWorked SolutionAnswer: (iii) 190 ns (simple); 200 ns hierarchical - both shown
Given: , , ,
Simultaneous access (common textbook for this question):
→ Option (iii)Hierarchical access (cache checked first, then memory on miss):
→ Option (ii)
Most WBUT/MAKAUT PYQs expect (iii) 190 ns. If hierarchical model is assumed, answer is 200 ns.
Q1(e). (e) For converting a virtual address into the physical address, the programs are divided into (i) pages (ii) frames (iii) segments (iv) blocks20222m
Module 4: Memory Organization
View this question on its own page →(e) For converting a virtual address into the physical address, the programs are divided into
(i) pages
(ii) frames
(iii) segments
(iv) blocksWorked SolutionAnswer: (i) pages
Explanation:
- Virtual memory - Programs (logical address space) are divided into fixed-size blocks called pages.
- Physical memory is divided into same-size blocks called frames/page frames.
- Page table maps virtual page number → physical frame number for address translation via MMU.
- Segments are variable-size logical divisions (segmentation), while blocks is generic; for pure paging the division is pages.
Hence programs are divided into pages, physical memory into frames.
Q1(g). Which cache replacement algorithm removes the least recently used block. (i) FIFO (ii) LRU (iii) Random Replacement20242m
Module 4: Memory Organization
View this question on its own page →Which cache replacement algorithm removes the least recently used block.
(i) FIFO
(ii) LRU
(iii) Random ReplacementWorked SolutionAnswer: (ii) LRU
Explanation:
- LRU (Least Recently Used): Evicts block that has not been referenced for longest time - exploits temporal locality; needs timestamp/counter/stack.
- FIFO: Evicts oldest inserted block regardless of recent use.
- Random Replacement: Random victim - simple hardware.
LRU gives best hit rate among three but most complex to implement.
Q1(h). How many 128x8 bit RAMs are required to design 32 kx 32 bit RAM? (i) 512 (ii) 128 (iii) 1024 (iv) 3220232m
Module 4: Memory Organization
View this question on its own page →How many 128x8 bit RAMs are required to design 32 kx 32 bit RAM?
(i) 512
(ii) 128
(iii) 1024
(iv) 32Worked SolutionAnswer: (iii) 1024
Calculation:
Desired: bit
Available: bit- Depth expansion: rows
- Width expansion: chips per row
- Total chips:
Hence 1024 chips required. Same as Q77.
Q1(j). A computer with 32-bit wide data bus uses 1K, X, and 8 static RAM memory chips. What is the smallest memory that this computer has? a) 12K b) 10K c) 8K d) 16K e) 24K20242m
Module 4: Memory Organization
View this question on its own page →A computer with 32-bit wide data bus uses 1K, X, and 8 static RAM memory chips.
What is the smallest memory that this computer has?
a) 12K
b) 10K
c) 8K
d) 16K
e) 24KWorked SolutionAnswer: Theoretically 4K bytes (4 chips) → among given options (c) 8K is closest listed; ideal answer 4K
Explanation:
Chip: bit = 1KB, 8-bit wide.
CPU bus: 32-bit wide → need chips in parallel per word to match width.- One row (4 chips): bit = 4KB
- This is smallest feasible memory (must be multiple of 4 chips to fill bus).
Given options list 12K/10K/8K/16K/24K (no 4K), the smallest listed option that satisfies 4-chip grouping and is ≥4K is c) 8K (2 rows of 4 chips = 8KB). If 4K were listed it would be exact answer. Some textbooks directly answer 4K for this configuration.
Q1(j). (j) The DMA controller has ____ registers. (i) 4 (ii) 2 (iii) 3 (iv) 120222m
Module 4: Memory Organization
View this question on its own page →(j) The DMA controller has ____ registers.
(i) 4
(ii) 2
(iii) 3
(iv) 1Worked SolutionAnswer: (iii) 3
Explanation:
Standard DMA controller (e.g., Intel 8237) has 3 main registers per channel:- Address Register - holds starting address of memory block (source/destination)
- Word Count Register - number of words/bytes to transfer
- Control/Status Register - direction, mode (burst/cycle stealing), enable
Some descriptions count 4 including Data Buffer register, but classic exam answer is 3 registers.
Q1b. (b) How is virtual memory managed using paging and TLB? Explain with suitable example.20197m
Module 4: Memory Organization
View this question on its own page →(b) How is virtual memory managed using paging and TLB? Explain with suitable example.
Worked SolutionVirtual Memory, Paging and TLB
Virtual Memory: Technique that allows execution of program larger than physical main memory by using disk (swap) as extension. CPU generates virtual/logical address, translated by MMU to physical address. Gives programmer illusion of large contiguous memory and provides isolation/protection.
Paging: Virtual and physical memory divided into fixed equal blocks - pages (virtual) and frames (physical), e.g. 4KB. Virtual address = [Virtual Page Number (VPN) | Offset]. Page Table stores mapping VPN -> Frame No. + valid/dirty/protection bits. On page fault (valid=0), OS brings page from disk, updates table.
Example: 32-bit virtual addr, 4KB pages (offset 12 bits). VA =
0x00403ABC-> VPN =0x00403, Offset=0xABC. Page Table[0x00403]= Frame0x00A-> PA=0x00AABC.TLB - Translation Lookaside Buffer: Small, fully-associative high-speed cache of recently used Page Table Entries inside MMU.
- TLB Hit: VPN found in TLB -> frame number returned in ~1 cycle, no memory access.
- TLB Miss: Search page table in memory (or walk), load entry into TLB, may cause page fault.
Effective Access Time: where = hit ratio, = TLB time, = memory time. With , EAT memory speed. TLB greatly reduces translation overhead. Replacement via LRU/random, flush on context switch.
Q1d. What do you mean by locality of reference?20172m
Module 4: Memory Organization
View this question on its own page →What do you mean by locality of reference?
Worked SolutionLocality of Reference:
Principle that memory accesses are clustered, not random — basis for caches and virtual memory.
- Temporal Locality: Recently accessed locations tend to be accessed again soon (e.g., loops, stack variables). → Keep them in cache.
- Spatial Locality: If a location is accessed, nearby locations will be accessed soon (e.g., sequential instructions, arrays). → Fetch blocks/lines.
Due to locality, a small fast cache can achieve hit rate ~90-95% and make average access time close to cache speed despite large, slow main memory.
Q1d. What do you mean by cache coherence problem?20162m
Module 4: Memory Organization
View this question on its own page →What do you mean by cache coherence problem?
Worked SolutionCache Coherence Problem:
Occurs in multiprocessor / multi-cache systems where multiple caches may hold copies of the same memory block.
If one processor (P1) writes to its cached copy of block X, other caches holding X become stale/inconsistent with main memory and with each other. Subsequent reads by other processors would get old data.
- Problem: Ensuring all caches and main memory see a consistent view of shared data after writes.
- Solutions: Snooping protocols (write-invalidate, write-update / write-broadcast), directory-based protocols, MESI state machine.
Without coherence, program correctness is violated.
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q1e. Why is the wait-for-memory-function-completed step needed when reading from or writing to the main memory?20142m
Module 4: Memory Organization
View this question on its own page →Why is the wait-for-memory-function-completed step needed when reading from or writing to the main memory?
Worked SolutionWhy WMFC is needed:
Main memory (DRAM) is asynchronous and slower than CPU. Its access time is variable and longer than one CPU clock period. CPU issues read/write by placing address/data on bus and issues Memory Enable but cannot proceed until memory completes the operation.
WMFC (Wait-for-Memory-Function-Completed) is a control step where CPU waits for MFC (Memory Function Completed) signal from memory controller.
- Ensures data in MDR/MBR is valid before it is used (read) or guarantees write has been latched.
- Synchronizes fast synchronous CPU with slow asynchronous memory.
- Without WMFC, CPU would fetch stale/wrong data or overwrite next operation, causing incorrect execution. Cycle time = access time + recovery time, so next memory operation can start only after WMFC/MFC.
In synchronous control sequence:
MAR ← address; MDR ← data (for write); WMFC; MDR ← valid data (for read).Q1e. How many 128 × 8 RAM chips are needed to provide a memory capacity of 2048 bytes?20162m
Module 4: Memory Organization
View this question on its own page →How many 128 × 8 RAM chips are needed to provide a memory capacity of 2048 bytes?
Worked SolutionAnswer: 16 chips
Each RAM chip = = 128 bytes (128 locations of 8-bit words).
Required capacity = 2048 bytes.
So 16 chips of are needed (arranged as bytes; 8-bit width matches, no width expansion needed — only depth expansion; needs 11 address lines, 7 for chip internal, 4 for chip select via decoder).
Q1e. The average memory access time for a machine with a cache hit rate of 90% where the cache access time is 10 ns and the memory access time is 100 ns is * (i) 55 ns * (ii) 45 ns * (iii) 90 ns * (iv) 19 ns20192m
Module 4: Memory Organization
View this question on its own page →The average memory access time for a machine with a cache hit rate of 90% where the cache access time is 10 ns and the memory access time is 100 ns is
- (i) 55 ns
- (ii) 45 ns
- (iii) 90 ns
- (iv) 19 ns
Worked SolutionAnswer: (iv) 19 ns
Average memory access time (hierarchical access: check cache first, go to memory only on miss):
Given hit rate , ns, ns:
If counting on miss (simultaneous vs hierarchical variants), then ns — but with given options, 19 ns is the expected answer.
Correct option: (iv) 19 ns
Q1f. The minimum time delay between the initiations of two independent memory operations is called * (i) access time * (ii) cycle time * (iii) transfer rate * (iv) latency time20192m
Module 4: Memory Organization
View this question on its own page →The minimum time delay between the initiations of two independent memory operations is called
- (i) access time
- (ii) cycle time
- (iii) transfer rate
- (iv) latency time
Worked SolutionAnswer: (ii) Cycle time
- Access time = time between initiation of read/write operation and completion (data available).
- Cycle time = minimum time delay between initiations of two successive independent memory operations. It = access time + recovery/recharge time needed for memory to recover before next access (e.g., DRAM precharge).
- Always cycle time ≥ access time.
Hence delay between initiations of two independent operations is cycle time. So option (ii) cycle time is correct. Other options: transfer rate = bytes/sec, latency = delay to first bit.
Q1g. What is the importance of cache memory in a computer?20152m
Module 4: Memory Organization
View this question on its own page →What is the importance of cache memory in a computer?
Worked SolutionImportance of Cache Memory (2 Marks)
Cache is a small, very fast SRAM between CPU and main memory that bridges the speed gap between high-speed processor and relatively slow DRAM main memory.
- Speed Gap: CPU cycle time is ~1ns while DRAM access is ~50-100ns. Without cache, CPU would stall waiting for memory. Cache (access ~2-5ns) supplies most needed words at CPU speed.
- Exploits Locality of Reference: Due to temporal locality (recently used data reused soon) and spatial locality (next addresses likely accessed), ~90-95% accesses hit in cache, giving average access time ≈ cache time.
- Result: Improves effective memory access time, increases throughput, reduces memory bandwidth demand. Hence hit ratio and system performance increase significantly despite small size and high cost/bit.
Q1g. Define locality of reference.20142m
Module 4: Memory Organization
View this question on its own page →Define locality of reference.
Worked SolutionLocality of Reference - Defined (2 Marks)
Locality of reference is the empirical observation that memory references tend to cluster in a small region over a short time interval. It is the basis for cache and virtual memory.
Temporal Locality: If a memory location is referenced, it is likely to be referenced again soon. e.g. loops, reusable variables, stack. Keeping recently used blocks in cache yields hits.
Spatial Locality: If a location is referenced, nearby locations are likely to be referenced soon. e.g. sequential instruction fetch, arrays. Fetching a whole block/line exploits this.
Sequential Locality: Special case of spatial — ordered instruction execution.
Due to locality, 90/10 rule holds: 90% of time CPU accesses only 10% of address space, making cache hierarchy very effective.
Q1h. Give the features of a ROM cell.20142m
Module 4: Memory Organization
View this question on its own page →Give the features of a ROM cell.
Worked SolutionROM Cell Features (2 Marks)
ROM (Read Only Memory) cell stores a fixed bit permanently:
Non-volatile: Retains contents without power — used for bootstrap, firmware, microprogram.
Mask-programmed: Contents written at fabrication via contact mask / transistor presence (1 = transistor present, 0 = absent). Not field-writable.
Non-destructive read: Reading does not erase cell; access via address decoder → word line → bit line sense.
High density, low cost/bit for large volumes; slower write-once but fast read comparable to RAM.
Variants: PROM (fusible link, OTP), EPROM (floating gate, UV erase), EEPROM/Flash (electrically erasable) retain ROM cell principle but allow reprogramming.
Single ROM cell = 1 transistor + contact/via; array is OR plane of word lines.
Q1i. Define hit ratio and explain its significance.20162m
Module 4: Memory Organization
View this question on its own page →Define hit ratio and explain its significance.
Worked SolutionDefinition:
Where hit = data found in faster memory (Cache), miss = data not found and must be fetched from lower level (Main memory).
Hit ratio is usually expressed for cache: , also applicable to TLB, etc.
Significance - AMAT (Average Memory Access Time):
The effective access time depends critically on hit ratio:
or for hierarchical memory:
- High ( 0.9-0.99 due to locality of reference) → → system performs near cache speed, despite large cheap main memory.
- Low → AMAT → approaches main memory time, cache is ineffective and penalty dominates.
- Used to evaluate/design cache: organization, block size, associativity, replacement policy all aim to maximize . Helps in deciding cache size vs. cost trade-off and in calculating effective CPU stall cycles due to memory.
Example: , , → vs without cache.
Q1j. In cache memory, FIFO and LRU are examples of: (i) Mapping techniques (ii) Addressing techniques (iii) Replacement algorithms (iv) Write policies20252m
Module 4: Memory Organization
View this question on its own page →In cache memory, FIFO and LRU are examples of:
(i) Mapping techniques
(ii) Addressing techniques
(iii) Replacement algorithms
(iv) Write policiesWorked SolutionAnswer: (iii) Replacement algorithms
Explanation:
In cache mapping (especially set-associative and fully-associative), a miss with no empty block requires evicting an existing block. The policy that decides which block to evict is the replacement algorithm.- FIFO (First-In First-Out): Evicts the block that has been in cache longest (oldest load), using a queue per set. Simple to implement, but not always efficient (does not consider locality).
- LRU (Least Recently Used): Evicts the block least recently accessed, exploiting temporal locality. Most effective general policy; approximates optimal. Implemented via counters/linked list or -way LRU bits. Higher hardware overhead.
Why not other options:
- (i) Mapping techniques: Direct, Associative, Set-Associative - decide where a block can be placed.
- (ii) Addressing techniques: Way of forming addresses.
- (iv) Write policies: Write-through / Write-back (and Write-allocate) - handle consistency between cache and main memory on writes, not eviction.
Hence FIFO and LRU belong to replacement policy class; choice directly affects miss rate and hit ratio.
Q3. (3). Consider a hypothetical 32-bit microprocessor having 32-bit instructions composed of two fields—the first byte contains the opcode and the remainder the immediate operand or an operand address. (a) What is the maximum directly addressable memory capacity (in bytes)? (b) Discuss the impact on the system speed if the microprocessor bus has— i) a 32-bit local address bus and a 16-bit local data bus, or ii) a 16-bit local address bus and a 16-bit local data bus. \(c\) How many bits are needed for the program counter and the instruction register?202214m
Module 4: Memory Organization
View this question on its own page →(3). Consider a hypothetical 32-bit microprocessor having 32-bit instructions composed of two fields—the first byte contains the opcode and the remainder the immediate operand or an operand address.
(a) What is the maximum directly addressable memory capacity (in bytes)?
(b) Discuss the impact on the system speed if the microprocessor bus has—
i) a 32-bit local address bus and a 16-bit local data bus, or
ii) a 16-bit local address bus and a 16-bit local data bus.
(c) How many bits are needed for the program counter and the instruction register?Worked SolutionHypothetical: Instruction = 32 bits = 8 bits opcode + 24 bits address/immediate.
(a) Maximum Directly Addressable Memory Capacity
Direct field = bits.
If byte-addressable: bytes B MB.
If word-addressable (32-bit word =4B): words B MB, i.e. words.
Note: If microprocessor internally has full 32-bit address bus, theoretical max = B GB, but with given format without indirect/indexing you can only encode 24-bit direct address only MB directly without using indirect or paging.
(b) Impact of Bus Width on Speed
Assume memory and CPU are 32-bit, but buses narrower:
i) 32-bit address bus, 16-bit data bus
- Address bus 32-bit can address full GB.
- Data bus 16-bit each 32-bit instruction or operand needs 2 bus cycles to fetch/transfer (16 bits per cycle).
- e.g. Instruction fetch: vs with 32-bit data bus.
- Data read/write of 32-bit word also 2 cycles. Bus bandwidth halved: bits/cycle vs .
- Needs two memory accesses, causes wait states, effective CPI increases.
- Still functionally correct, but speed roughly ~50% for memory-intensive code + extra control logic (byte assembly, multiplexing).
ii) 16-bit address bus, 16-bit data bus
- Address 16-bit directly addressable = KB only! Massive limitation.
- To access beyond 64KB need banking, segment registers, page registers, or multiplexed address (like 8086 with 20-bit via segment:offset) – adds software/hardware overhead and slowdown.
- Cannot use full 32-bit address field; higher bits must be latched in two cycles (address multiplexing) or ignored.
- Data 16-bit same 2-cycle fetch as case (i).
- Overall: Much slower than (i) + severely limited memory. Requires extra bus cycles to send full 32-bit address (send low 16 then high 16) if attempting to address 4GB, effectively 2 address cycles + 2 data cycles per access. System speed degraded by and programmability restricted.
Summary: Widening address bus increases address space; widening data bus increases throughput. Halving data bus doubles memory cycles. Halving address bus collapses address space.
(c) Bits needed for PC and IR
- Instruction Register (IR): Must hold full instruction bits (8 opcode +24 operand). So bits.
- Program Counter (PC): Must hold address of next instruction.
- If holding direct field only: bits (to address MB).
- If holding full memory address (32-bit address bus): bits to address full GB, even though instruction can only encode 24 bits directly (rest via indirect).
- Practical design: bits, bits. For byte-addressable with word-aligned instructions (4B), PC increments by 4.
Exam answer: bits, bits minimum ( bits for full 4GB system).
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q3. Explain in detail the hierarchical memory structure with a neat and labelled diagram.201514m
Module 4: Memory Organization
View this question on its own page →Explain in detail the hierarchical memory structure with a neat and labelled diagram.
Worked SolutionHierarchical Memory Structure
Memory is organized as a pyramid/hierarchy based on trade-off between speed - cost - capacity - access time. Faster memory per bit is costlier and smaller.
↑ Speed, Cost/bit | Capacity ↓ +-----------------+ | CPU Registers | < 1 ns, <1KB, fastest, costliest +-----------------+ | Cache | L1: 2-5 ns, 32-64KB | L1 | L2 | L3 | L2: 5-10 ns, 256KB-8MB SRAM +-----------------+ | Main Memory | 50-100 ns, 4-32 GB, DRAM | (Primary) | +-----------------+ | Secondary | 5-10 ms, 256GB-4TB | SSD / HDD | +-----------------+ | Tertiary / | sec-min, TB-PB, Optical Tape | Off-line | Archival, slowest, cheapest +-----------------+ ↓ Slower, Cheaper, LargerLevels in Detail
1. Registers (Top)
- Inside CPU, <32-64 words, flip-flops, 0.5-1 ns, directly accessed by ALU.
2. Cache Memory (SRAM)
- Between CPU and RAM. Holds copies of frequently used blocks (locality of reference).
- L1 split I/D, L2 unified, L3 shared. Hit ratio ~ 90-95%. Block size 32-128B.
- Managed by hardware.
3. Main Memory (DRAM)
- Primary memory, volatile, 4-32 GB. Byte-addressable. Managed by OS + MMU.
4. Secondary (Magnetic/Flash)
- Non-volatile, virtual memory backing store, page file on SSD/HDD.
5. Tertiary/Offline
- Tape libraries, optical jukebox for backup.
Key Principles
- Inclusion: Data at level is subset/copy of level (Cache contains copy of RAM block).
- Locality: Temporal (recently used reused) & Spatial (neighbors used) → hierarchy works.
- Access time: where is hit rate.
- Cost:
Advantages: Gives illusion of large, cheap memory with speed near registers; transparent to programmer via memory management; exploits locality.
Modern example PC: Registers ~1KB, L1 64KB, L2 512KB, L3 8MB, RAM 16GB, SSD 1TB, HDD/Cloud TB.
Q3. Explain the concept of virtual memory with the help of a diagram. Explain how virtual address is mapped to actual physical address.201714m
Module 4: Memory Organization
View this question on its own page →Explain the concept of virtual memory with the help of a diagram. Explain how virtual address is mapped to actual physical address.
Worked SolutionVirtual Memory Concept
Virtual memory is a memory management technique that gives program illusion of large contiguous main memory (e.g. GB) while physically only part resides in RAM; remainder kept on secondary storage (disk). Address generated by CPU (virtual/logical) is translated to physical via MMU.
CPU generates MMU + Page Table + TLB Main Memory / Disk Virtual Address -----> Translation -----> Physical Address ---> RAM (if present) 32-bit VPN -> PFN 32-bit else Page Fault -> Disk- Virtual address space Physical address space (e.g. virtual vs physical).
- Transparent to programmer, allows multiprogramming, protection, demand paging.
- Uses locality – only active pages kept in RAM.
Diagram: Paged Virtual Memory Mapping
Virtual Address (32b) +----------------------+------------------+ | Virtual Page Number | Page Offset | | VPN (20b) | OFFSET (12b) | -> 4KB pages +-----------+----------+-----+------------+ | | v | +--------------+ | | Page Table | TLB | | (in RAM) | cache | | VPN -> PFN | | +------+-------+ | | | v v Physical Address (32b) +----------------------+------------------+ | Physical Frame Number| Offset | | PFN (20b) | (12b same) | +----------------------+------------------+ RAM: [Frame 0][Frame 1]...[Frame N] Disk: swap space with all pagesVirtual to Physical Mapping Steps (Paging)
Assume page size KB B offset bits, VPN bits for -bit virtual.
- CPU generates virtual address .
- MMU looks up TLB (Translation Lookaside Buffer) – cache of page table.
- TLB hit: get PFN immediately.
- TLB miss: access page table in RAM (pointed by Page Table Base Register - PTBR). May be multi-level (e.g. 2-level for 32-bit).
- Page Table Entry (PTE) contains: PFN, valid bit, dirty, protection (R/W/X), referenced.
- If valid=1: (concatenation).
- If valid=0: Page Fault → trap to OS. OS loads required page from disk to free frame (using replacement e.g. LRU), updates PTE, restarts instruction.
- Physical address sent to cache/memory.
Example: , page KB VPN=, offset=; page table maps VPN .
Segmentation + Paging: Sometimes VA = segment + offset; segment table → page table. But pure paging described above is most common (x86, ARM).
Advantages: Large logical space, protection/isolation, sharing, efficient multiprogramming, demand loading.
Overhead: Translation time (mitigated by TLB hit), page fault handling, fragmentation (internal).
Q3(a). A 4-way set associative cache memory unit with a capacity of 16 KB is built using a block size of 8 words. The word length is 32 bits. The size of the physical address space is 4 GB. Find the number of bits for TAG, SET, and WORD fields in the address generated by CPU.20237m
Module 4: Memory Organization
View this question on its own page →A 4-way set associative cache memory unit with a capacity of 16 KB is built using a block size of 8 words. The word length is 32 bits. The size of the physical address space is 4 GB. Find the number of bits for TAG, SET, and WORD fields in the address generated by CPU.
Worked SolutionGiven
- Cache size KB B B
- Associativity (4-way set associative)
- Block size = words, Word = bits B
Block = B B - Physical address space GB B Physical address bits
Calculations
1. Number of blocks in cache:
blocks2. Number of sets:
sets
SET field bits3. WORD / Offset field:
Block = B. Byte offset within block = bits.
This bits comprises:- Word offset within block: bits (select 1 of 8 words)
- Byte offset within word: bits (select 1 of 4 bytes)
If address is word-addressable, WORD field = bits.
If byte-addressable (standard), combined offset = bits.Common naming in question: WORD field = bits (or split ).
4. TAG field:
- Byte-addressable: bits
- Word-addressable with byte split: bits same.
Answer
Physical Address (32 bits) +-----------+---------+---------------+ | TAG 20b | SET 7b | WORD/OFFSET 5b| | | | (3b word+2b byte)| +-----------+---------+---------------+- TAG = 20 bits
- SET = 7 bits
- WORD/Offset = 5 bits (3 bits word + 2 bits byte)
If counting WORD only (word index): WORD=3 bits, BYTE=2 bits, TAG=20, SET=7.
Check: .
Alternative: If cache size given as KB words (unlikely), then sets SET=9, TAG=18. But standard is bytes → answer above.
Q3(b). How is the virtual address mapped into physical address? What are the different methods of writing into cache?202314m
Module 4: Memory Organization
View this question on its own page →How is the virtual address mapped into physical address? What are the different methods of writing into cache?
Worked SolutionA) Virtual address → Physical address mapping (Paging)
Virtual address generated by CPU is not real RAM address. MMU translates via Page Table + TLB.
Assume bits, page KB B offset b, VPN b.
VA (32b): [ VPN 20b | Offset 12b ] | v +-------------------+ | TLB (cache) |---- hit ----> PFN | VPN -> PFN | +---------+---------+ | miss v Page Table in RAM (PTBR points) PTE: [ PFN | valid | prot | dirty | ref ] | v PA (32b): [ PFN 20b | Offset 12b ] (concatenation)Steps:
- Split VA into VPN + offset.
- Search TLB ( ~64-512 entries, associative). Hit → PFN in 1 cycle.
- Miss → hardware walks page table (often 2-level: Dir + Page table) in memory; may fault.
- If PTE valid=1 → ; check protection.
- If valid=0 → Page fault → OS loads page from disk to frame, updates PTE, restarts.
- TLB updated.
Segmentation variant: → segment table → page table. But paging alone is core.
B) Cache Write Methods
When CPU writes, cache and main memory can become incoherent. Policies:
1. Write-Through
- Write to both cache and main memory simultaneously.
- Simple, coherent, but every write goes to bus → high traffic, slow.
- Usually with write buffer to hide latency.
- On read miss, block fetched.
CPU Write → Cache + Memory (together)2. Write-Back (Copy-Back)
- Write only to cache; set Dirty bit per block. Memory updated only on eviction of dirty block.
- Reduces bus traffic (many writes coalesced). Faster.
- Needs dirty bit + extra control; memory stale until write-back.
CPU Write → Cache (dirty=1) ---- later on replace ---> Memory3. Allocation policy on Write Miss
- Write-Allocate (Fetch on Write): On write miss, load block to cache then write (common with write-back).
- No-Write-Allocate (Write-Around): On write miss, write directly to memory, not loading to cache. Common with write-through to avoid polluting cache with write-only data.
Typical combos:
- Write-Through + No-Write-Allocate
- Write-Back + Write-Allocate (most performant, used in L1/L2)
Comparison:
Property Write-Through Write-Back Memory update Immediate Deferred (on evict) Bus traffic High Low Dirty bit No Yes Speed Slower Faster Coherence Simple Complex (need snooping) Example: -way cache: Write hit in write-back sets dirty; on replacement if dirty=1, 32B block written back to RAM before loading new block.
Q4. What is swapping and how is it useful in memory management?201514m
Module 4: Memory Organization
View this question on its own page →What is swapping and how is it useful in memory management?
Worked SolutionSwapping and Use in Memory Management
Definition
Swapping is moving a process (or part) temporarily out of main memory (RAM) to secondary storage (backing store / swap space on disk) and bringing it back later for execution. Introduced for multiprogramming when RAM insufficient.
Swap Out: RAM --> Disk; Swap In: Disk --> RAM. Managed by medium-term scheduler (swapper) and dispatcher.
How Swapping Works
- System keeps
Ready Queueof processes in memory andSwap Devicequeue on disk. - When memory pressure high or process blocked (e.g. I/O wait) and higher priority process arrives, dispatcher selects victim (e.g. lowest priority, sleeping).
- Victim's entire address space (or at least resident pages) is copied to swap file, its PCB updated (state = swapped, location = disk), frames freed.
- Later when memory free or process becomes ready, swapper selects swapped process, finds contiguous / non-contiguous free frames, loads it back, possibly at different physical address (requires relocation via base-limit registers or paging).
Time = swap size / transfer rate. E.g. 10 MB process, disk 20 MB/s => 0.5s out +0.5s in =1s overhead -> swapping is expensive, attempted only when needed.
Types
- Whole process swapping (old UNIX, embedded) - simple but costly.
- Page swapping / paging (modern VM) - swap only pages/frames, not whole process.
- Roll in / Roll out for priority scheduling.
Usefulness / Advantages
- Degree of Multiprogramming: Allows more processes than fits in RAM to co-exist by multiplexing memory over time, increasing CPU utilization.
- Handles Insufficient Memory: Large process (>RAM) can still run by swapping parts; avoids need for all processes to fit simultaneously.
- Compaction: Swapping out creates holes, allows memory compaction to reduce external fragmentation (combine free blocks) and allocate contiguous memory.
- Priority Scheduling: High priority process swapped in quickly by swapping out low priority.
- I/O Idle Utilization: Blocked process swapped out so its RAM used by ready processes.
- Foundation for Virtual Memory: Modern demand paging is refined swapping per page with lazy loading.
Disadvantages / Considerations
- Swap time overhead and disk I/O bottleneck; double transfer.
- Need for relocation hardware.
- Not suitable for real-time if swap time unpredictable.
- Thrashing if swapped too frequently.
- Requires swap space reservation on disk.
Swapping vs Paging
Swapping Paging (demand) Whole process moved Only required pages moved Contiguous allocation needed Non-contiguous frames ok High overhead Lower per-fault overhead Effective only if combined with compaction and medium-term scheduling; modern OS uses swapping + virtual memory so that
Total Logical Memory >> Physical RAM.Diagram:
Main Memory Disk (Swap Space) [ P1 ][hole][ P2 ] swap out P2 --> [P2 image] [ P1 ][ P3 ][hole] <-- swap in P4 [P4 image][P2]Free frames consolidated after swap.
- System keeps
Q4. What is associative memory? Explain with the help of a block diagram. Also mention the situation in which associative memory can be effectively utilized.201614m
Module 4: Memory Organization
View this question on its own page →What is associative memory? Explain with the help of a block diagram. Also mention the situation in which associative memory can be effectively utilized.
Worked SolutionAssociative Memory (Content Addressable Memory - CAM)
Definition: Memory accessed by content (data) rather than by address. CPU supplies a search word (key); memory simultaneously compares it with all stored words in parallel and marks those that match. Access time is constant irrespective of location. Opposite of Random Access Memory (RAM) where .
Also called Associative Storage / Content Addressable Memory.
Block Diagram
+-----------------------------+ Search Word (Argument) -->| Argument Register (A) | (key + mask) | Key Register (K) Mask (M) | +-------------+---------------+ | (unmasked bits) v +-----------------------------+ | Associative Memory Array | Word0: bit0..bit n + Match logic | Word1 } each with | Word1: comparator (XNOR per bit) | ... } comparison logic | ... + AND of bits | Wordm } | +-------------+---------------+ | Match lines Mi (Mi=1 if word i matches A on K=1 bits) v +-----------------------------+ | Encoder / Priority or | | Match Register + Selector |----> Matched word(s) out +-----------------------------+- Argument Register A: holds search key.
- Key Register K: 1 means compare that bit, 0 = don't care (maskable).
- Mask Register M (optional): disables masked bits.
- Match Logic per word: =1 only if all unmasked bits equal.
- Output is either first matching word (priority encoder) or all matches flagged.
Operation: Load and , assert search, all words compare in parallel (one clock), vector produced, encoder outputs address/data of matched word. Write modifies matched word(s).
Example: 4 words 1010, 1100, 1011, 0010; search , (don't care LSB) => matches word0 (1010) and word2 (1011).
Cost & Characteristics
- Fast search but hardware heavy: comparator per bit per word => XNOR gates. Expensive, power hungry, so used small.
- Word size typically 16-64 bits, capacity to words.
Effective Utilization
Cache Memory / TLB (Translation Lookaside Buffer): Most important use. Fully associative cache / TLB stores block tags; CPU searches tag in parallel to find hit/miss without set indexing. E.g. TLB maps virtual page -> physical frame: associative lookup of VPN yields PPN in one cycle.
Virtual Memory Page Table Cache: Hardware search of page table.
Database / Pattern Matching: Search records by field (e.g. find all employees with age=30) without scanning.
Networking: Router's forwarding table, packet classification, firewall ACLs, Ethernet switch MAC lookup, IP longest prefix match -> ternary CAM (TCAM) with don't-care.
AI / Fault tolerance: Associative recall, spare memory remapping.
In COA syllabus: used to implement fully associative cache and TLB where hit time must be minimal; otherwise direct-mapped is cheaper. Hybrid set-associative + CAM for tags is practical trade-off.
Q4(a). Explain different cache replacement algorithms used in memory management.20247m
Module 4: Memory Organization
View this question on its own page →Explain different cache replacement algorithms used in memory management.
Worked SolutionCache Replacement Algorithms
When a cache miss occurs in associative / set-associative cache and set is full, one line must be evicted. Direct-mapped needs no choice. Algorithm balances hit rate vs hardware cost.
1. Least Recently Used (LRU)
Evict the line not used for longest time (least recent). Exploits temporal locality.
Implementation: Per set maintain recency stack / counters. For 2-way, single bit per set; for -way, states or counters, or pseudo-LRU tree.
Pros: Best hit rate, approximates optimal. Cons: bits, complex for large (e.g. 8-way needs 3 bits per line).2. First-In First-Out (FIFO) / Round-Robin
Evict oldest inserted line (first loaded). No regard to reuse.
Implementation: Circular pointer per set; increment on insertion.
Pros: Very simple, bits per set. Cons: May evict hot line that was loaded early but still frequent (Belady anomaly in paging).3. Least Frequently Used (LFU)
Evict line with fewest hits since insertion. Keeps hot lines.
Implementation: Counter per line, increment on hit; on replacement choose min counter.
Pros: Good for skewed access. Cons: Counters saturate, stale history; hot line pollutes after phase change; extra storage.4. Random Replacement
Pick victim uniformly at random (LFSR).
Pros: Zero bookkeeping, no pathological worst case, surprisingly competitive; used in ARM Cortex, many LLCs.
Cons: Slightly lower hit rate than LRU (~2-5%) but saves power/area.5. Optimal (Belady's / MIN) - Theoretical
Evict line whose next use is furthest in future (requires future knowledge). Gives minimum misses, used only as offline benchmark to evaluate others. Not implementable.
6. Others
- Not Most Recently Used (NMRU): Opposite of LRU, protect MRU; simpler than LRU.
- Not Recently Used (NRU) / Clock: One reference bit per line, clock hand clears bits; evict first with .
- Pseudo-LRU (PLRU) Tree: Binary tree of bits per set, approximates LRU with bits vs .
Algorithm Hit rate Hardware Where used LRU High High L1/L2 small associativity PLRU Near LRU Medium Intel L2/L3 FIFO Medium Low Simple caches Random Medium Minimal LLC, ARM LFU Workload dep High Not common in cache Optimal Max (bound) N/A Analysis Example: 2-way set with lines A,B. Access sequence A B A C.
LRU: After A B A, LRU=B, so C replaces B.
FIFO: After A B A, FIFO=A (oldest), so C replaces A -> one extra miss vs LRU.
Random: 50% chance.Modern caches: Pseudo-LRU or Tree-LRU for 4-16 way, Random for large LLC to save power; inclusion of dirty bit may bias to evict clean line first to avoid write-back.
Q4(a). A set-associative cache has a block size of four 16-bit words and a set size of 2. The cache can accommodate a total of 4096 words. The main memory size that is cacheable is 64K 32 bits. Design the cache structure and show how the processor’s addresses are interpreted.20227m
Module 4: Memory Organization
View this question on its own page →A set-associative cache has a block size of four 16-bit words and a set size of 2. The cache can accommodate a total of 4096 words. The main memory size that is cacheable is 64K 32 bits. Design the cache structure and show how the processor’s addresses are interpreted.
Worked SolutionSet-Associative Cache Design (Numerical)
Given: Block = -bit words bits bytes
Cache capacity words bit bits bytes
Set size (2-way set-associative)
Cacheable main memory bits bytes KB1. Number of Blocks & Sets
If normalized to 32-bit CPU word: block bits offset bit. Add byte offset bit if byte-addressed.2. Address Interpretation
Main memory bits needs bits for 32-bit word address (). Equivalent bits needs bits for 16-bit word address.
Case A - 16-bit word address (most exam-expected):
Total 17 bits (- for )17-bit word address: | Tag (6) | Set index (9) | Word (2) | 16-11 10-2 1-0If CPU byte-addressed: add bit byte offset inside 16-bit word:
Tag(6) | Set(9) | Word(2) | Byte(1)=18 bits total for KB.Case B - 32-bit word address (normalized):
Total bits, block words16-bit address: | Tag (6) | Set (9) | Block offset (1) | 15-10 9-1 0With byte offset:
Tag(6)|Set(9)|Word(1)|Byte(2)=18 bits ( because 32-bit =4 bytes).3. Cache Structure Design
- Organization: sets lines/set lines.
- Each line:
Valid(1) + Dirty(1) + Tag(6) + Data(64 bits = 4×16 bits). Optionally LRU bit per set (1 bit for 2-way). - Data RAM: bytes, divided into blocks of 8 bytes.
- Tag RAM: bits (or ).
- Size: Total tag storage bits.
CPU Address (17-bit word) ---> [Tag 6] [Set 9] [W 2] | | | +-------+ +-----+ +----+ | | | word mux 4:1 Tag compare (×2) --> set decoder 512 --> selected set's 2 tags | HIT if tag match & Valid=1 v Data out (selected 16-bit word or 32-bit word)Operation: Set field selects one of 512 sets (both ways read in parallel); Tag field compared associatively with 2 tags in set; if match, Word offset selects one of 4 words in block (or 1 of 2×32-bit words). Replacement uses LRU per set.
For exam diagram show set decoder, two comparators, MUX and valid/LRU bits. Numbers: 512 sets, 2 lines/set, 8 bytes/block, 9+2+6 split.
Check: Cache ratio .
Q4(b). Discuss the different mapping techniques used in cache memories and their relative merits and demerits.20237m
Module 4: Memory Organization
View this question on its own page →Discuss the different mapping techniques used in cache memories and their relative merits and demerits.
Worked SolutionCache Mapping Techniques
Cache maps main memory blocks to cache lines. For memory address: Tag | Line/Set Index | Word/Offset. Three techniques:
1. Direct Mapping
- Rule: Each memory block maps to exactly one cache line:
Line = j mod (number_of_lines) - Address:
Tag | Line | Word(e.g., 12-bit tag, 8-bit line, 6-bit word for 64-byte block) - Hardware: One comparator per access, simple.
- Pros: Simple, cheap, fast hit time (one tag compare).
- Cons: Conflict misses high - if two blocks map to same line they thrash (even if other lines empty). No flexibility. Worst hit ratio.
- Use: Low-cost caches.
2. Fully Associative Mapping
- Rule: Any memory block can go to any cache line. No index field.
- Address:
Tag | Wordonly. Cache stores Tag per line. - Hardware: CAM - all tags compared in parallel (content-addressable memory) + valid bit. Replacement algorithm needed (LRU, FIFO, Random).
- Pros: Most flexible, lowest conflict misses - best hit ratio for given size. No thrashing.
- Cons: Expensive (parallel comparators for every line), slow for large cache (many comparators, high power). Replacement logic complex. Suitable only for small caches (e.g., TLB).
- Use: Small fully-associative TLB, victim caches.
3. Set-Associative Mapping (k-way)
- Compromise between 1 and 2. Cache divided into sets, each set has lines.
Set = j mod (number_of_sets). Block can go to any of lines within set. - Address:
Tag | Set | Word - Examples: 2-way, 4-way, 8-way. If -> Direct, if -> Fully associative.
- Hardware: comparators per set (parallel within set), plus set decode.
- Pros: Good balance - reduces conflict misses greatly (e.g., 4-way removes most thrashing) with modest hardware cost. Most used in modern CPUs (L1: 4-8 way, L2/L3: 8-16 way).
- Cons: Slightly slower than direct (k compares + mux), needs replacement within set (LRU approx).
- Intel Example: 32KB 8-way L1, 1MB 16-way LLC.
Comparison Summary
Technique Lines per block Comparators Hit time Miss rate Cost Direct 1 1 Fastest Highest Lowest 2/4-way Set k k Medium Medium-Low Medium Fully Associative All All lines Slow (large) Lowest Highest Other merits/demerits:
- Capacity vs Conflict vs Compulsory misses: Direct suffers conflict; Fully associative only compulsory+capacity; Set-associative reduces conflict sharply even 2-way improves miss rate ~30-40%.
- Replacement: Direct - no choice; Associative/Set - need LRU.
- Victim Cache / Pseudo-associative: Extra small fully-associative buffer for direct-mapped conflict blocks.
Modern processors use Set-Associative (typically 4-16 way) as sweet spot; TLBs use Fully-Associative; cheap microcontrollers may use Direct-mapped.
- Rule: Each memory block maps to exactly one cache line:
Q4b. Give an integrated diagram showing the TLB and cache operations for a logical/virtual address generated by a processor.20197m
Module 4: Memory Organization
View this question on its own page →Give an integrated diagram showing the TLB and cache operations for a logical/virtual address generated by a processor.
Worked SolutionTLB and Cache Operations for Virtual Address
Virtual (Logical) address from CPU is translated to Physical address via TLB + Page Table, then Physical address accesses Cache + Main Memory.
Address Split Example (32-bit VA, 4KB pages, 32KB 4-way cache 64B blocks)
- VA:
Virtual Page Number (VPN) | Page Offset (12 bits)(20+12 for 4KB) - PA:
Physical Page Number (PPN) | Page Offset - PA for cache:
Tag | Set | Block Offset(e.g., PPN part provides Tag+Set)
Integrated Flow
CPU generates VIRTUAL ADDRESS (VA) | v +------------+ TLB Hit (80-99%) +-----------------+ | TLB | --------------------------->| CACHE | |(Translation| VPN -> PPN translation | (Physically | | Lookaside | | tagged/indexed)| | Buffer) | TLB Miss -> Page Table | | | CAM 64-1024| walk (hardware / OS) | Tag | Set | Off | +------------+ -> refill TLB +--------+--------+ | |Hit | Miss | Miss v v +------------+ +-------+ +--------+ | Page Table | | Data to CPU | Main Memory | | in Memory | +-------+ (fetch block -> cache) |(2-level) | +------------+ | v Physical Address (PA) = PPN + offset ---> to Cache & Memory protection checkStep-by-Step Operations
CPU issues VA: VPN + Offset. Also permission bits checked.
TLB Lookup (parallel with cache - virtually indexed):
- TLB Hit: CAM compares VPN with all entries (valid+ASID). Returns PPN in ~1 cycle. Form PA = PPN || offset.
- TLB Miss: Hardware page table walker reads page table in memory (2-4 accesses for multi-level), brings PTE to TLB. If page not in memory -> Page Fault -> OS loads from disk.
Cache Access (using PA - physically indexed physically tagged PIPT, most common):
- Decode PA:
Set = (PA >> blockOffset) % sets, compare Tag array for that set (4-way). - Cache Hit: Data returned to CPU (~4-10 cycles L1). No memory access.
- Cache Miss: Request goes to L2/L3 / Main Memory; block (64B) fetched to cache line (with Tag), then to CPU. TLB and cache may be accessed in parallel or sequentially depending on design:
- PIPT: TLB first, then cache (safe, needs translation).
- VIPT: Index with VA bits (no alias), Tag with PA -> overlaps TLB.
- VIVT: Both virtual - needs flush on context switch.
- Decode PA:
Overlap / Virtually Indexed Physically Tagged (VIPT) optimization: L1 cache can start set decode using page offset bits (12 bits = not translated) while TLB translates VPN. On translation complete, tag compare uses PPN.
Protection & Extras
- TLB PTE contains Valid, Dirty, Referenced, R/W/X, U/S, Cacheability bits - checked on translation.
- On context switch, TLB flush or ASID-tagged entries avoid flush.
- Multi-level Inclusive TLB + L1/L2 Cache hierarchy: TLB miss cost 20-100 cycles; Page fault ms.
Summary:
VA -> TLB (VPN->PPN) -> PA -> Cache(Tag/Set match) -> Hit? -> CPU : Memory. TLB is cache for page table, Cache is cache for memory blocks.- VA:
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q4b. Differentiate between hardwired programmed control and microprogrammed control.20147m
Module 4: Memory Organization
View this question on its own page →Differentiate between hardwired programmed control and microprogrammed control.
Worked SolutionHardwired vs Microprogrammed Control Unit
Aspect Hardwired Control Microprogrammed Control Principle Control signals generated by combinational circuit (logic gates, encoder/decoder, sequence counter SC, flip-flops). Fixed wiring. Control signals generated by microprogram stored in Control Memory (ROM). Each microinstruction bit = one control signal; execution = fetching microinstructions. Structure Gates + Decoder (IR opcode -> D0-D7) + Timing from SC + Flip-flops (E, I) + Encoder to generate , etc. Control Address Register (CAR), Control Data Register (CDR), Control Memory (256x20 bits), Next-address logic / Sequencer, Control Buffer Register. Storage No stored program. Combinational logic. Microprogram in ROM/RAM (firmware). microinstructions per machine instruction. Speed Fast (gate delay only) ~ 1-2 gate levels. Ideal for RISC, pipelined. Slower (control memory access each microcycle, ~1 memory fetch per microinstruction) Flexibility Inflexible - to change instruction set need to redesign hardware/wiring. Complex to modify. Flexible - change by updating microcode ROM; add new instruction by adding microroutine. Easy to support CISC complex instructions. Design Cost Complex design for many instructions (many states, hard to debug). But cheap hardware for simple ISAs. Easier design: write microprogram akin to programming. Modular. Complexity handling Becomes unwieldy when instructions > ~50, addressing modes many (state explosion). Handles complex instructions (MUL, interrupt) easily - just longer microroutine. Used in CISC (IBM 360, VAX, 68000). Control signals Generated as Boolean equations: e.g., Each bit of microinstruction directly drives signal: etc. Modification Requires hardware change (ECN). Can be patched via writable control store (WCS) - firmware update. Example RISC processors (MIPS, ARM), old 8085 hardwired, Mano basic computer simplified hardwired version. Historical: IBM System/360, Intel microcode for x86 CISC, modern x86 decodes complex instructions to micro-ops from microcode ROM. Control memory size None Need width ROM; control throughput is fetch-decode of microinstructions (horizontal vs vertical microcode). Techniques Sequence counter + decoder; one-hot, PLA Horizontal (many bits per microinst, parallel) vs Vertical (encoded fields, compact) ; Wilkes model. Diagram Analogy
- Hardwired:
IR,T,I,SC -> Combinational Logic (PLA) -> 30 control lines - Microprogrammed:
IR -> Map -> CAR -> Control Memory -> CDR -> control lines; CDR.next_addr -> CAR
Horizontal vs Vertical within Microprogrammed
- Horizontal: 40-60 bits, each bit one signal - high parallelism, fast but large ROM.
- Vertical: 16-20 bits encoded, needs decoder, compact but slower.
Modern hybrid: RISC core hardwired for simple ops + microcode ROM for complex x86 instructions translated to micro-ops (e.g., Intel/AMD).
Conclusion: Use Hardwired when speed is critical and instruction set simple/small; use Microprogrammed when instruction set is complex/variable and design flexibility/upgradeability matters.
- Hardwired:
Q5. Discuss the different ways in which ROM can be programmed.201614m
Module 4: Memory Organization
View this question on its own page →Discuss the different ways in which ROM can be programmed.
Worked SolutionDifferent Ways ROM Can Be Programmed
ROM (Read Only Memory) programming refers to how data is written into ROM. Based on programmability and erasability, types are:
1. Mask Programmed ROM (MROM)
- When programmed: At time of manufacturing by manufacturer using photographic mask.
- Mechanism: Transistor connections at crosspoints defined by mask. Presence/absence of transistor = 1/0.
- Features: Non-field programmable, cheapest per unit in mass production but high setup cost, 100% non-erasable.
- Use: Firmware, character generators, microcode where volume high and code never changes.
2. PROM (Programmable ROM) - One Time Programmable (OTP)
- Mechanism: Manufactured as all 0s/1s with fusible NiCr links at each bit. User programs with PROM programmer which applies high current pulse (20-50mA, ~10-12V) to blow fuses for desired bits.
- Process:
Address selected -> data applied -> programming pulsefor each word. - Features: Field programmable once, cannot be erased; if mistake chip discarded.
3. EPROM (Erasable PROM)
- Uses FAMOS transistors with floating gate storing charge.
- Programming: Electrical - with EPROM programmer, apply Vpp ~21-25V pulse to inject hot electrons into floating gate via avalanche. 0 = charged, 1 = uncharged.
- Erasing: UV light (~253.7nm) through quartz window for 15-20 min erases entire chip by photoelectric discharge. Then reprogrammable (typically ~1000 cycles).
- Types: UV-EPROM
4. EEPROM (Electrically Erasable PROM) / E²PROM
- Uses FLOTOX/ MNOS structure with thin oxide allowing Fowler-Nordheim tunneling.
- Programming & Erasing: Both electrically - no UV, no removal from circuit. Byte/word erasable using ~20V internal charge pump.
- Features: ~10^4-10^5 cycles, slower write (ms vs ns read), more expensive per bit due to 2 transistor per cell.
5. Flash Memory (Advanced EEPROM)
- Bulk/ sector erase instead of byte erase using same tunneling.
- Programming: Electrical with on-chip charge pump. Erase entire block at once (~1s), program byte/page wise.
- Features: High density, in-system programmable, ~10^5-10^6 cycles, used in SSD, pen drives, BIOS.
Summary Table:
Type Programmability Erasability Volatility MROM Factory mask only No Non-volatile PROM Once by user (fuse) No Non-volatile EPROM User, electrical UV whole chip Non-volatile EEPROM User, electrical byte-wise Electrical byte-wise Non-volatile Flash User, electrical sector-wise Electrical block-wise Non-volatile For exam, diagram of ROM array with row/column decoders and fuse/ floating gate cell should be drawn.
Q5(a). Illustrate what are the challenges associated with concurrent access to memory in parallel processing?20247m
Module 4: Memory Organization
View this question on its own page →Illustrate what are the challenges associated with concurrent access to memory in parallel processing?
Worked SolutionChallenges of Concurrent Memory Access in Parallel Processing
Multiple processors/cores accessing shared memory simultaneously creates conflicts due to true/false sharing. Key challenges:
1. Race Conditions & Data Inconsistency
Two CPUs read-modify-write same location
xwithout synchronization:P1: R x(5) -> +1 -> W x(6) P2: R x(5) -> +1 -> W x(6) // lost update, expected 7Without atomicity, final value non-deterministic.
2. Cache Coherence
Each core has private L1/L2 cache. If P1 caches
x=5and P2 updates to 6, P1 still sees stale 5. Need coherence protocol (MSI/MESI) with invalidation/update, adding bus traffic and latency.3. Memory Consistency Model
Order in which writes by one CPU become visible to others. Sequential consistency vs weak consistency. Without fences/barriers, reordering by compiler/CPU leads to subtle bugs.
4. Synchronization Overhead
Need locks, semaphores, barriers, atomic CAS. Lock contention serializes execution, creates critical section bottleneck, reduces speedup (Amdahl). Lock granularity trade-off: fine-grain = overhead, coarse-grain = contention.
5. False Sharing
Two unrelated variables
a,bin same cache line (64B). P1 writesa, P2 writesb-> line bounces between caches via invalidations despite no true sharing, degrades performance by 10-100x.6. Memory Contention & Bandwidth
Shared bus/memory controller saturates. In UMA, all accesses via single bus -> bottleneck. In NUMA, remote memory access latency 2-3x local -> non-uniform performance, need locality optimization.
7. Deadlock / Livelock / Priority Inversion
Circular wait on locks -> deadlock. Livelock when both back-off repeatedly. Requires deadlock avoidance protocols.
8. Scalability & Coherence Traffic
Snoopy protocol broadcasts limit to ~32 cores; directory protocols add memory overhead and indirection latency for large systems.
Solution directions: MESI/MOESI + directory, atomic primitives (LL/SC), transactional memory, lock-free data structures, cache-line padding, NUMA-aware allocation.
Q5(b). Consider a direct mapped cache with 8 cache blocks (numbered 0-7). If the memory block requests are in the following order 3, 5, 2, 8, 0, 63, 9, 16, 20, 17, 25, 18, 30, 24, 2, 63, 5, 82, 17, 24. What would be the status of cache blocks (block numbers residing in cache) at the end of the sequence.20237m
Module 4: Memory Organization
View this question on its own page →Consider a direct mapped cache with 8 cache blocks (numbered 0-7). If the memory block requests are in the following order 3, 5, 2, 8, 0, 63, 9, 16, 20, 17, 25, 18, 30, 24, 2, 63, 5, 82, 17, 24. What would be the status of cache blocks (block numbers residing in cache) at the end of the sequence.
Worked SolutionDirect Mapped Cache - Final Block Status
Cache size blocks (0-7). Direct mapped: index = block mod 8.
Requests: 3,5,2,8,0,63,9,16,20,17,25,18,30,24,2,63,5,82,17,24
Trace:
# Block Index () Action Cache state 0-7 - - - init [-,-,-,-,-,-,-,-] 1 3 3 miss [-,-,-,3,-,-,-,-] 2 5 5 miss [-,-,-,3,-,5,-,-] 3 2 2 miss [-,-,2,3,-,5,-,-] 4 8 0 miss [8,-,2,3,-,5,-,-] 5 0 0 miss evict 8 [0,-,2,3,-,5,-,-] 6 63 7 miss [0,-,2,3,-,5,-,63] 7 9 1 miss [0,9,2,3,-,5,-,63] 8 16 0 miss evict 0 [16,9,2,3,-,5,-,63] 9 20 4 miss [16,9,2,3,20,5,-,63] 10 17 1 miss evict 9 [16,17,2,3,20,5,-,63] 11 25 1 miss evict 17 [16,25,2,3,20,5,-,63] 12 18 2 miss evict 2 [16,25,18,3,20,5,-,63] 13 30 6 miss [16,25,18,3,20,5,30,63] 14 24 0 miss evict 16 [24,25,18,3,20,5,30,63] 15 2 2 miss evict 18 [24,25,2,3,20,5,30,63] 16 63 7 hit [24,25,2,3,20,5,30,63] 17 5 5 hit [24,25,2,3,20,5,30,63] 18 82 2 miss evict 2 [24,25,82,3,20,5,30,63] 19 17 1 miss evict 25 [24,17,82,3,20,5,30,63] 20 24 0 hit [24,17,82,3,20,5,30,63] Final Cache Status
- Block 0: 24
- Block 1: 17
- Block 2: 82
- Block 3: 3
- Block 4: 20
- Block 5: 5
- Block 6: 30
- Block 7: 63
Vector form: [24, 17, 82, 3, 20, 5, 30, 63] for indices 0-7.
Hits = 3 (63,5,24); Misses = 17. No fully associative/LRU needed - direct mapped deterministic.
Q6. Define paging in memory management and write its advantages.201514m
Module 4: Memory Organization
View this question on its own page →Define paging in memory management and write its advantages.
Worked SolutionPaging in Memory Management
1. Definition
Paging is a non-contiguous memory allocation technique that eliminates external fragmentation. It divides both logical (virtual) address space and physical memory into fixed-size blocks:
- Pages: Fixed-size blocks of logical/virtual memory (e.g., 4 KB)
- Frames (Page Frames): Same-size blocks of physical memory
- Page Table: Data structure maintained by OS that maps page number -> frame number. Each process has its own page table base register (PTBR).
Logical address = where = page number (index into page table), = offset within page.
Physical address = where = frame number from page table entry.
Translation:
Logical Addr (e.g., 16-bit with 1K page): | page p | offset d | | |-------> offset passes unchanged v Page Table[p] -> frame f | Physical Addr = f * page_size + dWith TLB (Translation Lookaside Buffer) caching recent translations for speed.
Example: Page size 4KB, 32-bit VA: 20-bit , 12-bit . Logical addr
0x00403ABC: , -> ifPageTable[0x00403]=0x07F1Athen physical =0x07F1AABC.If page not in memory, page fault occurs - OS loads page from disk (demand paging, virtual memory).
2. Diagram
Process Virtual Memory Page Table Physical Memory +---------------+ +------------+ +---------------+ | Page 0 |-------------->| Frame 2 |------------>| Frame 0 | +---------------+ +------------+ +---------------+ | Page 1 |-------------->| Frame 5 |------------>| Frame 1 | +---------------+ +------------+ +---------------+ | Page 2 | | invalid | | Frame 2: Pg0 | +---------------+ +------------+ +---------------+ | Page 3 |-------------->| Frame 1 | | Frame 3 | +---------------+ +------------+ +---------------+ Frame 5: Pg13. Advantages of Paging
No External Fragmentation: Any free frame can be allocated to any page; memory is used efficiently. Compaction not needed.
Supports Virtual Memory: Allows process size > physical memory via demand paging; only needed pages loaded, rest on disk.
Simplifies Memory Management: Fixed-size blocks easy to manage with free-frame list; allocation/deallocation fast.
Allows Sharing: Shared pages (common code/libraries) can map to same frame in different processes - saves memory.
Memory Protection: Page table entry contains protection bits (R/W/X, user/supervisor) - prevents illegal access; invalid entries cause trap.
Supports Multiprogramming: Multiple processes can reside in fragmented physical frames simultaneously.
Efficient Swapping: Swapping whole pages is easy; copy-on-write optimization possible.
Disadvantage (for completeness): Internal fragmentation (last page may be partially unused ~ half page average), and page table overhead (+ TLB needed) and extra memory reference if TLB miss (2 accesses).
Q6(a). Differentiate between expansion and extension of memory.20147m
Module 4: Memory Organization
View this question on its own page →Differentiate between expansion and extension of memory.
Worked SolutionDifferentiate between Expansion and Extension of Memory
Although both are techniques to increase memory capacity using smaller chips, they address different dimensions: depth (words) vs. width (bits). Sometimes textbooks use the terms interchangeably, but standard distinction is:
Aspect Memory Expansion (Word/Depth Expansion) Memory Extension (Bit/Width Extension) Goal Increase number of words (depth) e.g., -> Increase word length / bits per word (width) e.g., -> What is increased Address space (more addresses) Data bus width (more bits per address) Address lines Extra MSB lines needed for chip selection; address split into chip-select + intra-chip address Same address lines to all chips; no extra address decoding for width Data lines Data width unchanged; chips' data buses share via tri-state/bus, only one active at a time Data buses concatenated; each chip contributes part of word, all active simultaneously Chip Select (CS) logic Decoder required: -to- decoder driven by high-order address bits enables one chip at a time No decoder: CS of all chips tied together (common CS), all chips enabled together Connection Address buses common, data buses common (wired-OR via tri-state), CS decoded Address buses common, data buses split/combined, CS common Example Four to make : <br> A0-A9to all chips,A10-A11-> 2:4 decoder -> CS0-CS3. Data D0-D7 common bus.Two to make : <br> A0-A9to both, CS0=CS1= CS, Chip1 D0-D3 -> system D0-D3, Chip2 D0-D3 -> system D4-D7.Diagram CPU A0-A9 ----> all chips A0-A9<br>`CPU A10-A11 -> Decoder -> CS0CS1 Analogy Adding more pages to a book (more pages) Widening each page (more columns per page) Diagrams
Expansion (Depth) using x2:
A0-A9 +----------------+ +---------->| 1Kx8 Chip0 |----> D0-D7 --+ | +----------------+ | Tri-state A0-A9-+ +----------------+ +--> System D0-D7 +---------->| 1Kx8 Chip1 |----> D0-D7 --+ | +----------------+ A10 --> Decoder -> CS0 (A10=0), CS1 (A10=1) (only one active)Extension (Width) using x2:
A0-A9 ------> +--------+ D0-D3 ----> System D0-D3 |1Kx4 C0 | CS -------->| | +--------+ A0-A9 ------> +--------+ D0-D3 ----> System D4-D7 |1Kx4 C1 | CS -------->| | +--------+Combined: To make from chips, do both: need 4 groups (expansion) each with 2 chips in parallel (extension) = 8 chips.
In short: Expansion = more words, Extension = wider words. Both together give arbitrary memory from chips.
Q6b. Describe organization of a typical RAM chip. Differentiate between static RAM chip and dynamic RAM chip.20147m
Module 4: Memory Organization
View this question on its own page →Describe organization of a typical RAM chip. Differentiate between static RAM chip and dynamic RAM chip.
Worked SolutionSolution - RAM Chip Organization & SRAM vs DRAM
A) Organization of a Typical RAM Chip:
A RAM chip of size (e.g., , ) has:
- Memory Array: Matrix of memory cells arranged in rows columns. For , 8192 cells (128 rows 64 columns).
- Address Decoder: address lines decoded to select one row/word. Row decoder selects row, column decoder selects bit group. Example: 10 lines for 1024 words (5 for row, 5 for column or 10 for row).
- Memory Cells: Each cell stores 1 bit (flip-flop for SRAM, capacitor+transistor for DRAM).
- Chip Select (CS) / Chip Enable (CE): Enables chip only when selected - allows building larger memories by combining chips.
- Read/Write Control (RD/WR, WE, OE): write enabled, read.
- Bidirectional Data Lines (): Input data for write, output for read - tri-state buffers. lines = word length.
- Address Lines (): Input address.
Construction of larger memory: Using chip select and address decoding. Eg., to make from two chips, drives CS via decoder.
Block diagram: Address Lines -> Row/Column Decoder -> Memory Cell Array -> Sense Amplifiers / Write Drivers -> Data Lines. Control logic coordinates CS, OE, WE.
B) Difference between Static RAM (SRAM) and Dynamic RAM (DRAM):
Parameter Static RAM (SRAM) Dynamic RAM (DRAM) Cell Design 6 transistors (bistable latch/flip-flop) 1 transistor + 1 capacitor (charge storage) Storage Holds data as long as power on (static) Charge leaks, needs periodic refresh every ~2ms Refresh Circuit Not needed Required (refresh controller, ROW strobing) Density Low (6T per bit) High (1T per bit) - 4-5x denser Speed Fast (access 1-10 ns, no refresh overhead) Slower (access 50-70 ns + refresh) Power More power per cell, but no refresh power Less per cell, but refresh consumes power Cost Costly per bit Cheap per bit Use Cache (L1,L2,L3), fast buffers, registers Main memory (DDR SDRAM) Volatility Volatile (like DRAM) Volatile Summary: SRAM = speed, DRAM = density & cost-effectiveness for large memory.
Typical RAM Chip Pin Diagram: , , , , , , .
Q7. A virtual memory system has an address space of 8k words, memory space of 4k words and page & block size of 1k words. The following page reference changes occur during a given time interval: 4, 2, 0, 1, 2, 6, 1, 4, 0, 1, 0, 2, 3, 5, 7 Determine the four pages that are resident in main memory after each page reference change if the replacement algorithm used is - (i) FIFO - (ii) LRU.201614m
Module 4: Memory Organization
View this question on its own page →A virtual memory system has an address space of 8k words, memory space of 4k words and page & block size of 1k words. The following page reference changes occur during a given time interval:
4, 2, 0, 1, 2, 6, 1, 4, 0, 1, 0, 2, 3, 5, 7
Determine the four pages that are resident in main memory after each page reference change if the replacement algorithm used is- (i) FIFO
- (ii) LRU.
Worked SolutionAddress space , memory , page virtual pages (0-7), page frames. Reference string length :
Table shows resident set after each reference. F = page fault.
(i) FIFO - evict oldest loaded page
Ref Hit/Fault Resident set (4 frames) Evicted FIFO queue (oldest→newest) 4 F 4, -, -, - - [4] 2 F 4, 2, -, - - [4,2] 0 F 4, 2, 0, - - [4,2,0] 1 F 4, 2, 0, 1 - [4,2,0,1] 2 Hit 4, 2, 0, 1 - [4,2,0,1] 6 F 6, 2, 0, 1 4 [2,0,1,6] 1 Hit 6, 2, 0, 1 - [2,0,1,6] 4 F 6, 4, 0, 1 2 [0,1,6,4] 0 Hit 6, 4, 0, 1 - [0,1,6,4] 1 Hit 6, 4, 0, 1 - [0,1,6,4] 0 Hit 6, 4, 0, 1 - [0,1,6,4] 2 F 6, 4, 2, 1 0 [1,6,4,2] 3 F 6, 4, 2, 3 1 [6,4,2,3] 5 F 5, 4, 2, 3 6 [4,2,3,5] 7 F 5, 7, 2, 3 4 [2,3,5,7] - Faults , Hits , Hit ratio .
- Final resident pages {2,3,5,7}.
(ii) LRU - evict least recently used
Maintains recency; on hit update timestamp.
Ref Hit/Fault Resident set Evicted (LRU) 4 F 4, -, -, - - 2 F 4, 2, -, - - 0 F 4, 2, 0, - - 1 F 4, 2, 0, 1 - 2 Hit 4, 2, 0, 1 - (2 MRU) 6 F 6, 2, 0, 1 4 (LRU) 1 Hit 6, 2, 0, 1 - (1 MRU) 4 F 6, 2, 4, 1 0 (LRU, not used since time 3) 0 F 6, 0, 4, 1 2 (LRU) 1 Hit 6, 0, 4, 1 - 0 Hit 6, 0, 4, 1 - 2 F 2, 0, 4, 1 6 (LRU) 3 F 2, 0, 3, 1 4 (LRU) 5 F 2, 0, 3, 5 1 (LRU) 7 F 2, 7, 3, 5 0 (LRU) - Faults , Hits , Hit ratio .
- Final resident pages {2,3,5,7} (same final set but different intermediate eviction order; LRU has one extra fault).
Note for this string FIFO outperforms LRU by 1 fault - shows FIFO not always worse, but LRU generally avoids Belady's anomaly and is stack-optimal.
Q7. What is a page fault? What does a page fault signify? Explain the different page replacement algorithms which determine the page to be removed in case of full memory.201714m
Module 4: Memory Organization
View this question on its own page →What is a page fault? What does a page fault signify? Explain the different page replacement algorithms which determine the page to be removed in case of full memory.
Worked SolutionSolution - Page Fault and Page Replacement Algorithms (14M)
What is a Page Fault?
In virtual memory with demand paging, pages are loaded from secondary storage (disk) to main memory only when needed. A page fault is an exception (trap) that occurs when a running process tries to access a page that is currently not present in main memory (valid bit = 0 in Page Table or TLB miss). The MMU detects this via page table entry's present/absent bit and raises interrupt #14 (x86).What does it signify?
- Indicates miss in main memory hierarchy; required page (or segment of program/data) is still on disk (swap space).
- Triggers OS fault handler: OS must block the process, allocate a free frame, read the page from disk into frame (I/O), update page table (frame number, valid=1), and restart the faulting instruction.
- High frequency = thrashing if insufficient frames (working set > memory).
- Counted as overhead: interrupt + context switch + disk I/O (
ms) >> memory access (ns).
Page fault handling steps:
- Trap to OS, save registers.
- Check if reference was legal (segmentation violation vs valid page on disk).
- Find free frame (or victim via replacement algorithm if none free).
- If victim dirty, write back to disk.
- Read required page from disk into frame (DMA).
- Update page table, TLB invalidated.
- Restart process at faulting instruction.
Page Replacement Algorithms - when memory is full (no free frame), which victim page to evict:
1. FIFO (First-In First-Out):
- Replaces page that has been in memory longest (queue). Simple via FIFO queue.
- Belady's Anomaly: More frames can increase faults! Not stack algorithm.
- Example: Reference string 1,2,3,4,1,2,5,1,2,3,4,5 with 3 frames -> 9 faults.
2. Optimal (OPT / MIN) - Theoretical:
- Replaces page that will not be used for longest period in future (furthest next use). Gives minimum faults, used as benchmark.
- Impossible to implement perfectly (requires future knowledge), but approximated.
- Example: Same string -> 7 faults (optimal).
3. LRU (Least Recently Used):
- Replaces page that has not been used for longest time in past. Exploits locality.
- Implementation: counter/timestamp or stack, or approximation via reference bits.
- Good performance, close to Optimal. Stack algorithm (more frames never hurts).
- Example: With same string -> 10 faults.
4. Approx. LRU variants:
- NRU / Clock (Second Chance): Circular queue with reference bit R. Give second chance if R=1 then clear and rotate; if R=0 replace. Efficient.
- Aging / LFU / MFU: Least Frequently Used (count accesses) / Most Frequently Used - but LFU suffers cache pollution.
5. LIFO / Random:
- LIFO replaces last loaded; Random picks random victim - simple, avoids Belady but unpredictable.
Comparison Table:
Algorithm Needs future? Overhead Anomaly Performance FIFO No Low Yes Poor Optimal Yes - No Best (ideal) LRU No High (stack) No Good Clock No Low No Good approx. LFU No Medium No Depends Selection criteria: Fault rate, implementation cost, hardware support (R and M bits in page table entry help Clock/LRU approximation). Modern OS uses Clock (enhanced second chance with Dirty bit) or LRU approximation with aging.
Dirty bit: If victim page modified (M=1), must write back before replacement - double I/O cost, so some algorithms prefer clean victims (NRU class 0: R=0 M=0).
Q7a. Explain swapping. Why is it used in memory management?20147m
Module 4: Memory Organization
View this question on its own page →Explain swapping. Why is it used in memory management?
Worked SolutionSwapping in Memory Management
Definition
Swapping is the technique of temporarily moving a process (whole or part) from main memory (RAM) to secondary storage (swap space/backing store) and bringing it back later for execution.Introduced in early time-sharing systems (Atlas, UNIX) to support multiprogramming beyond physical memory size.
Stored image on disk is called swap-out; retrieving is swap-in (roll-out / roll-in).
How it Works
- Scheduler detects low free frames or blocked process waiting for I/O.
- Swapper (mid-term scheduler) selects victim process → copies its entire address space (code, data, stack, PCB) to contiguous swap area on disk.
- Page tables / base-limit registers updated, frames freed.
- Later when memory available and process scheduled, swapper reads image back (possibly at different physical address → requires relocation / dynamic binding via relocation register).
Modern systems swap pages/segments, not whole processes (demand paging is a lazy swap).
Diagram:
Main Memory [P1|P2|P3|hole] ↔ Disk Swap Area [P4(swapped)] ↔ SchedulerWhy Used? (Objectives)
- Multiprogramming degree: Run more processes than fits in RAM. Example processes on RAM via time-multiplexing.
- Memory compaction / fragmentation removal: Swapping out creates large contiguous free blocks, reducing external fragmentation.
- Priority & scheduling: Swap out low-priority/blocked processes to give room to urgent ones (mid-term
suspend). - Fairness & time-sharing: Quantum expired → swap out to let next process in.
- Emergency handling: Low-memory handler frees RAM quickly.
- I/O overlap & backing store for paging: Pages not resident stay on disk.
Types
- Whole-process swapping: Simple but heavy I/O (entire address space).
- Page swapping (paging): Swap only pages, more efficient, foundation for virtual memory.
- Segment swapping: Similar for segmented systems.
Cost & Issues
- Transfer time: Main cost . e.g. . So swap only if process idle for longer.
- Blocked I/O: Process with pending I/O or pinned pages cannot be swapped.
- Thrashing risk: Excessive swapping degrades CPU utilization → need working set / locality.
Today pure swapping rare; virtual memory + demand paging is generalized swapping with finer granularity, and swap file/partition remains as overflow store.
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q7b. Explain virtual memory. Explain the role of logical as well as physical address.20147m
Module 4: Memory Organization
View this question on its own page →Explain virtual memory. Explain the role of logical as well as physical address.
Worked SolutionVirtual Memory
Definition: Virtual memory is a memory management technique that makes an application think it has contiguous, large private address space, independent of physical RAM size, by automatically moving data between RAM and disk (swap/backing store) via paging/segmentation. It gives illusion of
virtual size >> physical size.OS + MMU provide address translation per reference; only active working set stays in RAM, rest on disk, loaded on demand (page fault).
Why Virtual Memory?
- Run programs larger than physical memory.
- Multiprogramming isolation & protection (each process virtual space).
- Simplified linking/loading, no external fragmentation (with paging).
Logical (Virtual) vs Physical Address - Roles
Logical / Virtual Address - Generated by CPU before translation.
- Address seen by process/compiler: e.g. -bit virtual → per process (), -bit in x86-64.
- Partitioned:
| Virtual Page Number (VPN) | Offset |(offset = page size bits; e.g. page → bits offset). - Never used to access RAM directly; goes through MMU.
- Contiguous from process view; sparse vs file mapping allowed.
- Protect bits checked per virtual page.
Physical Address - Actual address on RAM bus after translation.
- After MMU/TLB lookup:
| Physical Frame Number (PFN) | Offset |. - Range limited by installed RAM: e.g. RAM → -bit physical.
- Used by cache/memory controller.
- Multiple virtual pages (even from different processes) can map to same physical frame (shared memory) or one virtual page can map nowhere (paged out → page fault).
Translation flow:
CPU issues VA ──► TLB (VPN→PFN) hit? ──► PA to cache/RAM │ miss └─► Page Table walk (in RAM) ──► PFN + valid bit │ invalid (not resident) └─► Page Fault → OS loads frame from disk, updates table, retriesExample: VA
0x00403F12() with pages, page table maps → PA0x1A2F12.Key distinction: Logical addresses give program portability & protection; physical addresses give actual storage location. Compiler/linker deals in logical; MMU/OS manages physical. Without translation, process would see raw RAM limits and fragmentation.
Modern extensions: Demand paging, copy-on-write, memory-mapped files, TLB, multi-level page tables all build on this split.
Q8. Explain in detail the three mapping procedures related to cache memory.201514m
Module 4: Memory Organization
View this question on its own page →Explain in detail the three mapping procedures related to cache memory.
Worked SolutionCache mapping decides how a main memory block maps to cache line(s). Let cache have lines, memory have blocks, address = Tag + Index/Set + Word/Offset.
1. Direct Mapping
Each memory block maps to exactly one cache line: .
Address split: .
e.g., 4096 lines need 12 line bits. With 64-word blocks (6 bits), address = Tag(remaining)+12+6.- Search: Compare only that line's tag - fast, simple.
- Miss: Replacement is forced, no choice.
- Drawback: Thrashing - two blocks mapping to same line continuously collide even if cache has free lines.
2. Associative (Fully Associative) Mapping
Any memory block can go to any cache line. Address = only; no line field.
- Search: Content-addressable memory (CAM) compares incoming Tag with all line tags in parallel.
- Replacement: Need algorithm - LRU, FIFO, Random.
- Advantage: No collision thrashing, best hit rate.
- Drawback: Expensive comparators for all lines, slow for large cache.
3. Set-Associative Mapping
Compromise. Cache divided into sets, each set has lines (-way). Block maps to , can occupy any of lines within set.
Address: .
Example , 4096 lines → 2048 sets → 11 set bits. Address = Tag+11+6.Search: Index set via Set field, associatively compare Tag among lines in that set only.
Replacement: Choose within set (LRU).
Special cases: → Direct, → Fully Associative.
Tradeoff: Hit rate improves with larger but cost increases. Typical .
Replacement policies (LRU, LFU, FIFO) apply to associative and set-associative when set is full. Write policies: Write-through + write-allocate/no-allocate, Write-back.
Q8a. Explain cache memory organization. Discuss mapping techniques (direct, associative, set-associative), replacement algorithms, and write policies.20257m
Module 4: Memory Organization
View this question on its own page →Explain cache memory organization. Discuss mapping techniques (direct, associative, set-associative), replacement algorithms, and write policies.
Worked SolutionCache Memory Organization (7 Marks)
1. Introduction:
Cache is a small, very fast SRAM between CPU and main memory that exploits locality of reference (temporal & spatial) to reduce average access time. CPU first checks cache; on hit data returned quickly, on miss block fetched from main memory.Hierarchy: CPU ↔ L1 ↔ L2 ↔ Main Memory ↔ Disk. Cache stores blocks/lines consisting of tag + data block + valid/dirty bits.
2. Mapping Techniques:
Mapping determines where a main memory block can be placed in cache.a) Direct Mapping:
Each memory block maps to exactly one cache line:Cache Line = j mod mwhere = number of lines. Address split:| Tag | Line | Word |.- Advantage: Simple hardware, low cost, fast lookup.
- Disadvantage: High conflict misses – two blocks mapping to same line thrash even if other lines empty. Hit ratio lower.
b) Fully Associative Mapping:
Any block can go into any line. Address split:| Tag | Word |. Tag compared associatively with all line tags in parallel.- Advantage: Most flexible, minimum conflict misses, best hit ratio.
- Disadvantage: Expensive – requires associative CAM comparator for every line, slow for large cache.
c) k-Way Set-Associative Mapping: Compromise.
Cache divided into sets, each set has lines. Block maps toSet = j mod v, can occupy any of lines within that set. Address split:| Tag | Set | Word |.
Example: 2-way, 4-way. Direct () and Fully Associative () are extremes.- Advantage: Reduces conflicts while keeping hardware manageable. Widely used (e.g., Intel uses 8-way/16-way).
- Disadvantage: Moderate hardware complexity.
3. Replacement Algorithms (needed when set is full):
- LRU (Least Recently Used): Replaces block not used longest time. Best hit ratio, implemented via counters/stack. Common.
- FIFO: Replaces first-loaded block. Simple but not optimal, suffers Belady effect.
- LFU: Replaces least frequently used.
- Random: Random selection, simple hardware, average performance.
4. Write Policies (on write hit):
- Write-Through: Data written to both cache and main memory simultaneously. Simple, consistent but high bus traffic. Uses write buffer.
- Write-Back (Copy-Back): Write only to cache and set dirty bit. Block written back to memory only on replacement. Less traffic, better performance but coherence complex.
- On write miss: Write-Allocate (fetch block to cache then write) vs No-Write-Allocate (write directly to memory).
Performance: where =hit rate.
Q9. How many ROM chips are required to produce a memory capacity of 4096 bytes? How many address lines are required to access the 4096 bytes? How many of these addresses will be common to all these chips?201714m
Module 4: Memory Organization
View this question on its own page →How many ROM chips are required to produce a memory capacity of 4096 bytes? How many address lines are required to access the 4096 bytes? How many of these addresses will be common to all these chips?
Worked SolutionROM Chip Calculation for 4096 Bytes (14 Marks)
Given: Required memory capacity = 4096 bytes = bits.
Let ROM chip capacity be bytes/chip. Standard chips often , , etc. General formulae below; numerical example for most common exam assumption follows.General Formulae:
- Number of chips
- Number of address lines to access 4096 bytes: lines (-)
- Common addresses: Address lines are split into chip-select (higher) + intra-chip (lower). Lower lines where go to all chips in parallel (common), upper lines go to decoder to generate chip selects.
Worked Example – Assume typical exam chip bit (512 nibbles = 256 bytes? often quoted as 1024×4):
Most textbooks assume bit ROM (128 bytes? actually bits =512 bytes) or (512 bytes).
Case A: If chip = (1024 bytes = 1 KB) – commonest for 4096:
- chips
- Address lines =12
- Per chip needs lines (-) common to all 4 chips (connected in parallel)
- Remaining lines () decoded via 2:4 decoder for chip select. So 10 common address lines, 2 chip-select lines.
Case B: If chip = bit = 256 bytes? Many colleges treat chip as bytes ():
- chips
- Per chip needs 9 lines () common to all 8 chips
- Remaining 3 lines decoded via 3:8 decoder. So 9 common lines.
Case C: If chip = bit = 2048 bits =256 bytes and need byte organized memory: Need 2 chips per byte location (pair to make 8 bits), so chips. Per chip 9 lines common? Actually 9 lines for 512 locations, 4 lines common? Detailed: chips arranged as 8 rows ×2 columns, - (9 lines) common to all, - (3 lines) to 3:8 decoder.
Answer in generic terms:
- Chips required = (e.g., for 1K×8, for 512×8, for 512×4)
- Address lines =12
- Common lines = to all chips (e.g., 10 lines for 1K chips, 9 for 512-byte chips), remaining lines are chip-select decoded.
Without loss, exam expects: 8 chips of 512 bytes, 12 address lines, 9 common (if 512-byte assumed) or 4 chips, 10 common (if 1K assumed). State assumption explicitly.
Q9(a). Write short notes on: Paging20237m
Module 4: Memory Organization
View this question on its own page →Write short notes on: Paging
Worked SolutionShort Note: Paging (7 Marks)
Concept: Paging is a memory management scheme that eliminates external fragmentation by dividing logical memory into fixed-size pages and physical memory into same-size frames. Pages are mapped to available frames via page table.
Terminology: Page size power of 2 (512B-8KB typical, e.g., 4KB in x86). Logical address =
| Page Number (p) | Offset (d) |. Physical address =| Frame Number (f) | Offset (d) |.Mechanism:
- CPU generates logical address. MMU extracts and .
- Page Table (per process, in RAM) gives mapping. Accessed via Page Table Base Register (PTBR).
- Physical address = . Translation via TLB cache for speed.
Page Table Entry contains: Frame number, valid/invalid bit, protection (R/W/X), dirty, referenced, present bit.
Example: 16-bit logic, page 1KB (10 bits offset):
| p(6) | d(10) |. If maps to , logic00 0010 00 0000000000→ physical00 0111 00....Types:
- Single-level: Simple but large for 32-bit (1M entries).
- Multi-level/Hierarchical paging (2/3-level): Used in x86 (Page Directory → Page Table), reduces table size.
- Inverted Page Table: One entry per frame, for large address spaces.
Advantages: No external fragmentation, simple allocation, supports virtual memory and swapping (pages to disk), protection and sharing (shared frames).
Disadvantages: Internal fragmentation (last page waste avg ½ page), page table memory overhead, translation overhead (TLB miss penalty), needs TLB for performance.
Demand Paging: Pages loaded from disk only on page fault (valid=0) → supports virtual memory larger than physical, uses page replacement (FIFO/LRU).
Paging vs Segmentation: paging fixed size, invisible to programmer; segmentation variable, logical units.
Q9(b). Write short notes on: Memory interleaving20237m
Module 4: Memory Organization
View this question on its own page →Write short notes on: Memory interleaving
Worked SolutionMemory Interleaving [7M]
Need: CPU is faster than DRAM. Single memory module can serve only one access at a time (access time ). Pipelining requests to multiple modules can increase effective bandwidth and hide latency (similar to pipeline).
Definition: Divide main memory into independent modules/banks that can be accessed in parallel/overlapped. Interleaving defines how consecutive addresses are spread across modules.
1. Types:
High-order interleaving (Memory banking): MSB selects module.
Address:| Module (k bits) | Offset (n-k bits) |
e.g. 4 modules (0-3), addresses 0-255: Module 0 holds 0-63, M1:64-127, M2:128-191, M3:192-255. Consecutive addresses map to same module -> no advantage for sequential access. Useful when program has locality in different segments (code in M0, data in M1).Low-order interleaving (true interleaved): LSB selects module.
Address:| Offset | Module |
e.g. 4 modules: mapping -> Module = .
Module 0: 0,4,8,12... Module1:1,5,9... Sequential addresses map to successive modules.
Low-order is generally called memory interleaving and used for cache line fill and vector access.
Example: 4-way low-order, , cycle.
Without interleaving: 4 words sequentially takes .
With interleaving: Issue request to M0 at , M1 at , M2 at , M3 at (pipelined). M0 returns at , M1 at ... Total . Effective access time not .2. Address generation:
For modules, bits of address select module. For low-order LSBs.
Memory controller has MAR/MDR, can latch requests.3. Advantages:
- Higher bandwidth : times potential.
- Reduced effective access time for sequential / stride-1 and vector operations.
- Avoids bank conflicts : If accesses are uniformly distributed, probability of conflict .
- Essential for cache block transfer (burst mode) and SIMD/vector processors.
4. Disadvantages / Limitations:
- Bank conflict: If successive accesses map to same module before it recovers (e.g. stride = ), pipeline stalls. e.g. stride 4 with 4 modules -> all accesses to M0.
- Cost: sets of decoders, buffers, bus arbitration more complex.
- Not helpful for random access with poor locality.
5. Relation to DRAM banks:
Modern DDR SDRAM internally has 4-16 banks with interleaving. Also C-access interleaving used in supercomputers (e.g. Cray). Need also interleaved cache (non-blocking).Diagram: CPU Address Bus -> Decoder (LSB->Bank Select) -> Banks 0..m-1 -> Data Bus Multiplexer -> CPU.
Conclusion: Low-order -way interleaving converts memory latency-bound system into bandwidth-bound by overlapping access cycles.
Q9(d). Write short notes on: Locality of reference20237m
Module 4: Memory Organization
View this question on its own page →Write short notes on: Locality of reference
Worked SolutionLocality of Reference [7M]
Principle: Program memory access is not random but clustered. Observed empirically (Denning, 1968). Foundation for cache, virtual memory and hierarchy design. execution time in code.
1. Types:
Temporal Locality: If location is referenced at time , it will likely be referenced again soon (near future).
Reason: Loops, reuse of variables, stack, counters.
Example:for(i=0;i<1000;i++) sum += a[i]; // `sum` reused every iterationsumaccessed every iteration -> temporal.Spatial Locality: If location is referenced, nearby locations will likely be referenced soon.
Reason: Sequential instruction execution, array traversal, contiguous structures.
Example:a[0], a[1], a[2]...contiguous words -> fetchinga[i]brings cache block of 64B (8 words) -> next 7 accesses are hits. Instructions are sequential as well.Sequential Locality: Special case of spatial - next instruction is unless branch.
2. Implications / Applications:
- Cache Memory: Block size word exploits spatial locality. Upper level stores working set exploiting temporal. LRU replacement exploits temporal. Without locality, hit ratio and cache useless.
- Virtual Memory / Paging: Keep working set in RAM; pages brought on locality basis. Thrashing occurs when locality violated / working set exceeds frames.
- Prefetching: Hardware prefetcher fetches based on spatial.
- Branch prediction & instruction cache: Sequential locality predicts next fetch.
- Quantified: Hit ratio for L1 when locality high. Effective access time: -> makes .
3. Working Set Theory:
Denning: = set of pages referenced in last references. Locality implies small (e.g. 2-4 pages) vs total size. OS tries to keep resident. If physical memory -> thrashing.
4. Example Calculation:
Loop touches 1K word array stride 1 with 64B block (16 words):
Without spatial exploitation: 1000 misses. With block: misses -> 93% hit rate due to spatial.5. Violations:
Linked list with nodes scattered, random pointer chasing, large stride defeats spatial locality; large data set with no reuse defeats temporal -> cache pollution.Conclusion: Locality of reference bridges speed gap between CPU and memory; hierarchy design (register-cache-main-disk) succeeds only because of it.
Q9b. Discuss memory hierarchy design principles. Explain how access time, cost, and size influence memory organization.20257m
Module 4: Memory Organization
View this question on its own page →Discuss memory hierarchy design principles. Explain how access time, cost, and size influence memory organization.
Worked SolutionMemory Hierarchy Design Principles [7M]
Why hierarchy? No single technology gives simultaneously large capacity + low cost + high speed. Hierarchy combines multiple levels giving illusion of large fast cheap memory by exploiting locality of reference.
Levels (pyramid top=fast):
Registers (32-64 words, 0.5 ns, highest cost/bit) | Cache L1/L2/L3 (SRAM, KB-MB, 1-10 ns) | Main Memory (DRAM, GB, 50-70 ns) | Secondary (SSD/HDD, TB, 0.1-10 ms) | Tertiary (Tape/Cloud, PB, seconds)Design Principles:
1. Inclusiveness & Locality:
Upper levels store subset (copy) of lower level working set. Temporal locality -> reuse in cache; spatial locality -> block size >1 word (cache line 64B, page 4KB, disk block 4KB). Hit ratio needed for effectiveness.2. Cost-Performance Tradeoff:
Cost/bit decreases downwards, Access time increases. Average cost/bit:
Dominated by cheap large lower level, while average access time dominated by fast upper level if high:
For memory hierarchy: . With , ~ Cache speed but capacity ~RAM.3. Size vs Time vs Cost:
- Faster -> Smaller (SRAM 6T cell area >> DRAM 1T, register file tiny)
- Larger -> Slower (address decode delay, physical distance)
- Cheaper -> Larger (DRAM vs SRAM ). Hierarchy picks sweet spot at each point.
4. Block Replacement & Mapping:
Direct/associative mapping, write-through/write-back, LRU replacement, demand paging - all to approximate optimal (Belady) with minimal overhead.5. Policies:
- Access locality principle: rule.
- Consistency: Write policies keep levels coherent.
- VM: Page tables allow hierarchy to appear as linear address space.
Influence on Organization:
- Cache size tradeoff: Too small -> low hit rate, too large -> slower hit time (increases ) and higher cost. Optimum ~32KB L1, 256KB L2.
- Main memory sized to hold working sets of multiprogrammed processes: to avoid thrashing.
- Use interleaving/banking and wide buses to match bandwidth between levels (e.g. 64B cache line burst from DRAM).
Example: Evolution from 1980: No cache -> 1-level -> 3-level + TLB hierarchy improved effective CPI from ~10 to ~1 despite 100x gap between CPU and DRAM.
Conclusion: Hierarchy succeeds because if locality holds, while , bridging technology gap.