4

I'm about to install Linux in an SSD and I have doubts about how much swap space I should allocate.

I have a 1TB SSD drive and 16GB of RAM. I'm not sure if I even need to allocate space for the swap but i have found different opinions on the internet about it.

Pedro
  • 1,891
  • 1
  • 13
  • 23
  • See https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-swapspace#tb-recommended-system-swap-space and https://help.ubuntu.com/community/SwapFaq – K7AAY May 28 '20 at 22:55

2 Answers2

1

It's wise to have swap space setup. From years gone by, the recommendation was to have twice the swap as you had RAM. Now about 1:1 works fine. 16GB is ~1.6% of your total disk space, so probably not a huge amount to spare.

EDIT: Oh, nearly forgot, if you are planning to use suspend to RAM (which you should), then I recommend that you have at least as much swap space as you have RAM, in this case 16GB.

Pedro
  • 1,891
  • 1
  • 13
  • 23
  • 1
    Yes i heard that too. But i also read some articles that didnt recommend to have a swap space at all in a SSD. Why's that? – facuhump May 28 '20 at 21:57
  • 2
    The underlying technology under which SSDs work implies that there's an aspect of wear of the blocks, significantly more impactful on the first generations than on modern hardware. So it got people nervous about it (also I would wager the cost per GB was higher on your SSD than on your RAM stick, so it was worth having more RAM and saving on swap space). People said the same about using full disk encryption on SSDs..... – Pedro May 28 '20 at 22:03
  • 2
    Today though, I don't think it's an issue at all. Disks are more reliable, wear levels are significantly less impactful than before, wear levelling controllers do an excellent job at ensuring you don't get "hot spots", etc. I have been using SSDs on a daily basis for many years now and have never had a failure. – Pedro May 28 '20 at 22:04
  • https://unix.stackexchange.com/questions/433388/swap-partition-maximum-space-function?rq=1 https://unix.stackexchange.com/questions/256622/hibernation-and-swap-partitions-on-ssd-hdd?rq=1 https://unix.stackexchange.com/questions/219231/8g-ram-and-ssd-how-big-should-the-swap-be?rq=1 https://unix.stackexchange.com/questions/218078/linux-ssd-and-swap?rq=1 https://unix.stackexchange.com/questions/215488/linux-swap-space?rq=1 – Pedro May 28 '20 at 22:07
  • 2
    Thank you pedro, so what you say is that with a 4gb of swap it would be ok and i wouldn't probably even use it? – facuhump May 28 '20 at 22:32
  • 1
    If you were to do that, apart from suspend-to-ram (hibernation) you'd be alright for 99% of the time (unless you know you'll be doing really RAM intensive work). But with a 1TB disk, it's better if you do the whole 16G since it may not be as easy to add afterwards if you think you'll need it. – Pedro May 28 '20 at 22:54
  • You can use a logical volume for swap, which makes it easy to resize... – Stephen Kitt May 29 '20 at 06:05
  • @stephenKitt yes that's one of the ways to make life easier. Although if you don't leave spare space on the VG, some shuffling will ultimately be required. – Pedro May 29 '20 at 07:41
0

You should break this down into two steps:

1) Create two or three small partitions, also one 1-2GB for EFI partition, if ever. A partition big enough for hibernation (suspend-to-disk) is also a good idea. A normal size swap would be rather 6GB in your case. It is also possible to activate two (or more) smaller swap devices later.

If you do not use hibernation, then you can use that partition for something else. Same for future swap partitions: if you never use swap, you can format them as data partitions.

2) Try different swap configurations (or: just activate your default one)

Now you can just mkswap one of your small partitions you chipped off the full terabyte, and then swapon.

If you never use EFI, you can use that as emergency swap. If you never use the 6GB as swap, you can put something else there. This takes some configuring, but easier than a partition resize I think.