Can anyone give two examples for LRU and LFU?
1.bad for LRU and good for LFU
2.good for LRU and bad for LFU?
Can anyone give two examples for LRU and LFU?
1.bad for LRU and good for LFU
2.good for LRU and bad for LFU?
LRU bad LFU good
example can be found here: https://stackoverflow.com/a/29225598/7839693
LRU good LFU bad
Let's consider a modified version of that example:
A, B, C, A, A, A, A, B, B, B, B, C, D, C
With LRU we would get something like:
[A]
[A, B]
[A, B, C]
[B, C, A] <- a stream of As keeps A at the head of the list.
[C, A, B] <- a stream of Bs keeps B at the head of the list.
[A, B, C]
[B, C, D] <- here, we evict A
[B, C, D]
[B, D, C]
However, with LFU we would keep A and B, which would result in evicting C and D, which can be seen here:
[A]
[A, B]
[A, B, C]
[A, B, C] <- a stream of As makes the frequency of A = 5
[A, B, C] <- a stream of Bs makes the frequency of B = 5
[A, B, C] <- C = 2
[A, B, D] <- here, we evict C because it has the lowest frequency
[A, B, C] <- here, we evict D because it has the lowest frequency
We ended up evicting C and D with LFU compared to LRU, where we kept D and C
"Least Frequently Used" is the best polycy for page replacement in os !!!
LRU (Least recently used): the process to wich CPU will assign will be the one which is least recently used, in active processes queue.
LFU (Least frequently used): the process to wich CPU will assign will be the one which is least frequently used, in active processes queue.