How to Diagnose Swap Usage on Linux with smem

Table of Contents

Introduction

Have you ever logged into a Linux server, noticed that swap memory is being used, and wondered why when the system still has plenty of free RAM?

This is a common situation in Linux server administration. Linux uses swap space to manage memory efficiently. It can move less frequently accessed memory pages from RAM to swap, allowing available RAM to be used for other activities, including filesystem caching.

However, consistently high swap usage can indicate memory pressure, inefficient application configuration, or a process consuming more memory than expected.

The first step in troubleshooting Linux swap usage is identifying which processes are consuming swap memory. The smem command makes this easier by displaying memory consumption at the process level, including swap usage.

In this guide, you will learn how to:

  • Check current Linux RAM and swap usage.

  • Install and use the smem command.

  • Identify processes consuming the most swap memory.

  • Understand USS, PSS, RSS, and swap metrics.

  • Compare smem with other Linux monitoring tools.

  • Troubleshoot and reduce unnecessary swap usage safely.

Whether you manage a VPS, dedicated server, cloud instance, or production Linux environment, these steps will help you investigate memory consumption more effectively.

How to Check Swap Usage in Linux

To identify which Linux processes are using the most swap memory, install smem and run:

smem -rs swap -k

This command displays processes sorted by swap consumption, with the highest-consuming processes appearing first.

Before that, check overall system memory using:

free -h

If you need to investigate high swap usage, compare the results with process memory consumption and system monitoring metrics before changing kernel settings.

What Is Swap Memory in Linux?

Swap memory is disk space that Linux uses as an extension of physical RAM. When the kernel needs to manage memory pressure, it can move certain inactive memory pages from RAM into swap space.

Step 1: Check the current swap usage

Check how much swap is in use:

free -h

Look at the swap row. If the used column is high, continue with the next steps.

Step 2: Install smem

smem is a memory reporting tool that shows memory usage per process, including swap. It is not installed by default, but it is available in most repositories.

On RHEL, AlmaLinux, CentOS or Fedora (on RHEL-based systems you may need to enable the EPEL repository first):

dnf install smem

On Debian or Ubuntu:

apt install smem

Step 3: Find the processes using swap

Run the following command to list processes sorted by swap usage, highest first:

smem -rs swap

If you want the sizes in a readable format such as MB or GB, add the -k option:

smem -rs swap -k

The output looks like this (shortened):

PID User Command Swap USS PSS RSS
—————————————————————————
3878245 root /usr/bin/python3 /usr/bin/s 128.0M 10.2M 45.7M 85.6M
3878239 monit /usr/bin/ping -q -c10 -i2 2 0 156.0K 200.0K 2.1M
3878238 monit sh -c /usr/bin/ping -q -c10 4.0M 280.0K 443.0K 3.2M
3878237 monit /omd/sites/monit/bin/n 32.0M 300.0K 8.1M 18.5M
3878235 monit /usr/bin/ping -q -c10 -i2 2 0 156.0K 200.0K 2.1M
3878232 monit sh -c /usr/bin/ping -q -c10 0 280.0K 439.0K 3.2M
3878231 monit /omd/sites/monit/bin/n 16.0M 864.0K 6.1M 12.5M
3877754 root bash 0 4.8M 5.1M 8.2M
3877748 root sshd-session: root@pts/0 0 748.0K 2.2M 7.6M
3877745 root sshd-session: root [priv] 8.0M 1.2M 2.9M 11.6M
3877731 root /usr/libexec/nm-dispatcher 0 2.8M 4.2M 9.1M

Here is what the columns mean:

  • Swap: memory of that process currently sitting in swap
  • USS: memory that belongs only to that process
  • PSS: the process’s own memory plus its fair share of shared memory
  • RSS: all the RAM the process is using, including shared memory

Bonus: smem can also draw a pie chart on a desktop with a graphical environment (pie chart requires matplotlib):

smem –pie name -s rss

Step 4: Cross-check with other tools

No single tool is perfect for every situation. These alternatives are also useful for checking memory and swap per process.

No installation needed: every process exposes its swap usage in /proc, so this one-liner works on almost any system:

grep VmSwap /proc/[0-9]*/status 2>/dev/null | sort -k2 -nr | head

htop: an interactive version of top. It shows RES and VIRT by default. To see swap, press F2, go to Columns, and add the SWAP column.

dnf install htop    # or apt install htop

atop: like top, but it also records system usage over time, which makes it great for finding out what happened in the past. Press m inside atop to see memory details per process.

dnf install atop    # or apt install atop

glances: a real-time monitoring tool that shows per-process memory and swap on one screen. It can also run in server mode and be checked remotely.

dnf install glances    # or apt install glances

btop and bottom (btm): modern, colourful alternatives to top and htop. They give a clear visual view of CPU, memory, swap, disk and network. Both are available from their project pages and many package repositories.

apt install btop

Step 5: Reduce swap usage

Once you know which service is using swap, fix the cause first:

  • Tune memory-heavy services such as MySQL or rsyslog so they use less memory.
  • If a service really needs more memory, consider adding RAM.

After that, you can lower the vm.swappiness value so the kernel avoids swapping unless it really needs to:

sysctl vm.swappiness=10

echo ‘vm.swappiness=10’ >> /etc/sysctl.conf

The first command applies the change immediately, and the second keeps it after a reboot. Note that swap which is already in use is not released automatically; it is moved back to RAM only when the process needs it again.

Conclusion

Swap usage is not always a problem, but it is worth understanding when it grows. smem is a light and simple tool that shows exactly which processes are using swap, and its PSS values give an accurate view of real memory usage. 

Experiencing High Swap Usage on Your Linux Server?

Don’t let memory issues affect your server performance. Let Skynats help you identify resource bottlenecks, troubleshoot Linux memory issues, and keep your infrastructure running smoothly.

Get Expert Linux Server Management Support

Picture of Merin John

Merin John

Merin John is a Level 1 System Engineer at Skynats Technologies, specializing in server management, cloud infrastructure, and technical support.

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Subscribe and get your first issue fixed for Free!

Looking for server support and 24x7 monitoring?

Have doubts? Connect with us now.