Programming

How to find out which processes are using swap space in Linux

25 September 2026 · 5 min read

How to find out which processes are using swap space in Linux

Swap space in Linux acts as an extension of RAM, allowing the system to handle more memory demands than physically available. Understanding which processes are utilizing this swap space is crucial for optimizing system performance and troubleshooting memory-related issues. If your system is frequently swapping, it can lead to significant slowdowns. This article delves into various methods for identifying the processes consuming swap space, equipping you with the knowledge to diagnose and resolve performance bottlenecks.

Using the top Command

The top command is a powerful real-time system monitor that displays dynamic information about running processes, including swap usage. By default, top doesn’t show swap usage directly. However, you can configure it to display the ‘SWAP’ column by pressing ‘f’, then navigating to ‘SWAP’ and pressing ’s’ to select it. Once activated, the SWAP column reveals the amount of swap space each process is using.

This method allows for quick identification of processes consuming excessive swap. You can further sort processes by swap usage by pressing ‘O’ and then selecting ‘p’ for swap (or ‘M’ for resident memory). This interactive approach is invaluable for real-time monitoring and troubleshooting.

Leveraging the vmstat Command

The vmstat command provides valuable statistics about virtual memory, including swap space activity. While it doesn’t directly pinpoint processes using swap, it gives insights into overall swap activity (si and so columns), helping you gauge the system’s swap usage. High values in these columns suggest heavy swapping and potential performance issues.

Running vmstat 1 provides updates every second, allowing you to observe how swap usage fluctuates over time and correlate it with other system activities. This can be particularly useful for diagnosing intermittent performance problems linked to swapping.

For more detailed information check this helpful resource.

Exploring smem for Detailed Swap Usage

The smem utility offers a more comprehensive breakdown of memory usage, including Proportional Set Size (PSS), which provides a more accurate representation of a process’s share of shared memory, including swap. This is a crucial distinction from other tools that may overestimate swap usage.

Install smem using your distribution’s package manager (e.g., apt install smem on Debian/Ubuntu). Then, run smem -s swap to sort processes by their swap usage. This detailed breakdown can help pinpoint processes contributing significantly to swap activity, even if their resident memory usage appears low.

Using /proc/[pid]/smaps for Granular Insights

For highly granular information about a specific process’s memory usage, examine the /proc/[pid]/smaps file. Replace [pid] with the process ID. This file provides a detailed map of the process’s memory segments, including how much of each segment is swapped out.

This method is especially helpful when you’ve identified a specific process consuming excessive swap using other tools. Analyzing smaps can reveal why the process is using swap and which parts of its memory are being swapped.

Practical Example: Diagnosing a Slow System

Imagine your system is experiencing slowdowns. Using top, you notice several processes with high SWAP values. Further investigation with smem reveals that a particular database server is the primary culprit. Examining its /proc/[pid]/smaps file shows that a large portion of its data segments is being swapped out, indicating insufficient RAM for the database. This pinpoints the need to either increase RAM or optimize the database server’s memory usage.

  • Monitor swap usage regularly to prevent performance degradation.
  • Use a combination of tools for comprehensive analysis.
  1. Identify high swap usage processes with top.
  2. Analyze overall swap activity with vmstat.
  3. Get detailed swap usage with smem.
  4. Deep dive into process memory with /proc/[pid]/smaps.

[Infographic visualizing the different methods and their use cases.]

FAQ: Common Queries About Swap Usage

Q: What is swap thrashing?

A: Swap thrashing occurs when the system spends excessive time swapping data between RAM and swap space, leading to significant performance degradation. This often happens when available RAM is insufficient for the current workload.

Understanding how to monitor and analyze swap usage is essential for maintaining a healthy and performant Linux system. By utilizing the tools and techniques discussed in this article, you can effectively identify and address swap-related performance bottlenecks. Start optimizing your system’s memory management today to ensure smooth and efficient operation. Explore additional resources like this article on Swap space from Red Hat: Red Hat Swap Space Documentation and this tutorial on using vmstat: Vmstat Command Examples. Further information about the /proc filesystem can be found on the man7 website.

  • Optimize application memory usage to minimize swap dependency.
  • Consider increasing RAM if swap usage consistently remains high.

Question & Answer :
Under Linux, how do I find out which process is using the swap space more?

The best script I found is on this page : http://northernmost.org/blog/find-out-what-is-using-your-swap/

Here’s one variant of the script and no root needed:

#!/bin/bash # Get current swap usage for all running processes # Erik Ljungstrom 27/05/2011 # Modified by Mikko Rantalainen 2012-08-09 # Pipe the output to "sort -nk3" to get sorted output # Modified by Marc Methot 2014-09-18 # removed the need for sudo SUM=0 OVERALL=0 for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"` do PID=`echo $DIR | cut -d / -f 3` PROGNAME=`ps -p $PID -o comm --no-headers` for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'` do let SUM=$SUM+$SWAP done if (( $SUM > 0 )); then echo "PID=$PID swapped $SUM KB ($PROGNAME)" fi let OVERALL=$OVERALL+$SUM SUM=0 done echo "Overall swap used: $OVERALL KB"