On Sat, May 02, 2020 at 10:12:08PM +0800, William Kenworthy wrote: > I am afraid this is an ".. it depends" question. >
Yes, I agree. > If you work with large images or data sets, swap can be really handy. > If you are doing a little programming, web browsing, reading email you > will *probably* be ok, but why risk it? > Risk what? Having the OOM killer kill the problematic process? Depending on your usage, this might be the best. Personally I prefer that to a system that is stuck. I never had to force reboot on a system without swap, whereas with swap I had to reboot most of the times swap was used. Also it's super annoying when your system freezes because of a background process swapping (eg. an emerge world update) while your doing something else. I've been running a 8GB system for a year, before that a 4GB system. Both without swap. It's been fine so far. I did have processes killed (eg. firefox compiling), but at least I can continue to use my system without being interrupted by a freeze. It's a lot less frustrating to have to resume a killed compilation than to deal with a frozen system. > I have a 32gb ram in a master server for an mfs filesystem - it normally > sits at about 5GB of ram - however it can go well over 32Gb into swap at > times - the first machine I tried it with only had 4gb ram and crashed > when it filled the ram, and 8g swap taking the test file system with it > - its now production so I am not going to risk it by underprovisioning > swap. My 32Gb desktop is not using any swap at the moment ... but it > has used it at times. > > So, yes its quite likely you wont use swap - but if you do something > that needs it, it can help avoid a very messy crash. > > Swap is slow, but if you actually need it - its probably critical that > you have it! Unless you are really short of disk space, treat it as > insurance :) > > Look into using swapfiles instead of partitions for flexibility, and the > sysctl values of "vm.swappiness" and "vm.vfs_cache_pressure" to manage > swap usage (you can set to not use swap until it really has to - some > have seen the kernel being too eager to swap out causing slowdowns, > though you can make it go in the other direction and "thrash" when it > actually needs to use swap if you go to far. The default kernel swap > mechanism isn't really that bad! > Swapfiles are great, because you can only add them when you need and remove them when you're done. I sometimes use them when emerging large stuff when I have other big processes in memory. > So yes, most of my machines don't need swap *right now* and swap looks > like its not being used so it could be removed, but I cant guarantee > that they never will, and having years of experience using swap I > recommend that its better to be cautious and survive :) My systems usually survive (are not forcibly rebooted) better when there is no swap. But I agree that in the end, it depends on the usage.