How to Find Which Processes Are Using the Most Swap Memory in Ubuntu

When your Ubuntu system runs out of physical RAM, the Linux kernel begins moving inactive memory pages to a designated “swap” space on your hard drive or SSD. While swap space prevents your system from crashing due to an Out of Memory (OOM) error, reading and writing to a storage drive is significantly slower than accessing RAM. If your system begins relying heavily on swap, you will experience severe performance degradation, often referred to as “thrashing.”

If you notice your system slowing down and standard tools like free -m or htop show high swap usage, your next step is identifying exactly which processes are hoarding that space. Standard monitoring tools often obscure swap usage per-process, but you can uncover it using a few specific terminal commands.

Method 1: Using the smem Utility

The smem utility is one of the best tools available for accurately reporting memory usage in Linux. It calculates the proportional set size (PSS) and provides a clear breakdown of swap usage per process.

First, you need to install it, as it is not included in Ubuntu by default:

sudo apt update
sudo apt install smem

Once installed, you can run the command and pipe the output to tail to see the processes using the most swap (smem sorts by PSS and Swap by default in ascending order, so the biggest users will be at the bottom):

sudo smem -r -s swap | head -n 15

In this command, -r reverses the sort order so the highest consumers are at the top, and -s swap explicitly sorts the list based on swap consumption. You must run this command with sudo to see processes owned by all users, not just your own.

Method 2: Using the top Command

If you cannot install new packages on your server, you can use the built-in top command, but you must configure it to display the hidden Swap column.

  1. Type top and press Enter.
  2. Press the f key on your keyboard to enter the Fields Management screen.
  3. Use your arrow keys to scroll down until you highlight SWAP = Swapped Size (KiB).
  4. Press the Spacebar to select it (an asterisk * will appear next to it).
  5. Press the Right Arrow key to grab the column, then use the Up Arrow key to move it closer to the top of the list so it is easily visible next to the %MEM column.
  6. Press Enter to drop the column, then press q to return to the main top interface.

Now, you can press Shift + O, type SWAP, and press Enter to sort the active process list specifically by swap usage.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.