Swap. what is recommended

hey all, on a fresh :enos: install on ext4 do you recommend a swap file or a swap partition.
what are pro’s and con’s ?

i should urgently reinstall my desktop, i have already backed up everything i want to use again. just have these questions about swap

This is how it looks now.

❯ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 931,5G  0 disk 
└─sda1        8:1    0 931,5G  0 part /srv/nfsv4/Share
                                      /run/media/swh/Mediathek
sdb           8:16   0 931,5G  0 disk /srv/nfsv4/Filme
                                      /run/media/swh/Stuff
sdc           8:32   0 223,6G  0 disk 
└─sdc1        8:33   0 223,6G  0 part /run/media/swh/SDD
sr0          11:0    1  1024M  0 rom  
nvme0n1     259:0    0 232,9G  0 disk 
├─nvme0n1p1 259:1    0   300M  0 part /boot/efi
└─nvme0n1p2 259:2    0 232,6G  0 part /

i plan to mount the home partition in an internal ssd

You could check out a third alternative, Zram.
There are probably other advantages, but I use it mainly because of the ease and simplicity. No need to mess around with partitions or swap files.

4 Likes

Thank you! I did not know about this possibility. one never stops learning :wink: this looks like a simple but effective solution to me
if i understand correctly i install zram after installation.

1 Like

Yeah. You choose “no swap” during the EOS installation. When you’re up and running you just install the package and write the config, as described in the tutorial.

2 Likes

i will try that. thanks a lot

1 Like

I prefer a swapfile because of flexibility. But I use zram as well so that I have

NAME           TYPE      SIZE USED PRIO
/swap/swapfile file       18G   0B   -2
/dev/zram0     partition 7.5G   2G  100

where my main memory is 16 GB.

1 Like

My main memory is 16gb like yours. I will definitely choose ‘no swap’ during installation. I then install zram
i just notice that the pc, as it is configured now, is completely busy as soon as i do any video editing with handbrake
now i use a swap partition with 8gb

1 Like

In that situation, wouldn’t zswap be a better choice?

2 Likes

Thanks for asking. I have to admit that I had started with zram alone and then later having added a swapfile. Now, when thinking deeper you might be right as zswap seems to be better when swapfile is used additionally.

So, I have to re-evaluate

3 Likes

It all depends on the amount of physical RAM one has at hands. For 16GB and more, I would always recommend using Zram or Zswap, respectively.

1 Like

https://chrisdown.name/2018/01/02/in-defence-of-swap.html

:+1:t3:

2 Likes

When looking at zswap it seems that when enabled

  • swapon doesn’t show it
  • the only information about its parameters seems to be something like grep -R . /sys/module/zswap/parameters
  • the only information about its activity seems to be something like grep -R . /sys/kernel/debug/zswap/

Is this true?

1 Like

Try out swapon --show

:v:

1 Like

swapon --show doesn’t make a difference

1 Like

dmesg | grep zswap ?

1 Like

This shows

 dmesg | grep zswap
[    0.623013] zswap: loaded using pool lz4/z3fold
1 Like

And…

dmesg | grep swap

My current VM shows this:

dmesg | grep swap

[ 0.144028] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[ 0.917340] zswap: loaded using pool lz4/z3fold
[ 33.242568] Adding 4343804k swap on /dev/sda5. Priority:-2 extents:1 across:4343804k FS

https://wiki.archlinux.org/title/zswap

On bare-metal I keep using Zram.

1 Like

@swh

PS:

Some people use zram in combination with disk-based swap, and some people use zram exclusively.

Personally, I’ve never encountered situations where disk based swap was needed beyond zram. If you encounter it, it should be easy enough to set up a swap file.

2 Likes
 dmesg | grep swap
[    0.191318] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.623013] zswap: loaded using pool lz4/z3fold
[   10.654784] Adding 18874364k swap on /swap/swapfile.  Priority:-2 extents:5 across:544473088k FS

I think my answer to my question above about getting information regarding zswap active settings and statistics seems to be reading /sys/module/zswap/parameters/* resp. /sys/kernel/debug/zswap/.

This means that if I want to have a command line interface I could write a script or program to deal with these directory contents.

2 Likes

I might be wrong but the way I understand zswap is that it isn’t really a swap “device” in the way a swap partition, a swap file or zram is. That might be the reason why it doesn’t show in swapon -s.

It is a kernel feature and is enabled by default so there is no need enabling it. However if one uses zram, it needs to be disabled.

3 Likes