Memory Hierarchy (Cache, Main, Virtual Memory) # MCQs Practice set

Q.1 What is the primary purpose of cache memory in a computer system?

To store all data permanently
To increase CPU speed by storing frequently used data
To act as main memory
To manage virtual memory pages
Explanation - Cache memory stores frequently accessed instructions and data to reduce CPU access time and improve performance.
Correct answer is: To increase CPU speed by storing frequently used data

Q.2 Which of the following is the fastest type of memory?

Main memory (RAM)
Cache memory
Virtual memory
Hard disk storage
Explanation - Cache memory is located close to the CPU and is faster than main memory and virtual memory.
Correct answer is: Cache memory

Q.3 What type of cache mapping assigns a block of main memory to only one possible cache line?

Direct-mapped
Fully associative
Set associative
Random mapping
Explanation - In direct-mapped cache, each block of main memory maps to exactly one cache line, making it simple but prone to conflicts.
Correct answer is: Direct-mapped

Q.4 What is the typical size hierarchy from fastest to slowest in memory?

Virtual memory > Cache > Main memory > Registers
Registers > Cache > Main memory > Virtual memory
Main memory > Cache > Virtual memory > Registers
Cache > Registers > Main memory > Virtual memory
Explanation - Registers are fastest but smallest, followed by cache, main memory, and then virtual memory which is slowest.
Correct answer is: Registers > Cache > Main memory > Virtual memory

Q.5 Which cache replacement policy removes the least recently used block first?

FIFO
LRU
Random
LFU
Explanation - LRU (Least Recently Used) replacement removes the block that has not been accessed for the longest time.
Correct answer is: LRU

Q.6 What is virtual memory?

A type of RAM chip
A technique that uses disk storage as an extension of RAM
A cache memory technique
A type of ROM
Explanation - Virtual memory allows programs to use more memory than physically available by swapping data between RAM and disk.
Correct answer is: A technique that uses disk storage as an extension of RAM

Q.7 Which of the following is NOT a level of memory hierarchy?

Cache
Registers
GPU cores
Virtual memory
Explanation - GPU cores are processing units, not a type of memory in the traditional memory hierarchy.
Correct answer is: GPU cores

Q.8 What is the main drawback of using virtual memory?

It increases CPU speed
It may cause thrashing
It reduces main memory usage
It improves cache hit ratio
Explanation - Excessive use of virtual memory can lead to frequent page swaps, known as thrashing, which degrades performance.
Correct answer is: It may cause thrashing

Q.9 Which of the following describes a write-back cache?

Updates main memory immediately on every write
Updates cache only when needed and marks the block as dirty
Never writes back to main memory
Writes directly to virtual memory
Explanation - In write-back caches, writes update the cache first, and main memory is updated later when necessary.
Correct answer is: Updates cache only when needed and marks the block as dirty

Q.10 Set-associative cache is a compromise between which two types?

Direct-mapped and fully associative
Write-through and write-back
Virtual and physical memory
Primary and secondary storage
Explanation - Set-associative caches combine elements of direct-mapped and fully associative caches to balance speed and flexibility.
Correct answer is: Direct-mapped and fully associative

Q.11 What does the term 'cache hit' mean?

Data is not found in cache
Data is found in cache
Cache memory is full
Cache is cleared
Explanation - A cache hit occurs when the CPU finds the requested data in the cache memory, avoiding slower main memory access.
Correct answer is: Data is found in cache

Q.12 Which of the following is a type of cache mapping that allows a block to go into any cache line?

Direct-mapped
Fully associative
Set associative
Random mapping
Explanation - In fully associative caches, a block can be placed in any cache line, reducing conflicts but increasing search complexity.
Correct answer is: Fully associative

Q.13 In the memory hierarchy, which type of memory is typically measured in nanoseconds?

Hard disk
Cache memory
Virtual memory
Optical disk
Explanation - Cache memory access times are very low, typically in nanoseconds, unlike disks which are slower.
Correct answer is: Cache memory

Q.14 Which of the following reduces the average memory access time?

Increasing cache size
Using slower main memory
Increasing virtual memory size
Reducing register size
Explanation - A larger cache can store more frequently used data, increasing cache hits and reducing average access time.
Correct answer is: Increasing cache size

Q.15 What is the role of the Translation Lookaside Buffer (TLB) in virtual memory?

Stores frequently accessed cache blocks
Stores recent virtual-to-physical address translations
Stores hard disk data
Acts as a CPU register
Explanation - The TLB is a cache that stores recent page table entries to speed up virtual-to-physical address translation.
Correct answer is: Stores recent virtual-to-physical address translations

Q.16 Which of the following occurs when the CPU tries to access a page not in main memory?

Cache hit
Page fault
Segmentation fault
Cache miss
Explanation - A page fault happens when the required page is not in main memory, triggering the OS to fetch it from disk.
Correct answer is: Page fault

Q.17 Which memory level is closest to the CPU?

Registers
Cache
Main memory
Virtual memory
Explanation - Registers are inside the CPU and provide the fastest access to data.
Correct answer is: Registers

Q.18 Write-through cache updates main memory:

Immediately on every write
Only when block is replaced
Only during CPU idle time
Never
Explanation - Write-through cache ensures main memory is always up-to-date by writing immediately on every cache update.
Correct answer is: Immediately on every write

Q.19 Which of the following memory types is volatile?

Cache
ROM
Hard disk
Optical disk
Explanation - Cache is a type of RAM, which loses its data when power is turned off.
Correct answer is: Cache

Q.20 Which of the following best describes locality of reference?

Data is always random
Programs access the same memory locations frequently
Memory access time is uniform
Cache memory is unlimited
Explanation - Locality of reference (temporal and spatial) is the principle that programs tend to reuse the same memory locations or nearby locations frequently.
Correct answer is: Programs access the same memory locations frequently

Q.21 Which of the following is used to speed up main memory access?

Cache memory
Virtual memory
ROM
Hard disk
Explanation - Cache memory stores frequently accessed data to reduce the time CPU waits for main memory.
Correct answer is: Cache memory

Q.22 Which memory level has the largest capacity?

Cache
Main memory
Virtual memory
Registers
Explanation - Virtual memory uses disk space to extend the apparent size of RAM, giving the largest capacity among memory types.
Correct answer is: Virtual memory

Q.23 Which of the following is a disadvantage of direct-mapped cache?

Complex to implement
High conflict misses
Slower than main memory
Requires virtual memory
Explanation - Direct-mapped caches can lead to frequent conflicts if multiple memory blocks map to the same cache line.
Correct answer is: High conflict misses

Q.24 What is a dirty bit in cache memory?

Indicates if a block is invalid
Indicates if a block has been modified
Indicates the cache is full
Indicates memory size
Explanation - The dirty bit marks cache blocks that have been updated but not yet written back to main memory.
Correct answer is: Indicates if a block has been modified