PDA

View Full Version : 18.04 installs and swapfile size



bobwdn
July 10th, 2018, 12:26 PM
With the new changes to using swapfile in place of a swap partition on installs of 18.04 (server) I have a couple of questions.

I did two test installs on Virtualbox. One with 1Gb of RAM and another with 4GB of RAM to see what size swapfile would be generated during both install. This RAM size was the only difference between the two installs. Everything else I accepted the defaults. After installs both had the same size swapfile of 472Mb.

Then I start searching for 'how to adjust the size of swapfile' and there are too many suggestions that do not agree with one and other. Used 'Allocate' and the next one says 'no, don't use Allocate' use 'dd'! Old version, new version and the list goes on.

The "big deciders" (at Ubuntu) have some sort of plan for this but, what is it?

My questions is this. If the general rule is that server swap should be the same size or larger than the physical RAM then why is the installer only generating 472Mb for both 1Gb RAM and 4Gb RAM install (in this case)? What is the 'best/preferred method' to adjust this swapfile size? Why does the installer script not create an appropriate swapfile size that follows the (considered) standard practice of a swap size the same size or larger than the RAM on the MB?

The documentation on this subject is unclear. See my confusion?

TheFu
July 10th, 2018, 02:17 PM
Servers:
There are many opinions about swap. The old idea of 1-2x the physical RAM is just that, old. It was created when servers had less than 1G of RAM.

I don't want any swap on my servers. NONE. Add more RAM so that no swap is needed or move workloads to another machine. I suppose if I didn't like my customer much, I could go with lots of swap and load up more processes so the machine is constantly swapping instead of performing work. Many cheap shared web-hosting providers do it this way.

If I don't know how much RAM each process will use, then I'll start with 2G swap and monitor the server for a few weeks to confirm if there is enough RAM. Server monitoring is important for many reasons. If the workload seems to change drastically and you didn't add more tasks, then the box is likely hacked, for example.

There are 50 different ways to make a swap file. How it gets sized is up to you. Doesn't matter. But the last step is to use mkswap and add-it/mount-it for use.

In short, defaults aren't always useful. On a server where there is no way for the installation script to predict the actual workload, so starting with a swap that is on the smaller side is something I appreciate.

The answer for desktops is different. For desktops (or if any interactive GUI is running), I have only 1 answer for swap 4.1G. Desktops with less RAM, need more swap just to handle modern, bloated, browsers. Swap will make a system slower as more and more is used, so it provides valuable feedback to the end-user. On systems with more than 4G of RAM, swap is less and less important, but people with 16G of RAM tend to think they'll never run out and use lots of RAM. The slowing down feedback is useful for high-RAM systems. I don't hibernate, ever. I use standby only when moving a laptop around the same building. If I go outside, I shutdown for security reasons.

oldfred
July 10th, 2018, 04:51 PM
This is in my old notes on desktop install:
Ubuntu 17.04 Zesty Zapus
http://www.omgubuntu.co.uk/2016/12/ubuntu-17-04-drops-swaps-swap-partitions-swap-files
Starting from 17.04 Zesty Zapus release, instead of creating swap partitions, swapfiles will be used by default for non-lvm based installations.
no more than 5% of free disk space or 2GiB, whichever is lower.

Since my current drives do have swaps, it automatically finds & uses those partitions.
I did manually configure a swap file on one install of Cosmic.
I used these for reference:
https://wiki.manjaro.org/index.php?title=Add_a_/swapfile
https://devanswers.co/guide-creating-swap-space-ubuntu-16-04/

I was able on next install of cosmic to specifically say not to use my swap partitions, and it automatically created swap file.
On my desktop installs, I like to have some swap, but have had 4GB or more of RAM, and since then almost never have seen swap used.
The only recent reason for larger swap equal to RAM was for hibernation and hibernation is not recommended. Ubuntu boots fast enough that hibernation will not save much if anything anyway.