concept Servers & hardware
CPU cache locality and working sets
The same number of reads can produce more cache misses when the working set stops fitting: a line may be evicted before its next use. A set that fits can stay resident, but its first reads still miss in an empty cache.
What it means
A read is a cache hit if its line is still in the cache when you need it; otherwise, it is a miss. The working set for a stretch of reads is the set of distinct cache lines those reads touch. A small working set can stay resident. When space runs short, the order of the reads matters: a line you need again may be the one you just displaced.
Consider a single, initially empty, read-only cache. It is fully associative, meaning any line can occupy any slot. Its replacement rule is least recently used (LRU): on a miss with no free slot, evict the resident line that has gone longest without a read. A hit uses no extra slot, but it changes which line counts as most recently used.
Try it
Use the defaults: Cache capacity of 2 lines, Access sequence of A B A C A, and Replacement policy of LRU (least recently used). The letters name synthetic cache lines, not addresses on your server.
CPU cache locality and working sets
Change working-set size and a synthetic access sequence; inspect cache hits, misses and the intermediate replacement state.
Synthetic inputs only. This is not a measurement of your hardware or service.
2 references reused a resident line; 3 did not. The order is least to most recently used.
Reuse and capacity
- Resident-line hits
- 2
- Cache misses
- 3
- Final cache, least to most recently used
- C · A
| Step | Line | Hit or miss | Cache before | Cache after | Evicted line |
|---|---|---|---|---|---|
| 1 | A | miss | None | A | None |
| 2 | B | miss | A | A · B | None |
| 3 | A | hit | A · B | B · A | None |
| 4 | C | miss | B · A | A · C | B |
| 5 | A | hit | A · C | C · A | None |
Evaluated evidence
- Cache capacity (lines)
- 2
- Evaluated cache-line access sequence
- A · B · A · C · A
- Replacement policy
- lru
Empty, fully associative, read-only LRU toy cache. No prefetching, writes, associativity conflicts, real CPU policy or timing prediction.
About this model
Every input is local synthetic evidence. Numbers stay as raw text until this model validates them. The shown evaluated values come from the same result as the explanation.
Presets replace the entire scenario. Reset restores all starting fields, scenario selection and model state; it does not change the open or closed state of this help or article FAQ.
No external request, device command, stored-input history or measurement is performed.
Read the cache order from left to right, least to most recently used. After each read, the referenced line is at the right.
| Step | Line | Cache before | Result | Evicted line | Cache after |
|---|---|---|---|---|---|
| 1 | A | Empty | Miss | None | A |
| 2 | B | A | Miss | None | A B |
| 3 | A | A B | Hit | None | B A |
| 4 | C | B A | Miss | B | A C |
| 5 | A | A C | Hit | None | C A |
Step 3 decides what happens at step 4. Reading A again makes B the least recently used line. Loading C therefore evicts B, leaving A available for the last read. The result is 2 hits and 3 misses, with final order C A.
Now use A B C A and change only Cache capacity between runs. With 2 lines, loading C evicts A and leaves B C. The last A misses: 0 hits, 4 misses. With 3 lines, loading C leaves A B C. The last A hits: 1 hit, 3 misses. The extra slot changes only the return to A, not the first read of any line.
For Cache capacity, enter a digit from 1 through 8; 2.000000000000000001 is invalid, not rounded to 2. Access sequence takes 1–32 space-separated line names from A through H. An empty sequence or an unsupported name is invalid and produces no counts. With valid inputs but Unknown / evidence unavailable selected for the replacement policy, the result is unknown, not zero hits. Reset restores the default inputs and scenario, returns the step and virtual time to zero, and clears errors, history, and any comparison.
In practice
Separate cold starts from reuse. In an empty cache, the first read of each line is a cold miss even when the whole working set fits. For a repeat read, count the distinct other lines read since the previous read of that line. This is its reuse distance. Under fully associative LRU, the repeat hits exactly when that distance is less than the capacity in lines. In A B C A, the distance for the returning A is two (B and C), which explains why two slots are not enough but three are.
Cornell’s cache notes distinguish cold and capacity misses from conflict misses, where placement restrictions make lines compete for slots. This model has no such restrictions, and its LRU rule is not a universal CPU policy. Intel’s description of the Skylake-SP cache hierarchy illustrates why cache capacity and organization must be checked for the particular processor.
For a hardware performance question, identify the cache level and its organization, then measure the workload of interest. This simulation counts references without modeling writes, prefetching, latency, or execution overlap; its counts do not predict cycles or elapsed time. For the next reference in a trace, ask whether the line is still resident, not merely whether it was accessed before.
Frequently asked questions
Editorial questions based on the listed sources and explicitly labeled local examples.
Does fitting in cache guarantee every access is a hit?
No. This simulation starts empty, so a first reference misses even when the entire set would fit. Fitting capacity is different from already having the line resident.
Does this example implement a real CPU replacement policy?
No. Its fully associative LRU rule is declared for teaching. A named processor can use a different cache organization or replacement policy.
Why can a repeated access still miss?
In the two-slot trace A B C A, loading C has already evicted A. Repetition alone does not preserve a line across other accesses.
Can this simulation predict elapsed time?
No. The evaluator counts references and replacements without assigning hit latency, miss penalties, prefetch behavior or execution overlap.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- Cornell CS3410: Caches
Hits & Misses; Locality; Fully Associative Cache; Replacement Policies; Three Categories of Misses. A miss may be cold, capacity-related or conflict-related. LRU is an explicit replacement rule for a teaching cache, not a universal CPU policy.
Checked .
- Intel Xeon Processor Scalable Family Technical Overview
Cache Hierarchy Changes. Named processor hierarchy differs from preceding products; capacity and cache organization are platform-specific.
Checked .