Why LRU is better for replacement of file buffers in the buffer cache?

525 Views Asked by At

Can someone please explain why LRU is not considered practical for a page replacement algorithm, it is perfectly acceptable for replacement of file buffers in the buffer cache.

2

There are 2 best solutions below

0
haramq On

LRU has a way of using Counter. We use the CPU clock to check the time each time a page call occurs. So, if page replace should occur, you will choose the oldest one. This method has the disadvantage that whenever the replacement occurs, the oldest page in the page table must be found and the time of the page must be changed every time the page table is changed.

0
Matt Bryant On

For an LRU policy to be successful, you want a use-case with good temporal locality (recently used objects should be reused) and an easy way to track when objects are used. Both files and memory fit the first criteria. Files also fit the second criteria - the user will typicall do a system call to access the desired data, making it easy to update the LRU. However, there's no cheap way to mark when memory is accessed, as the operating system is typically not involved in memory accesses. This leaves a page replacement system unable to easily determine ordering.

A possible workaround for this would be to approximate LRU via NRU (Not Recently Used), where pages are occasionally set to fault on access and use tracking is done in the fault handler.