How to disable zswap in Fedora template and AppVM?

I want to disable zswap and use zram. I hope this will make the mouse freezes less often.

Here is what I tried to disable zswap.

  1. Reinstall Qubes 4.1 with the default settings (Luks, ext4, and thin lvm).
  2. Update whonix-gw. Restart sys-whonix. Update fedora-34 template VM.
  3. Start Fedora-34 template VM and check the content of /etc/default/grub
  4. I see that it points to two files: /etc/default/grub.qubes and /etc/default/grub.qubes-kernel-vm-support.
  5. I added a new line to /etc/default/grub.qubes: GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX zswap.enabled=0"
  6. Run grub2-mkconfig -o /boot/grub2/grub.cfg
  7. Restart the Fedora-34 template VM
  8. Run top in the template VM. I still see the VM has 1GB swap.

That means I didn’t disable zswap in the template VM.

What is the correct way to disable zswap in Fedora template and AppVM?

Thanks.

Turn swap off: swapoff -a.
Then comment out the swap line in /etc/fstab of your template.
Finally restart (or shutdown) the template and check with free -h.

I did the following in the fedora-34 template:

  1. Run swapoff -a
  2. Commented out the /dev/xvdc1 swap swap... line in /etc/fstab
  3. Restart the template
  4. Run free -h. An I still see total: Swap: 1.0Gi

When I run sudo cat /boot/grub2/grub.cfg | grep "zswap", I only see lines with zswap.enabled=0

When I run zramctl, it prints nothing. I think that means zram is not running.

Have you tried (in dom0):

qvm-prefs fedora-34 kernelopts “zswap.enabled=0”

Also check these out:

Also, you had already opened another thread asking the same question: How to disable the swap partition in template and app VMs?

Perhaps they should be merged.

  1. In dom0, run qvm-prefs fedora-34 kernelopts "zswap.enabled=0"
  2. Restart the fedora-34 template
  3. In fedora-34 template, run free -h. It says total: Swap: 1.0 Gi

I thought the answer in the other thread is for Debian instead of Fedora. But feel free to merge the two threads.

What does qvm-prefs <vm name> kernelopts "<kernel options>" actually do? So far it doesn’t seem to do anything to the fedora-34 template, which is using the PVH virtualization mode.

In the fedora-34 template vm:

# list units with names that contain "swap"
[user@fedora-34 ~]$ systemctl | grep "swap"  
dev-xvdc1.swap
swap.target
[user@fedora-34 ~]$ swapon -s   # check if any swap device is active
Filename    Type
/dev/xvdc1  partition
[user@fedora-34 ~]$ swapoff -a   # temporarily turn off all swap devices
[user@fedora-34 ~]$ swapon -s    # check if any swap device is active

[user@fedora-34 ~]$ sudo systemctl mask "dev-*.swap"
Invalid unit name "dev-*.swap" escaped as "dev-\x2a.swap".
Unit dev-\x2a.swap does not exist, proceeding anyway.
Created symlink /etc/systemd/system/dev-\x2a.swap → /dev/null.

# Try to undo the last command
[user@fedora-34 ~]$ sudo systemctl unmask "dev-*.swap"
Glob pattern passed to enable, but globs are not supported for this.
Invalid unit name "dev-*.swap" escaped as "dev-\x2a.swap".
Removed /etc/systemd/system/dev-\x2a.swap.

# Link the dev-xvdc1.swap unit to /dev/null. Nothing can active 
# this unit even if another unit depends on dev-xvdc1.swap.
[user@fedora-34 ~]$ sudo systemctl mask "dev-xvdc1.swap"
Created symlink /etc/systemd/system/dev-xvdc1.swap → /dev/null.

Restart fedora-34 template

[user@fedora-34 ~]$ free -h
         total
Mem:     ...
Swap:    1.0Gi ...
[user@fedora-34 ~]$ zramctl
[user@fedora-34 ~]$

Conclusion:

In the fedora-34 template vm, running sudo systemctl unmask "dev-*.swap" or sudo systemctl unmask "dev-xvdc1.swap" do not disable the swap.

[user@fedora-34 ~]$ systemctl | grep "swap"
● dev-xvdc1.swap                                    masked active active    dev-xvdc1.swap
  swap.target                                       loaded active active    Swaps

Erh. Looks like this is an “ever-swap”. It just won’t die.

sudo sed -i "s|/dev/xvdc1|#/dev/xvdc1|g" /etc/fstab
sudo systemctl mask dev-xvdc1-swap
  1. restart the laptop.
  2. start fedora-34 template
  3. comment out the /dev/xvdc1 line
  4. Run the following to check
[user@fedora-34 ~]$ cat /etc/fstab | grep "swap"
#/dev/xvdc1      swap                    swap    defaults        0 0
[user@fedora-34 ~]$ systemctl | grep "swap"
● dev-xvdc1.swap                                    masked active active    /dev/xvdc1
  swap.target                                       loaded active active    Swaps
  1. Restart the fedora-34 template
[user@fedora-34 ~]$ free -h
               total        used        free ...
Mem:           1.0Gi ...
Swap:          1.0Gi       0.0Ki       1.0Gi
[user@fedora-34 ~]$ zramctl 
[user@fedora-34 ~]$ 

There is one more swap service - dev-xvdc1-swap:
systemctl list-unit-files | grep swap

dev-xvdc1.swap is not the correct name of the service in Fedora. That stack exchange answer doesn’t work for Fedora.

[user@fedora-34 ~]$ systemctl mask dev-xvdc1-swap.service works.

And that also disable swaps in the AppVM and disposable VM based on the fedora-34 template.

Here is what I did:

[user@fedora-34 ~]$ systemctl list-unit-files | grep "swap"
dev-xvdc1-swap.service                     masked          enabled
dev-xvdc1.swap                             masked          disabled
swap.target                                static          -
[user@fedora-34 ~]$ systemctl unmask dev-xvdc1.swap
Removed /etc/systemd/system/dev-xvdc1.swap.
[user@fedora-34 ~]$ systemctl list-unit-files | grep "swap"
dev-xvdc1-swap.service                     masked          enabled
swap.target                                static          -
[user@fedora-34 ~]$ systemctl unmask dev-xvdc1.swap.service
Unit dev-xvdc1.swap.service does not exist, proceeding anyway.
[user@fedora-34 ~]$ systemctl unmask dev-xvdc1-swap.service
Removed /etc/systemd/system/dev-xvdc1-swap.service.
[user@fedora-34 ~]$ systemctl list-unit-files | grep "swap"
dev-xvdc1-swap.service                     enabled         enabled
swap.target                                static          -
[user@fedora-34 ~]$ systemctl mask dev-xvdc1-swap.service
Created symlink /etc/systemd/system/dev-xvdc1-swap.service → /dev/null.

I disabled zswap in a clone of the fedora-35-minimal template.

sudo swapoff -a
systemctl mask dev-xvdc1.swap  # doesn't work
vi /etc/fstab  # comment out the line for swap. doesn't work.
sudo vi /etc/default/grub.qubes  # add zswap.enabled=0; doesn't work
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
systemctl mask dev-xvdc1-swap.service  # this finally works