Block Replacement A replacement policy determines, out of all possible candidates, which one should be evicted from the cache upon arrival of a new piece of data. We evaluate an algorithm by running it on a particular string of memory references and computing the number of block misses. The string of memory references is called a reference string . Reference strings can be generated. Artifically (By using a random-number generator). We can trace a given system and record the address of each memory reference.
Block Replacement Algorithms First-in, First-out (FIFO) . Optimal. Least Recently used (LRU). For each algorithm, we will calculate The number of Hits. The number of misses. Hit Ratio (The number of Hits / Total number of attempts) The algorithm, that gives the more number of hits, will also increase the system performance by reducing the effective access time.
Block Replacement Algorithms Assumptions: Three blocks are given to the process. Initially all three blocks are empty. First-in, First-out (FIFO): When a block must be replaced, the oldest is chosen. Implementation: By using a FIFO Queue: We replace the block at the head of the queue. When a block is brought into memory we insert it at the tail of the queue.
First in First Out (FIFO) 7 1 2 3 4 2 3 3 2 1 2 1 7 1 Blocks : 3 Nos
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 7 *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 7 7 * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 7 7 7 * * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 7 7 7 2 * * * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 7 7 7 2 2 * * * * Hit
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 7 7 7 2 2 2 * * * * Hit *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 7 7 7 2 2 2 2 * * * * Hit * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 7 7 7 2 2 2 2 4 * * * * Hit * * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 2 7 7 7 2 2 2 2 4 4 * * * * Hit * * * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 2 2 * Hit
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 2 2 2 * Hit Hit
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 1 * Hit Hit *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 1 1 * Hit Hit * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 2 1 1 1 * Hit Hit * * Hit
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 2 2 1 1 1 1 * Hit Hit * * Hit Hit
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 2 2 2 1 1 1 1 1 7 * Hit Hit * * Hit Hit *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 2 2 2 2 1 1 1 1 1 7 7 * Hit Hit * * Hit Hit * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 2 1 2 2 2 1 1 1 1 1 7 7 7 * Hit Hit * * Hit Hit * * *
First in First Out (FIFO).. 7 1 2 3 4 2 3 3 2 1 2 1 7 1 1 1 1 1 3 3 3 3 2 2 7 7 7 2 2 2 2 4 4 4 * * * * Hit * * * * * 3 3 3 3 2 2 2 2 2 1 2 2 2 1 1 1 1 1 7 7 7 * Hit Hit * * Hit Hit * * * HIT = 5 Miss = 15 Hit Ratio = 25% (5/20)
Belady's Anomaly As we know, the number of BLOCK misses decreases with the increase in number of available blocks, but for some block- replacement algorithms, the block - misses may increase as the number of allocated blocks increases. This most unexpected result is known as Belady's Anomaly . The FIFO Algorithm suffers from this Anomaly. Consider the following reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
BELADY’S ANOMALY 1 2 3 4 1 2 5 1 2 3 4 5 USING 3 BLOCK S