The officially official Devuan Forum!

You are not logged in.

#1 2021-10-09 21:15:13

nobodyuknow
Member
Registered: 2017-09-10
Posts: 173  

[SOLVED] swap using file rather than partition

In "How Linux Works" (chapter 4), the author noted that a file, instead of a partition, can be used for swap. I could see how this could be useful for installing Devuan after Windows to create a dual-boot, in other words, only having to worry about creating one extra partition. Is there any performance difference between partition-swap and file-swap?

P.S. In my first draft of the above, I wrote "duel-boot" instead of "dual-boot," which is probably more accurate. :-)

Offline

#2 2021-10-09 23:06:06

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] swap using file rather than partition

Test for yourself to determine any performance difference but I don't think there is any.

@p.H over at the Debian forums maintains that swap files are a dirty hack because swap is designed to operate on block devices and they seem to know what they're talking about (and certainly more so than me). The fact that btrfs has only recently gained the ability to support swap files would seem to confirm this.


Brianna Ghey — Rest In Power

Offline

#3 2021-10-09 23:59:12

steve_v
Member
Registered: 2018-01-11
Posts: 329  

Re: [SOLVED] swap using file rather than partition

nobodyuknow wrote:

Is there any performance difference between partition-swap and file-swap?

On an SSD, probably not, assuming you're using a non-exotic filesystem. On a mechanical HDD, the traditional reasons for using a swap partition are avoiding fragmentation (and thus expensive head seeks) and the ability to place the swap partition on the fastest part of the disk (pi and RPM vs linear velocity and all that).

Head_on_a_Stick wrote:

@p.H over at the Debian forums maintains that swap files are a dirty hack because swap is designed to operate on block devices and they seem to know what they're talking about.

It certainly was, and he sure does.
My (admittedly fairly limited) real-world tests don't show any performance penalty for swap files though, at least not on an ext4 formatted SSD. Swap files have been a thing for many years, so I'd expect most of the bees are ironed out by now.

Head_on_a_Stick wrote:

The fact that btrfs has only recently gained the ability to support swap files would seem to confirm this.

TBF, BTRFS is a COW filesystem. Swap files on COW filesystems are always going to need explicit support from the FS, and are always going to be a hack.
If running BTRFS (or ZFS), I'd go with a swap partition any day. Ideally more than one and on different devices so they can stripe.


Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

Offline

#4 2021-10-10 08:39:01

Camtaf
Member
Registered: 2019-11-19
Posts: 408  

Re: [SOLVED] swap using file rather than partition

Unless you are really short of memory, (i.e. 1GB or less), & only use it as a standard desktop type of system, you don't even need swap.

I run Devuan on an old 1GB ram laptop, & I give it 2GB of swap, it works well enough as a basic machine, it even goes online with Firefox, if a little slowly, but perfectly usable. Two other old laptops with just 2GB ram, I don't even bother with swap. smile

If you have a laptop, & want it to hibernate, you will want a swap partition of equal size to your ram.

Last edited by Camtaf (2021-10-10 08:39:51)

Offline

#5 2021-10-21 11:57:17

NicePics13
Member
Registered: 2019-09-13
Posts: 14  

Re: [SOLVED] swap using file rather than partition

It's very easy to hang your entire system when browsing the modern web on a 2GB RAM (or less) PC without swap. Even Raspberry Pis have a 128MB swapfile as standard on the SD card.

Offline

Board footer