0

I am reading some tutorials about swap for Ubuntu and in general for other distributions. Mostly from:

From there, it refers to other valuable tutorials of the same domain, of course all about swap, among them the information is well covered and very well explained.

According with them: if the PC/Laptop has either 8GB or less is recommended use swap how a dedicated partition - it normally x2 of the current RAM capacity available (mostly when Hibernating is applied). Until here I am ok for some laptops and old PC Desktops. Be aware, they have HDD about their hard-disks.

Something of my concern is that use swap impacts the SSD's lifespan, so is suggested use swap file instead. It is suggested for other scenario about to avoid resize the swap partition

So until here swap file is valuable for:

  • Accomplish a manual administration about the swap size without a partition being involved and to avoid harm the SSD lifespan

So I want to know if is a recommendable apply the swap file approach for these PC/Laptops with either 4GB and 8GB of RAM - currently they have HDD but some of them would be upgraded to SSD when themselves passed/gone away

The goal is have one standard approach and avoid use the swap partition. I think the manual administration is flexible than a raw/fixed partition.

Therefore:

  • Is wise and safe use swap file for PCs/Laptops of 8GB or less?

it without matter if the hard disks are currently either HDD or SSD.

About SSD Lifespan

This case is mentioned here:

muru
  • 207,228

3 Answers3

1

Personally i prefer swap files, for the same reason you already stated. Creating a smaller or larger swap file is much easier than resizing a partition.

One of my PCs has 8 GB RAM, is running Ubuntu 20.04, and has no swap space at all. You might want to consider this as an option. Depending on what you are doing with your PC, you might be fine just without swap space.

If you are worried about your SSD wearing out due to swap activity, you can reduce this by lowering the swappiness. See this FAQ.

Sheldon
  • 467
1

The Default in New Install

Ubuntu uses a swap file in all new installation by default since version 17.04.

Ubuntu installation does not change this default based on whether you install Ubuntu on a SSD or a HDD.

Therefore I conclude that it is safe and wise to use a swap file with a SSD and a HDD.

Other Issues

SSDs are Fragile

There is a lot of information on the web on how SSDs are fragile and will breakdown with excessive writes (and reads). There is a recent report that finds the SSDs are as reliable as HDDs. The specifics are sparse and this may only be strictly true for enterprise/server grade drives.

Alternately one can look at original manufacturer warranties as another metric of reliability of SSDs. the consumer grade (cheap ones) SSDs and HDDs come with 3 years of warranty. This tells me for normal use the issue of an SSD breaking down may not be a problem.

How Much Swap

This topic has been hashed to death as well. Here is my two-cent's worth. The swap size is often linked to the RAM size with various rules of thumbs. What is often lost in translation is the size of swap depends on the use of the computer.

I will give you a personal example. I have a desktop with 32GB of RAM and 8GB swap (in SSD). Yet once (and only once) I managed to run out of swap. I was working with a number of large datasets in R. The code I wrote kept on loading various datasets in RAM without unloading them when they were not needed anymore. In this case, it was just bad coding practice on my part. My stopgap solution to add another 64GB of swap and run the "bad" code again. This time it worked and I got the results I needed. I fixed the code later.

Hope this helps

user68186
  • 37,461
1

One more little-known use of swap: When you install a newer executable while the old one is still running, the old image can no longer be unloaded from memory, and it has no disk backing. The kernel will relocate the old executable image to swap, so it can be memory managed normally. When the old executable finally finishes executing, the memory and the swap space backing it are freed.

Without swap, the old executable would either have to call all its pages into memory, or it would have to be killed. Otherwise it would have to be stopped in order to be replaced, and the system would have to be brought to single user mode to do package management.

Swap lets you install new packages while services are running, and to wait until installation is over to bounce the service to pick up the update.

Source:https://haydenjames.io/linux-performance-almost-always-add-swap-space/

Joepie Es
  • 1,570