Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Swap is most useful, when you (almost) never look at the swapped out data again.

That might sound stupid, but it occurs often enough in practice: eg code or data structures that were only used when starting off the program in question.

An optimally coded program wouldn't benefit from this. But real world programs often do.



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.


If you hit the swap, there is no disk cache. Which is problematic on its right own.


Huh?

Swapping out unused stuff leaves more space for the disk cache.


disk cache is just 'free memory', when swap is used there is no free memory.

Pretty much any OS (linux, windows, macos) use the unallocated memory for disk cache. Disk swap also takes RAM as page descriptors.


> [...] when swap is used there is no free memory.

Well, that's not true. In Linux you can have pages swapped out to disk and physical memory used for disk cache at the same time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: