Swap partitions?

Hi,

when using Core on all data disks a 2 GB swap partition is created. The advanced menu says:

By default, all data disks are created with the amount of swap specified. Changing the value does not affect the amount of swap on existing disks, only disks added after the change. Does not affect log or cache devices as they are created without swap. Setting to 0 disables swap creation completely. STRONGLY DISCOURAGED

I wonder…

  • why is it discouraged to disable the partition?
  • what should a tiny 2 GB swap space be useful for?
  • if a defective HDD can crash the system, when swap is used? I know that the swap space is mirrored to all HDDs, but still I do not know if errors could be detected this way.
  • why ZFS is not fed with whole disks instead of partitions. Some say future disks may be a bit smaller and could not be added to the vdev, but honestly I’ve never had such a problem.

Thanks!

The SWAP partition is there for if you run out of RAM. I’d recommend you search the internet for something like ‘truenas swap file purpose’ as an example. If you are using SWAP space often, your RAM amount is too small. If you have a lot of RAM, you can elect to create no SWAP partitions, but as you said, it is such a small amount of space so why not just create it? And think about the situation you might be in down the road, you have a failure of the computer, you NEED your data now, but you only have a computer with 8GB RAM. That SWAP partition could be helpful at that time. It’s an example and I am speculate it has occurred more than once.

Anyway, that is the purpose of the SWAP partition.

1 Like

One side effect of having SWAP on data disks, is that it reserves some disk space. That may not seem important, but disk manufacturers can’t agree on disk sizes.

This may mean if you have one manufacturer’s disk, and want to replace it with another manufacturer’s disk, (of the same advertised size), it could be just mega-bytes too small. Having SWAP on all disks may allow “fixing” the issue.

Does that actually happen?
YES.
Perhaps a few times a year I see it in the forums where people are asking what they can do.

(Of course, their are situations where the original disk did not have swap, and the replacement is smaller, even without a SWAP partition…)

The old Sun Microsystems used to use the lowest common size from different vendors, (Seagate, Quantum, Fujitsu, IBM, etc…), as the size for disks they sold. Thus, it did not mater which vendor was used, it could replace any disk in that size bucket. They were exactly the same size, (a simple internal disk configuration…)

5 Likes

Does that actually happen?
YES.
Perhaps a few times a year I see it in the forums where people are asking what they can do.

Really? I honestly never had such a problem and also I’ve checked various disk sizes from my servers: all disks of the same size really have the exact same sizes, no matter if HDD (Toshiba, Seagate, WD) or SSD (Micron, Samsung, Kingston, Seagate, Intel).

I’m really interested if this problem really exists or is just another myth.

That said other “appliances” I use just add whole disks to ZFS (Proxmox, napp-it).
EDIT: I was wrong. ZoL leaves a 8MB “Solaris reserved” partition at the end. Same for OmniOS.

Yes, it really exists. Or did in the past for ME! It’s possible that manufacturers have gotten together and fixed that problem.

And I have seen it in the old forums where someone requested help on that exact issue.

As for my current systems, I have not bought same sized HDDs in a while.

But, the 2 NVMe drives in my desktop are different sizes;

Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: HP SSD EX950 512GB                      
Disk /dev/nvme1n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Lexar SSD

Plus, in my new laptop, the Samsung NVMe and Samsung SATA SSD are different sizes .

Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 PRO 1TB                 
Disk /dev/sda: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: Samsung SSD 860 

For your SSDs this is expected, because strangely enough there are different sizes sold:

  • 240 GB vs 256 GB
  • 480 GB vs 512 GB
  • 960 GB vs 1 TB
  • 1.92 TB vs 2 TB

@Exhorder - Point taken.

Except that not all manufacturers of NVMe & SATA SSDs make similar sizes. So, problems can arise.

And my Samsung NVMe says it is 1TB but is actually smaller that the Samsung SATA SSD which is nominally 1TB. Of course, the “PRO” definition might also mean it is smaller to include more spare space.

@Stux did bring up a very good point that I forgot to mention.

I think we can agree that it is possible (regardless of media type) and I know most of use have seen it, either first hand or someone on the forums having issues that boiled down to a few sectors too few.

If someone disagrees, you can, it is okay to disagree, but it shouldn’t take over the topic.

This problem does exist across the board in terms of device types. During COVID I spun up a computer imaging factory. Essentially I was 'dd’ing .img files to flash drives which could be used to deploy software packages to laptops.

We used a bunch of this one wonderful brand, most of which died for no reason… so I had to buy a bunch more from a different brand. The img file I had created for the first brand was just sliiiightly larger than the new one. Was definitely a stupid headache.

The last two 32GB USB Thumbdives… same model, same manufacturer, were different sizes.

It happens.

When it happens, you set swap to 0GB, add the drive, then put it back to 2GB :wink:

When talking about USB flash drives: agreed! They are all more or less junk. For sure they are not the same size.

I think this is discussed enough. As I’ve said above: If you throw a whole drive to zfs it get’s a 8 MB spare partition at the end on (all?) systems. At least on Linux and Omnios. Sure enough that is exactly for that reason.

Remaining question from first post:

  • What should a tiny 2 GB swap space be useful for? Even on an emergency system with only 8 GB RAM I can recover my data without problems without swap.
  • Can a defective HDD crash the system, when swap is used? I know that the swap space is mirrored to all HDDs, but still I do not know if errors could be detected this way when reading from swap.

To advert a crash due to lack of RAM. This is for emergency use, not expected to be used every day.

I personally have not seen the failure of a SWAP partition take out a system. However if it were a single disk stripe, I could see that happening. Design your system properly to never run out of RAM and it would not be a problem. And I personally have created a pool with a zero SWAP partition value and it ran fine. It was just an experiment, I’m back to a 2GB SWAP partition size. Even with 16GB RAM assigned to my TrueNAS VM, I have seen the SWAP file used for a few KB. But that is only when I’m doing a lot more on the VM than I typically do. If it were something that happened all the time, I’d increase my assigned RAM another 1 GB.

I had this happen. There were issues with swap being used in the past.

Solutions were

  1. my page in swap script
  2. ix started mirroring swap
  3. the issue with swap being used was fixed.

Meanwhile, scale has the issue again.