Zswap enabled by default in all VMs?

In this official " How low can you go?" blog post Canonical talks about how they will be able to offer a viable desktop experience for a Raspberry Pi 4 with just 2Gb of RAM thanks to zswap:

Zswap is essentially a compression tool. When a process is about to be moved to the swap file, zswap compresses it and checks whether the new, smaller size still needs to be moved or if it can stay in your RAM. It is much quicker to decompress a ‘zswapped’ page than it is to access the swap file so this is a great way of getting more bang for your buck from systems with smaller amounts of RAM.

Would enabling this by default for all VMs be a good thing (especially since at least for me a lot of time the VMs are using at least some 25% of the swap and even more when run for longer periods of time)? What do you think?

1 Like

I run the snippet below from time to time (as part of a long running shell script) but I think I’ve found it doesn’t do much, in particular, for VMs that use qubes memory balancing, which most of my VMs use.

The snippet currently assumes that the rest of the volatile volume past the 1GB of swap is unused and therefore blindly marks it as swap and adds it to swap. Be aware this may be incompatible with future changes the Qubes team is making w/r/t the uses of the volatile volume.

It appears, to me, that memory balancing supersedes swapping priority and most apps in a memory balanced VM go into an unusable state before swapping can occur.

In any case, this is what I’ve tried:

        if [[ "$answer" = "l" || "$answer" = "L" ]]; then
		# if we want to exclude some VMs, replace excluded-VMs below
		declare -a DispArray=`qvm-ls --running |cut -d " " -f1 | grep -v excluded-VMs | grep -v mirage`
		
		echo ""
		echo "**Setting large swap and enabling zswap for linux VMs"
		
		for val in ${DispArray[@]}; do
			if [ "$val" != "NAME" ];
			then
				kerncheck=$(qvm-prefs "$val" | grep kernel | grep -v kernelopts | grep -v mirage | awk '{print $3}')
				if [ ! -z "$kerncheck" ] && [ "$val" != "NAME" ] ;
				then
					echo -n "-$val-: "
			        	
					xvdc3=$(qvm-run --pass-io $val "sudo swapon|grep xvdc3")
			        	if [ -z "$xvdc3" ];
			        	then
						echo "Making Adjustments"
						qvm-run $val "sudo sh -c 'sync ; echo 1 > /proc/sys/vm/drop_caches'"
						qvm-run $val "sudo mkswap  /dev/xvdc3 && sudo swapon /dev/xvdc3"			
						qvm-run $val "sudo sh -c 'sysctl vm.swappiness=60'"
						qvm-run $val "sudo sh -c 'echo lz4hc > /sys/module/zswap/parameters/compressor'"
						qvm-run $val "sudo sh -c 'echo 20 > /sys/module/zswap/parameters/max_pool_percent'"
						qvm-run $val "sudo sh -c  'echo 1 > /sys/module/zswap/parameters/enabled'"
					else
						echo "Previously adjusted."
					fi
				fi
			fi
		done

               echo "$message"
        fi

How much RAM do you have on your system and how much do your VMs take up usually?

32GB and usage varies by task.