4 ms·
There is a large class of programs that may allocate large amounts of memory, but only work on a small set at once
by guipsp 4y ago
There 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 agoWell simply put any allocation that's not really needed any time soon but is also not freed. Swap let's you use that. 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
- guipsp 4y agoMost programs actually. Compilers, databases, even your browser! I mean, you can argue that they should manage paging out manually, but it's so much easier to use swap and an unmodified program.
- lazide 4y agoNone of those go out of their way to do so, and certainly not databases. Every database tuning documentation I've ever read says avoid swap at all costs. 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?
- guipsp 4y agoI mean, at this point I feel like you're misinterpreting on purpose. I didn't say it would be faster or more reliable, just easier.
- lazide 4y agoNo? I was providing an example. 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.