- 2074 Magh · 6 marks
Memory simulation with example
Short answer
Trace-driven simulation feeds address traces to a memory model. For 3 frames and reference string 7,0,1,2,0,3,0,4,2,3,0,3,2, FIFO gave 3 hits (hit ratio 0.23), LRU gave 4 hits (0.31); using t_mem=100 ns, t_miss=8 ms, FIFO effective time ≈ 6.15 ms, LRU ≈ 5.54 ms.
Discuss memory simulation with example.
Memory simulation models the behaviour of a computer's memory system (main memory, cache or virtual memory) to estimate performance measures such as hit ratio, page-fault rate and average access time. It is usually trace-driven: a sequence of memory references (an address trace), taken from a real program or generated randomly, is fed to a model of the memory and its replacement policy.
Components
- Memory structure: page size, number of frames (or cache lines), associativity.
- Replacement policy: FIFO, LRU, optimal, random.
- Reference string (input): the order in which pages are referenced.
- Output: hits, misses (faults), hit ratio, effective access time = h × t_mem + (1 - h) × t_miss.
Algorithm
- Read the next page reference.
- If the page is already in a frame, count a hit (and update the usage order for LRU).
- Otherwise, count a fault; if all frames are full, remove a page according to the policy; then load the page.
- Repeat until the end of the string and report the statistics.
reference -> [in memory?] -yes-> hit
|no
[free frame?] -no-> replace (FIFO/LRU)
|
load page -> fault count + 1
Example: 3 frames
Reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2 (13 references).
FIFO
| Ref | 7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 | 3 | 0 | 3 | 2 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Frames | 7 | 7,0 | 7,0,1 | 0,1,2 | 0,1,2 | 1,2,3 | 2,3,0 | 3,0,4 | 0,4,2 | 4,2,3 | 2,3,0 | 2,3,0 | 2,3,0 |
| Result | F | F | F | F | H | F | F | F | F | F | F | H | H |
FIFO: 3 hits, 10 faults; hit ratio = 3/13 = 0.23.
LRU gives faults at 7, 0, 1, 2, 3, 4, 2, 3, 0, i.e. 9 faults and 4 hits (the 0 at position 5, the 0 at position 7, and the final 3 and 2); hit ratio = 4/13 = 0.31. So LRU performs better for this string.
With t_mem = 100 ns and t_miss = 8 ms, even a small difference in hit ratio changes the effective access time greatly: FIFO gives about (3/13)(100 ns) + (10/13)(8 ms) ≈ 6.15 ms, while LRU gives about (4/13)(100 ns) + (9/13)(8 ms) ≈ 5.54 ms. The simulation lets the designer choose the number of frames and the replacement policy; cache simulation follows the same method, using block addresses and mapping rules.
✓ Answer checked by Claude Opus 5.5 (high effort)