#3432 PR merged: remove zram swap from disklayout.conf

Labels: enhancement

gdha opened issue at 2025-03-18 12:50:

Pull Request Details:
  • Type: Enhancement

  • Impact: Low

  • Reference to related issue (URL): #3343

  • How was this pull request tested? via rear savelayout on a Fedora Silverblue system

  • Description of the changes in this pull request: Avoid having zram swap entry in the disklayout.conf file as it is memory based and not disk based swap.

jsmeix commented at 2025-03-19 07:25:

@gdha
please post here the complete outputs of the commands

# cat /proc/swaps

# swapon --show

on a system that uses /dev/zram* for swap.

I would like to see what the outpout is
when /dev/zram* is used for swap.

I am in particular interested what the swap type is.

As far as I know the swap type is either 'partition' or 'file'.

But /dev/zram* is memory based and not disk based
so it seems it is neither a partition nor a file
(of course disregarding "everything is a file" in Unix).

When the swap type is really either 'partition' or 'file'
then from https://github.com/rear/rear/issues/3343 follows
that the swap type for /dev/zram* must be 'partition'
because if it was 'file' it would have been skipped by

if [ "$filename" = "Filename" ] || [ "$type" = "file" ] ; then
    continue
fi

According to
https://wiki.archlinux.org/title/Zram
it looks as if it could be even correct
that /dev/zram* swap type is 'partition'
because zram is a compressed RAM disk
but the 'lsblk' output in
https://github.com/rear/rear/issues/3343#issue-2646259861
shows that it is not a partition but a whole 'disk'

# lsblk -ipo NAME,KNAME,PKNAME,TRAN,TYPE,FSTYPE,LABEL,SIZE,MOUNTPOINT

NAME       KNAME      PKNAME TRAN TYPE FSTYPE LABEL SIZE MOUNTPOINT
/dev/zram0 /dev/zram0             disk              1.9G [SWAP]

Also the above Arch Linux article also tells that

zram behaves differently than disk swap

but curretly I don't see how exactly it is different
(of course RAM is faster but no persistent storage).

So the actual issue could be that a false or at least
misleading swap type 'partition' is reported which
is not sufficiently backward compatible with the usual
swap type 'partition' for a normal disk partition.

gdha commented at 2025-03-20 10:02:

@jsmeix

root@silverblue:~# cat /proc/swaps
Filename                Type        Size        Used        Priority
/dev/zram0                              partition   1982460     68392       100

root@silverblue:~# swapon --show
NAME       TYPE      SIZE   USED PRIO
/dev/zram0 partition 1.9G 195.6M  100

root@silverblue:~# lsblk -ipo NAME,KNAME,PKNAME,TRAN,TYPE,FSTYPE,LABEL,SIZE,MOUNTPOINT
NAME        KNAME      PKNAME   TRAN   TYPE FSTYPE LABEL        SIZE MOUNTPOINT
/dev/sda    /dev/sda            sata   disk                      15G 
|-/dev/sda1 /dev/sda1  /dev/sda        part vfat                600M /boot/efi
|-/dev/sda2 /dev/sda2  /dev/sda        part ext4                  1G /boot
`-/dev/sda3 /dev/sda3  /dev/sda        part btrfs  fedora_vbox 13.4G /var/home
/dev/sr0    /dev/sr0            ata    rom                     1024M 
/dev/zram0  /dev/zram0                 disk                     1.9G [SWAP]

gdha commented at 2025-03-25 08:30:

@rear/contributors If there are no further objection I would like to merge it upcoming Friday 28/Mar/2025?

pcahyna commented at 2025-03-25 19:03:

@jsmeix

So the actual issue could be that a false or at least
misleading swap type 'partition' is reported which
is not sufficiently backward compatible with the usual
swap type 'partition' for a normal disk partition.

swap type partition is used even for whole disks:

# mkswap /dev/vdb
# swapon /dev/vdb
# swapon --show
NAME     TYPE      SIZE USED PRIO
/dev/vdb partition  10G   0B   -2

so it should be better named block (as it applies to any block device, I doubt that the kernel cares whether the device is a partition or a disk). zram is a block device:

$ ls -l /dev/zram0 
brw-rw---- 1 root disk 253, 0 Mar 25 09:49 /dev/zram0

and thus "like a disk", I don't think that the swap code even distinguishes it from real disks and disk partitions (unfortunately, because otherwise the handling of this swap area could be more adapted to its peculiarities).

pcahyna commented at 2025-03-25 19:10:

@gdha thanks for the fix! A note about the intermediate commit: if you were to change how the list of swaps is being read (I see that in the final version you don't), one could then use the output of swapon --show --noheadings.

Please squash the commits together to simplify the history.

pcahyna commented at 2025-03-28 14:50:

I don't think that the swap code even distinguishes it from real disks and disk partitions (unfortunately, because otherwise the handling of this swap area could be more adapted to its peculiarities).

I realized that this statement is pretty vague, so let me elaborate. zram swap lets you attach a compressed swap space of a given size, but it would be more useful to be able to specify how much maximum RAM should one let zram to use, and let the swap space depend on the compression ratio that is achieved. Perhaps zswap is more suitable for this use though.


[Export of Github issue for rear/rear.]