Quote:
Originally Posted by keiths121
What does that mean if it is cached? Does that mean it will be freed if there is a need for the additional memory?
|
In simple cases yes. In complicated cases, it depends what you mean by "need".
The system might swap other memory to the swap file in preference to releasing memory from cache. The algorithms are pretty good, so when it swaps in preference to releasing cache, that is usually the best choice. But may people misunderstand and think it is always wrong to swap in preference to releasing cache, and they take misguided steps to prevent the system from doing so.
So if "need" means the system really needs that memory (can't manage without it) then it absolutely will take it from cache. But if "need" means the system needs to take memory from somewhere and has a choice to swap or to take it from cache, the system will make a good choice. Most of the time that good choice is to take the memory from cache, rather than swapping. In the less common case that good choice is swapping, it is likely to still be a good choice, even though that may be hard to understand.
Notice in the example I quoted 90MB of swap space is in use even though 3146MB of memory is "free" including cache. When it wrote that 90MB to the swap area, I'm sure less than 3146MB was "free", but I'm sure quite a LOT was "free" (used by cache) and the system correctly swapped rather than taking from cache. I think that swapping happened long before I used that free command, yet the swap space was still in use. That implies the sleeping tasks that own the swapped memory haven't touched it since it was swapped.