/swapfile : fstab | SOLUTION : systemd-swap ! Thank You all!

I got rid of my swap partition and created a /swapfile following this procedure : https://wiki.archlinux.org/index.php/swap#Swap_file
I recently saw this : https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/

On the Arch wiki, the fstab instruction is :

/swapfile none swap defaults 0 0

on the ubuntu one : :

/swapfile swap swap defaults 0 0

What is the difference ? What is the most appropriate ?

1 Like
The second field (fs_file).
  This field describes the mount point (target) for the filesystem.  For swap partitions, this field should be specified as `none'.

So the manpage says you should use 'none' for a swap partition.
Don't know whether it's the same for swap files, but I would go with 'none' as well.

1 Like

I don't think it matters what you set the mountpoint to for a swap partition/file. none is what I have always used.

It would be easy enough to test though.

EDIT: So....I tested it on one of my systems. Setting the mountpoint to asshat seems to work just fine. Without going as far as reading the code I would guess it is ignored.


It's also go for systemd-swap and let system handle the size of the swap instead. So no need to edit the fstab at all.

1 Like

Thank you for your advices.
I'll stay with none.
In the meantime I read this : https://superuser.com/questions/172724/what-file-system-is-swap-on-linux that essentially says swap is not a file system :

Swap is no actual file system. It is just a reserved part of the disk that is raw addressable memory with no special structure.

(by the way, /swapfile is included in / that is ext4... (which is even more puzzling)

I also saw this paper confirming the none option : https://www.linux.com/news/all-about-linux-swap-space

It is saying that swap doesn't contain a logical filesystem(on the inside). However, the the swapfile itself is a file and it is part of whatever filesystem the swapfile is in.

A swap file is generally a tiny bit slower than a swap partition, as there's a filesystem layer in between.
As Tids, errr, Fabish :slight_smile: said, systemd-swap can handle all your swap wishes.

1 Like

Do you mean I'd be better of erasing my /swapfile and installing systemd-swap with swapfc_enabled=1 ?
I tried zram a long time ago and... observed slowdowns, is it now good practice to use it through systemd-swap ?

2 very different things.
systemd-swap is more of a service creating and managing a dynamic swapfile for you.
[yes it can interact with zram ... but to my knowledge it doesnt automatically mean you use zram]

Well, I just sat it up. Will see if improvement (or not)
Thank you for having me discovering it :slight_smile:

Adopted !
(zram, zswap, swapfc all set to 1)

You don't really need\want all of them at the same time in most cases. Either use ZRAM alone, or ZSWAP + swapfc.


Well, thank you indeed ! very interesting : the preallocated swap becomes minimal !

~]$ free
              total       utilisé      libre     partagé tamp/cache   disponible
Mem:           5855        1595        2298         205        1961        3757
Partition d'Ă©change:         511           0         511

And I feel a clear impact when opening a great number of apps, is this zswap effect ?

Maybe? As you can see in your free output, the swap file it isn't even used yet, so the memory compressed pool wasn't even full. Most likely placebo effect. Don't expect huge differences, at least from my experience.

In fact, I did a test on another PC of mine : an old HP dv6000 whith 4Go RAM running on Xubuntu
...simultaneoulsy launched 3 Firefox instances, one with a HD youtube video + Gimp and a 2Go image, + Qbittorrent + Filezilla + Thunderbird +Quodlibet.
In the past with a swapfile or yesterday with systemd-swap & zram, this led to lags for several minutes, here, I had no problems, could shift with docky during their startup... Impressive !

Obviously, in limited RAM scenarios and impactful work loads, are where these solutions shine.

But funnily enough, I also have a Pavilion dv6 and wouldn't notice that huge of a difference between normal swap partition and ZSWAP. But then again, I'll rarely have that work load, if ever. So I guess it is very dependent on perception, setup, and work flow.

Indeed it was a test on that dv6000 :wink:

On my production computer (Manjaro unstable HP envy M6 6Go RAM), I'm also impressed :

  • 3 Firefox instances with 20/30 tabs
  • Quodlibet
  • Thunderbird
  • Franz running Whatsapp, Skype, 2 Slacks, Twitter, Linkedin, Riot, Discord (Franz is really handy, but is a massive process eater)
  • /tmp loaded on RAM
    ---> real fluency difference that I cannot class as placebo.
~]$ free
              total       utilisé      libre     partagé tamp/cache   disponible
Mem:           5855        4387         221         781        1247         434
Partition d'Ă©change:         511         128         383

Like a new computer ! :heart_eyes:

[Edit] No slowdown while I work and systemd-swap too :

~]$ free
              total       utilisé      libre     partagé tamp/cache   disponible
Mem:           5855        4591         180         730        1084         292
Partition d'Ă©change:        1535        1168         367
1 Like

Strange thing on my Manjaro :

~]$ swapon -s
Nom de fichier				Type		Taille	Utilisé	Priorité
/var/lib/systemd-swap/swapfc/1         	file    	524284	392304	-2
/var/lib/systemd-swap/swapfc/2         	file    	524284	25208	-3

Is this logical ? (I only have the first line on my Xubuntu)

Swap files on that script, in order to be allocated dynamically, they are created by way of smaller "chunks". When utilization of the current chunk gets to 60% or whatever, another one is created, and so on.

I think that's what you are seeing there.

1 Like

Got the point !

[Edit] Morning start, logically, just one file :

 ~]$ swapon -s
Nom de fichier				Type		Taille	Utilisé	Priorité
/var/lib/systemd-swap/swapfc/1         	file    	524284	0	-2

Forum kindly sponsored by