stockmind / gpd-pocket-ubuntu-respin

Collection of scripts and tweaks to adapt Ubuntu and Linux Mint ISO images to let them run smooth on GPD Pocket
351 stars 35 forks source link

Consider disabling swapfile by default #85

Open mmccool opened 6 years ago

mmccool commented 6 years ago

Swap isn't actually a good idea on devices using eMMC, as it wears them out quickly. By default the Ubuntu installer creates a 2GB swapfile, and also sets up cryptswap (I assume only if you select an encrypted home directory). With 8GB of memory, there is not much chance you will run out of memory unless you are doing something very unusual, so I think it would be better to have it disabled by default.

You can disable it yourself using the instructions at the following locations. Conversely, if someone really wants swap for some reason, they can turn it back on (this will be easier if you just comment out the lines in /etc/fstab, etc instead of removing them). Since a swapfile is used in 17.04, this is pretty easy.

https://askubuntu.com/questions/34519/how-to-disable-cryptswap https://askubuntu.com/questions/912623/how-to-permanently-disable-swap-file

mmccool commented 6 years ago

I should mention booting is faster with the swapfile disabled as well. I suspect this is because it wasn't working: I saw a lot of errors relating to swap with the default configuration.

stockmind commented 6 years ago

Hi! Thank you for the suggestion!

I'm just a bit unsure that the better solution is to disable swap completely (looking around it seems that swap is not mandatory for specific applications and cases, and i try to keep configurations on this repository as generic as possible), but I can limit it to prevent any swap when is useless. What do you think about this? https://askubuntu.com/a/964933 And this: https://askubuntu.com/a/49130 "However I would not say zero swap.

In the unlikely event that you run out of RAM - perhaps opening a big file, perheps a long running tab in firefox, it doesn't matter, in that event your kernel OOM killer will kick in and start killing applications to get memory back. Under those circumstances it's entirely possible that you will lose data as applications get killed. However if you have a bit of swap then the system will carry on, grabbing swap and allowing the system to continue. "

Also can you post a log of the errors related to swap you are getting?

mmccool commented 6 years ago

I will try to see if I can capture the errors. I should have done that before; now I have to re-enable swap to get them ;).

8GB is actually a LOT of memory for this machine; if you run the system monitor you'll see it rarely gets above 2GB in normal usage (web browsing, etc, at least if you have a reasonable number of tabs). In theory I guess if you were running a CAD or imaging program it might be larger, but that's unlikely for most people (and they know who they are...). Swap just delays running out memory, since it is still finite, and slows your system down while doing it. If you have a program with a memory leak it will still crash eventually... [It would be nice if Ubuntu would flash up a notification when swap is excessive, because that would let you know something is going on; maybe there is a way to configure that?]

However, as you note in the links you gave, another reasonable option that still protects the SSD would be to leave swap enabled, but modify the "swappiness" value so that it only swaps in an absolute emergency (eg running out of memory completely). The tweaks in those links you cite seem to be a reasonable compromise.