3 ms·
Unused ram is wasted ram.
by artifact_44 6y ago
Unused ram is wasted ram.
- franga2000 6y agoIt's not nearly that simple: power consumption, other processes, future processes... are all factors in deciding how much RAM to use and a userspace application simply can't know enough to decide that. And what do you do if it overestimates and you actually need that RAM for something else? The OS doesn't know enough to decide which pages to swap out and swapping isn't the right solution anyways as now your app thinks its cache is in memory but it's actually on the disk. But the OS can't just deallocate pages since it doesn't know which are important. There's a pretty elegant solution to this that basically all OS use these days: the OS can use additional memory as a disk cache, since IO is still the biggest bottleneck on most systems. Apps can request a file to be cached too (see man 2 readahead), so there's no guessing involved and the app can cooperate with the OS instead of assuming it's the only thing that is or ever will be running and eating up qll resources accordingly.