Hacker News new | ask | show | jobs
by man8alexd 110 days ago
Anonymous memory and files have different access patterns. Files are frequently read sequentially and only once, so there is no need to keep them in memory. When files are read, cached memory pages are put into inactive file LRU first and promoted to active LRU only on the second access.
1 comments

It is possible to unify things behind a single mechanism, yet apply different policies to different instances of this mechanism depending on circumstances and heuristics. We do not need almost entirely disjoint paging systems in the Linux kernel to notice that some kinds of memory have access patterns different from other kinds of memory. Instead of guessing based on whether someone used MAP_ANONYMOUS, we should observe what a program is actually doing.
All LRUs, file-backend and anonymous are handled by the same code. There are some conditionals here and there - executable pages are promoted to active LRU on the first access, locked pages (if I remember correctly) too, but all pages go through the same cycle. See this Linux Plumbers conference presentation https://www.youtube.com/watch?v=0bnWQF7WQP0 with the following slides https://d3s.mff.cuni.cz/files/teaching/nswi161/2023_24/08_li...