It's the use cases that make a difference.
It's the use cases that make a difference.
1. Makes claims about performance 2. Provides no benchmarks
The only concrete answer to "why have swap if I have enough RAM" is "well, if you run out of RAM..."
The only time swap isn’t just delaying (and growing) the inevitable shitshow is when, for some reason:
1) some program is consuming some significant amount of Ram, but doesn’t need to run for awhile, and it’s somehow faster/easier to let it swap to disk than shutting it down and restarting it while you do something else that consumes Ram.
2) something you’re running has some amount of bloat or leak that you know will never get exercised, but also never will grow larger than your swap file and take your system out entirely.
Both of those situations are not only rare, but easy to misjudge and end up wedging your system.
And then compilation eventually finishes and the allocated memory is released on process termination.
Disk cache is really flexible at the OS level. Look up 'vmtouch' on Linux and play with some recently used files, you'd be surprised how many are in memory. If you don't have swap and only have 'X' amount of RAM free the program will still load and run fine, it'll just do so in a way that more directly thrashes the disk. If you add some swap the OS will page out some other memory that's not being used giving 'X+Y' RAM free for disk caching that the OS will use.
In fact this usage of free memory as disk cache is so ingrained that memory used this way doesn't even appear allocated. OSes are pretty much all designed to use whatever free RAM is available as disk cache. The disk cache shrinks if that RAM is actually needed.
Effectively a great way to think of swap is that your OS is always swapping, even without a swapfile! If you read a file there's swapping of that file into memory, it's even done using the standard memory paging that swap files do. Without a swap file you still have swapping but you've just removed the ability for the OS to write out memory that it thinks is less relevant than the files you're currently trying to read. Which is almost always a loss.
Technically a program, but not what I think anyone typically considers one in this context?
What other ones are you aware of?
I ask because generally programs use RAM because it’s fast - otherwise they’d use something else. Having a program intentionally allocate more than is available would almost certainly result in serious performance issues it would have a hard time dealing with predictably - as compared to using disk for the ‘excess’, and then reading/loading what it needs.
In terms of what benefits from that most modern programs are actually surprisingly flexible in memory allocation. Anything with a garbage collection behind the scenes will flush more often if needed. Having swap to push the non needed programs out let's GC based programs keep allocations longer which is intended to enable reuse
Some just allocate when they need it until it doesn't work (cough Chrome cough), but that is a far, far throw from intentionally allocating more memory than the machine has, and none of them seem to do it to intentionally only work on a small subset at a time, even if de-facto that is what happens.
What sort of performance or reliability would you expect anyway from a database that intentionally loaded the entire database into memory first without even caring how much would fit?
Every database I’ve ever dealt with has fixed memory limits that get set.
Otherwise the database server will OOM even with swap if it doesn’t limit memory consumption and how much it loads, on any machine, with a given large enough database. And the size of the database is up to the user.
It’s a fundamental part of the problem.
Speed and reliability to some extent are literally core requirements of database servers, so any database software that doesn’t do it is going to have a bad time.
Linux with swap available can swap out never used pages (say a part of library that never gets called) and use freed memory to cache disk IO. We see that on every server that has enough data to fill the remaining RAM with page cache. But you only need like a gig of swap to take advantage of it.
The OS will page in files that are being accessed regularly. Without a swap file you don't stop the OS swapping between memory and disk, that'd be pathological since disk access is that much slower.
Instead what not having a swapfile really means is that you are telling the OS "anything allocated ever on the system is more important than disk cache".