Put swap on SSD or HDD?
Solution 1
A swap partition on your SSD will let you wake up faster from hibernation (aka "suspend to disk") as compared to swap on a hard drive. But given the incredibly fast boot time of Ubuntu when booting from SSD a wake up from hibernation may be slower than a reboot.
If you do not hibernate you may never need to swap at all.
Only in case you often have very many RAM intensive applications running in parallel, your system may eventually use swap. Then a swap on SSD will be somewhat faster than a swap on a hard drive. Still there is no need to worry about wearing of your SSD from extensive swapping.
If not used for hibernation you can alway add a swap partition or swap on file later:
- How do I add a swap partition after system installation?
- Adding a new swap file. How to edit fstab to enable swap after reboot?
Solution 2
Apart from the other great answers, I just wanted to ask that you can have more than one swap partition. So you could put 4GiB of swap on the SSD and the rest in the HDD so if you need to swap something during your computers usage it goes to the fast swap. If you hibernate, probably the SSD swap won't be enough and you'll need the HDD swap too.
To do this, you'll need to create one swap partition in each disk, and once installed you'll need to open /etc/fstab
so your system gives preference to the fast swap. So open a terminal and execute sudo gedit /etc/fstab
. You'll need to locate the pair of lines referencing your swap partitions, and edit them to add the pri
setting (a higher number on the fastest disk):
# before
UUID=some-large-number none swap sw 0 0
UUID=another-large-number none swap sw 0 0
#after
UUID=some-large-number none swap sw,pri=10 0 0
UUID=another-large-number none swap sw,pri=20 0 0
You need to know which of this is in the fast disk and which on the slow disk. Executing the blkid
on the terminal will help you identifying each one.
Solution 3
SSDs are faster (although speeds decrease in time here too) but also have a smaller lifespan. Before making this choice think about the swapping habits of your distro.
Correct me if I'm wrong but this setup is your home PC, right? With 16GB I really doubt that you'll be doing much swapping especially since for example hibernation rarely works properly and is disabled in Ubuntu by default.
As an alternative to a swap partition you can use a swap file. The huge advantage with the second is that it can grow and shrink according to your needs where a partition is usually harder to deal with especially if it is between two other partitions and there is no space left.
Read here for more information on SSD for swap space:
For swap size see:
Solution 4
Personally with 16gb of memory to your disposal I wouldn't even bother with a swap partition... Just make sure that you add the following line to the end of the /etc/sysctl.conf file and things should run as normal:
vm.swappiness = 0
...save and reboot and no swap needed... I use this for my 2gb machine and never had a problem or slowdown since...
Related videos on Youtube
user197088
Updated on September 18, 2022Comments
-
user197088 about 1 year
New installation coming up. 120gb SSD for OS and HOME and 1tb HDD for storage. 16gb of ram which means 16gb of swap if I recall correctly. SSD space is too valuable for a swap partition right? If my thinking is correct can someone guide me through or point me in the right direction for putting a swap partition on a second hard drive? I have always selected the automatic settings when installing ubuntu. Thanks!
-
Daniel W. about 10 yearsI would suggest the same thing. I have 8gb RAM on my thinkpad and the only time swap even got activated so far was while running 2 virtual machines and eclipse side by side...and that took up about >100mb swap (while there where still ~2gb RAM available)
-
Paddy Landau about 10 yearsHowever, if you intend to hibernate, then you will need swap.
-
user197088 about 10 yearsThanks for your response. I don't think I will be hibernating if boot times are as quick as I have read. Thanks again!
-
user197088 about 10 yearsI don't plan on hibernating any with the implied boot times I have been reading. The 16gb of ram is due to this being a light video editing rig. Not sure yet if it will max out the ram.
-
thebugfinder over 8 yearswell, hibernation is not about booting fast, but about preserving state.
-
unfa over 6 yearsFor security, I would strongly suggest to never go without any swap. Doing one mistake like running something RAM-hungry when you're low on memory can bring your whole system down if you don't have swap. For lightweight home use it shouldn't be too much of a hassle, but if you do anything more advanced - have some swap just in case, it doesn't hurt you, but can save you some unplanned reboots.
-
jave.web about 5 yearsIn 2018, 16GB can be exhausted pretty quickly... As it could be in 2013 anyways.