I am reading OS Design: Three Easy Pieces, and I stumbled upon this quote in chapter 19: Translation Lookaside Buffers. It talks about eviction policies and comparing the hit efficiency of LRU vs. a random selection eviction.
Such a policy (Random policy) is useful due to its simplicity and ability to avoid corner-case behaviors; for example, a “reasonable” policy such as LRU behaves quite unreasonably when a program loops over n + 1 pages with a TLB of size n; in this case, LRU misses upon every access, whereas random does much better
I think I understand why LRU misses upon every access. For example, take an empty TLB of size 3 pages and a program loops through 4. The first page access is a miss, then second is a miss, then the third, then the fourth one is not in the TLB, so we must evict the least recent one (first page). After that eviction, we repeat the TLB lookup to finally get the fourth page in it, giving a total of four misses, but now how does the Random eviction work? Let's have the same empty TLB and program. We miss one, two, three pages. Now the fourth ought to be in there, so we have to replace a random page this time. So we repeat a TLB lookup and now the fourth page could be in the first, second or third TLB entry. Doesn't this just lead to four misses as well?
Where in my assumptions and logic about how TLB and evictions work am I missing here that random is better than LRU with this corner case. Doesn't random also just miss the same amount?
A step by step explanation of each policy would be preferable. Thanks.