The following is a hack, and should not be needed, as chances are something is guilty of consuming all your memory besides file system cache.
But this hack will increase the minimum amount of free memory macOS will maintain that should allow running apps some freedom and avoid some spinning beachballs.
Increasing the minimum free memory size:
Applying the sysctl values in the following URL seems to greatly
minimize my macOS Spinning Beach Balls:
https://stackoverflow.com/questions/57674233
I have been experimenting with them, and after a few days, my system
seems to have a lot less Spinning Beach Balls, and the ones I get seem
to be less severe.
Basically add the following sysctl values to /etc/sysctl.conf:
kern.vm_page_free_target=262144
kern.vm_page_free_min=147456
kern.vm_page_free_reserved=16384
kern.vm_page_speculative_percentage=1
vm.vm_page_background_exclude_external=0
vm.vm_page_background_mode=1
vm.vm_page_background_target=262144
vm.compressor_timing_enabled=1
Then reboot.
If you want to just set them for the current booted system, then:
sudo sysctl kern.vm_page_free_target=262144
sudo sysctl kern.vm_page_free_min=147456
sudo sysctl kern.vm_page_free_reserved=16384
sudo sysctl kern.vm_page_speculative_percentage=1
sudo sysctl vm.vm_page_background_exclude_external=0
sudo sysctl vm.vm_page_background_mode=1
sudo sysctl vm.vm_page_background_target=262144
sudo sysctl vm.compressor_timing_enabled=1
and they will go away on the next reboot.
Storing the values in /etc/sysctl.conf will set them after every boot.
You can look at the current values using:
sysctl kern.vm_page_free_target \
kern.vm_page_free_min \
kern.vm_page_free_reserved \
kern.vm_page_speculative_percentage \
vm.vm_page_background_exclude_external \
vm.vm_page_background_mode \
vm.vm_page_background_target \
vm.compressor_timing_enabled