How to modify swap space on Fedora 36 (Btrfs)?

I’ve recently upgraded from a low-end Intel system to a high-end AMD machine, moving over the same SSD to the new computer without formatting or reinstalling Fedora. I only removed the manually installed intel-media-driver package and assumed that Linux handles everything else.

htop shows that the swap space appears to be constantly “maxed out”, running free -h confirms this:

               total        used        free      shared  buff/cache   available
Mem:            27Gi        14Gi       299Mi       9.6Gi        12Gi       2.8Gi
Swap:          8.0Gi       8.0Gi          0B

The former machine had 8GB of RAM (4/4GB split between the iGU and OS as I understood), the current has 32GB (DDR4 @ 3600mhz). A 2020 opensource.com article recommends setting the swap at ‘0.5 times the amount of RAM’ (for 8GB - 64GB), but the Btrfs filesystem (the Fedora default since the release 33) isn’t mentioned and the instructions are for ext4.

I haven’t found current information for Fedora. Reinstalling the system is one solution and may be worthwhile in any case, but will take a lot of time to set up everything again.

Fedora is using zram, not traditional swap in most cases.

That being said, you shouldn’t need swap at 50% of your RAM for most desktop applications.

Adding more ram shouldn’t be consuming more swap.

You seem to be consuming a lot of memory there with only 2.8 GiB available. Are you running memory intensive workloads? If not, it looks like something is wrong there to me.

  1. Uninstall package zram-generator-defaults
  2. Configure zram. see readme
# /etc/systemd/zram-generator.conf
[zram0]
zram-size = ram / 2

I only removed the manually installed intel-media-driver package and assumed that Linux handles everything else.

The kernel does not automatically install required packages. If your hardware needs intel-media-driver, you have to install it.

You can see the actual usage of swap with the command zramctl.
My system is 32G RAM constantly running at 30 - 50% cpu usage with 2 VMs and this is the output of my swap

# zramctl
NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle         8G  3.3G  1.2G  1.2G      12 [SWAP]

As you can see I have the standard 8G of zram, in which 3.3G swap data is compressed into an occupied 1.2G actual space.

Info about zram on fedora and how to use it is here.
https://fedoraproject.org/wiki/Changes/SwapOnZRAM
The content of my /etc/systemd/zram-generator.conf is here

$ cat /etc/systemd/zram-generator.conf 
[zram0]
max-zram-size=8192
zram-fraction=1.0

That can easily be modified to change the size of the created zram0 swap device.

It is also easy to manually create a swap device on disk if you are set of moving from virtual swap to physical.

BTW, one suggestion above is to remove the defaults package for the zram generator. IMHO that is not required since it only establishes a default config for a new system and the changes you make later are not affected in any way by updates.

1 Like

You can see the actual usage of swap with the command `zramctl

NAME       ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle         8G   8G  7.3G  7.3G      16 [SWAP]

the said file doesn’t exist (but has now been created using the suggested defaults):

# /etc/systemd/zram-generator.conf
[zram0]
zram-size = ram / 2

3 posts were split to a new topic: Understanding my system’s RAM and swap use

I see from that that usage of swap (with 16 threads) is almost maxed out. After making that change to the generator file, did you reboot?
If you did then running zramctl again should show the new size of the swap and it should be ~14G from what the output of ‘free’ showed.