I have an Ubuntu 20.04 desktop system with 16 GB of physical memory and 8 GB swap.
After some uptime and somewhat heavy usage, I noticed swap space was almost fully used while physical memory was just below 50%. Consistently with that, I noticed poor performance when returning to applications that had been in the background for longer, complete with disk chatter – so apparently the system was busy reading memory pages from swap.
I then tried to force everything back into physical memory by running swapoff -a; swapon -a
(which briefly brought memory usage just above 90%). However, as soon as swapping was back on, I noticed the system immediately started moving pages back into swap until swap usage was at about 60%.
This looks kinda inefficient to me and I would prefer data to be kept in memory while stocks last, to avoid the overhead of reading pages from swap when I need them again.
How can I influence this behavior? I have seen the swappiness parameter being mentioned, but as I understand it, that just gives the system the order in which pages are to be evicted from physical memory, not how soon to start evicting pages.