Swap partition versus swap file

Hi all, how’s life treating ya?

I’ve been seeing this odd phrase, swap file, ever since I installed EOS and joined this forum; I’d never heard of it before and only know swap partitions. Now I’m wondering what the differences really are - and no, obviously I don’t mean the difference between a file and a partition in general; I’m curious as to when one would choose a swap partition, when a file.
Any recommended reading (novice to intermediate level), any personal experiences?

As for my own machines, both have swap partitions the exact same size as the amount of memory, but barely use any of it as I never use hibernation. I could probably shrink them to a few hundred megs :joy:

I use a swap file, very simply created after installation, inside my encrypted root partition.


As for swap size, this is entirely dependent on how much memory your system has and how much you consume with your system applications and workflow. Have you come remotely close to running out of memory? If not a relatively small swap file will probably do.

With systems having more memory these days than most people use, swap size = memory size is a bit out dated.

1 Like

There’s a ton of technical differences, but IMO, it comes down to:

If you have a tendency to install and remove ram, and use hibernate, swapfile is a lot easier than swap partition. If you double your ram, with a swapfile you delete the existing, recreate it as double the size, remake it into swap, and change some UUID’s in files. Done. With a partiton, you need to boot from external media, resize a partition from somewhere to get this extra space, possibly move partitions around to put the free space beside the swap partition, then extend the partition. Major hassle, IF you can even shrink anything to get the space. This is, and was, my primary reason for switching from swap partition to swap file back when I still used HDD’s.

Unless of course you want to use Hibernate, in which case it’s still highly recommended to avoid potential issues.


A swap partition is higher performance but in the real world I don’t think you are likely to see any practical difference.

A swapfile is easier to manage. You can also use tools like systemd-swap which dynamically manages your swap file as needed.

You call also look into zswap and zram.

1 Like


1 Like

ZRAM rocks , no slowing down even with heavy swapping so far :grin: . But no hibernate I guess :man_shrugging:

1 Like

I agree on zram/zswap; works wonders on a 2GB device I have. But I also have hibernation working on it too … (?)

You have zswap .

zram cannot hibernate , because the data will be cleared on power off :joy:

RAM is always cleared on power-off, :joy: -> hibernation works nonetheless (if there is some physical swap to store the contents to).

I played around with zram settings on my first install of systemd-swap to benchmark against the default zswap settings and am pretty sure that hibernation works in both cases. But, this was quite some time ago, so I wouldn’t swear on it :wink: .

The swap-on-zram will have higher priority, thus being favored over drive based swap and I’m pretty sure that if you have two swaps: swap-on-zram, and swap-on-drive, the kernel is smart enough to know it can’t hibernate to a zram device, and will instead use drive based swap.

1 Like