3 ms·
I wouldn't link the usefulness of swap to the quality of programs. It has a lot to do with user behavior. If a user opens 100 tabs in a web browser but never lo
by mytherin 6y ago
I wouldn't link the usefulness of swap to the quality of programs. It has a lot to do with user behavior. If a user opens 100 tabs in a web browser but never looks at most of them, swapping unused ones to disk if they don't fit in RAM anymore is a very useful behavior (considering the alternative is killing the entire program).
You could argue an optimally coded program should do this themselves, however, that is not so easy when multiple programs are running concurrently and fighting for RAM. On an 8GB machine, how much RAM should your web browser use? The answer is "it depends". If there are no other programs running, it can use all 8GB. If you are running an IDE, a chat client and a compiler in the background, it should probably be using less.
The individual programs don't have enough information to make this judgement call - and making very conservative estimates will lead to much more swapping than actually required. The operating system is in charge of allocating memory for all those programs and can effectively make the judgement of what should be swapped out or not.