We could always disable swap but this would normally be a bad idea unless you have an incredible amount of RAM and a workload that will never exceed it. However, for live/containerized and high performance environments it could be desirable.
Another middle ground may be to set swappiness to a lower number.
swappiness is a numeric value between 100 and 0, with 100 being the most aggressive and 0 being the least likely to swap.
Here is an example on Ubuntu 20's defaults:
We can see it is currently at level 60, which is a slight bias toward swapping more aggressively.
Just enter the numeric value and echo it into the swappiness entry under proc.
echo 30 > /proc/sys/vm/swappiness
How can we make the change permanent?
Edit /etc/sysctl.conf and add this:
linux, swapping, swappiness, swappingwe, disable, swap, ram, workload, exceed, containerized, environments, desirable, kernel, cache, unnecessarily, clearing, buffers, aggressively, passively, numeric, aggressive, ubuntu, defaults, proc, sys, vm, currently, temorarily, echo, entry, edit, etc, sysctl, conf,