5 ms·
Swap or no swap: https://haydenjames.io/linux-performance-almost-always-add-swap-space/ https://haydenjames.io/linux-performance-almost-always-add-s... It's th
by dschuetz 4y ago
Swap or no swap: https://haydenjames.io/linux-performance-almost-always-add-swap-space/ https://haydenjames.io/linux-performance-almost-always-add-s...
It's the use cases that make a difference.
- bloaf 4y agoThat is an article which 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..."
- lazide 4y agoIf you use swap because you don’t have enough RAM for things you need in RAM, you’re going to have a very bad time. 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.
- leni536 4y agoI found that gcc works mostly alright on swap for compiling C++. I assume that data structures for template instantiations are never really deallocated, and it often falls into category 2 of your deacription. And then compilation eventually finishes and the allocated memory is released on process termination.
- guipsp 4y agoThere is a large class of programs that may allocate large amounts of memory, but only work on a small set at once
- lazide 4y agoSuch as?
- AnotherGoodName 4y agoDisk cache for one. 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.
- lazide 4y agoThat is temporary and evictable kernel memory usage. It also isn’t allocating more memory than it has while doing it, it evicts things when it runs out of unallocated memory. 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.
- AnotherGoodName 4y ago
- Dylan16807 4y agoChrome does both of those. It takes gobs of memory that won't be needed for many hours, and it takes gobs of memory that will never be needed but are roughly stable and won't overwhelm a suitable swap file.
- xani_ 4y ago> The only concrete answer to "why have swap if I have enough RAM" is "well, if you run out of RAM..." 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.
- AnotherGoodName 4y agoYep the lesson a lot of people who claim 'no swap is better' need to learn is that your OS is always swapping, even without a swap file. The lack of swapfile just removes some flexibility in how that's handled. 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".
- mediaserf 4y agoHere is a great break-down of how linux swap actually works: https://www.linuxjournal.com/article/10678 https://www.linuxjournal.com/article/10678