How to Check Swap Space in Linux
Last Updated :
31 May, 2024
Swap space is like an extra space in your computer's memory. When your computer's main memory (RAM) gets full it uses this extra room (swap space) to store things that aren't being used right now. This extra room is located on your computer's hard drive. Keeping an eye on how much of this extra room is being used is important for your computer to work well. If too much of the extra room is being used, your computer might slow down.
How to Check Swap Space in Linux
What is Swap Space?
Swap space is a separate memory on your computer's hard drive. It acts like extra memory when your computer's main memory (RAM) gets full. When you have too many programs or files open and your RAM is all used up, your computer moves some of the things it's not using right now to the swap space on the hard drive. This frees up space in the RAM for the programs and files you're actively using.
Swap space helps your computer keep running smoothly when it's running out of memory. It's like having an extra room to store things temporarily when your main room gets too full.
Methods to Check Swap Space in Linux
1. Using swapon Command
The swapon command is used to turn on and use an area of your hard drive as extra memory. This extra memory area is called swap space. It helps your computer keep running smoothly when the main memory (RAM) is full. To use swap space run the below command. This command tells your computer to treat the area /dev/sda2 on your hard drive as extra memory (swap space).
Command :
swapon /dev/sda2
After running swapon, you can check which swap space areas are being used by running the below command.
Command :
swapon -summary
Output :

2. Using /proc/swaps Command
The /proc/swaps file shows information about the swap spaces your computer is currently using as extra memory. It lists details like the name, type, size, and how much of each swap space is being used. To view the contents of the /proc/swaps file, you can use cat command.
Command :
cat /proc/swaps
Output :

3. Using free command
The free command shows how much memory (RAM) and swap space your computer is using. When you run free, it displays the total, used, and free amounts for both RAM and swap space use the below command to do that.
Command :
free
Output :

4. Using vmstat Command
The vmstat command shows information about your computer's memory, CPU, and disk activity. It helps you understand how your system's resources are being used.
Command :
vmstat
Output :

- options: Different options to customize vmstat output
- delay: How often (in seconds) to update the information
- count: How many updates to show before stopping
Example Command :
vmstat 2 5
This shows memory, CPU, and disk usage, updating every 2 seconds for 5 times.
5. Using top/atop/htop/glances Command
The commands top, atop, htop, and glances are system monitoring tools used in Linux. They show real-time information about how your computer's resources like CPU, memory, and disk are being used.
Command :
top
Output :

atop command provides a comprehensive view of system activity over time, allowing you to analyze historical data. Navigate through different screens using arrow keys. Press 'q' to exit.
Command :
atop
Output :

htop command is similar to top but with a user-friendly interface and additional features. It displays a color-coded overview of processes, CPU, and memory usage.
Command :
htop
Output :

glances command presents a simplified overview of system resources like CPU, memory, network, and disk I/O on a single screen.
Command :
glances
Output :

The GNOME System Monitor is a graphical application that allows you to monitor various system resources in a user-friendly interface. It displays information about CPU usage, memory usage, swap space usage, disk activity, and network activity.

Conclusion
Monitoring swap space usage is important to ensure your Linux system runs smoothly. Swap space acts as extra memory when your computer's RAM gets full. Several command-line tools like swapon, free, vmstat, and GUI tools like GNOME System Monitor allow you to easily check how much swap space is being used.
Keeping an eye on swap usage helps you identify if your system needs more RAM or if certain programs are using too much memory. By monitoring swap, you can take steps to optimize your system's performance and prevent slowdowns caused by running out of memory.
Similar Reads
How to Check Disk Space in Linux
Efficient disk space management is important for maintaining the performance and stability of your Linux system. Over time, files and applications can fill up your storage, potentially causing slowdowns or errors. Commands to Check DIsk Space in LinuxKnowing how to check disk space in Linux helps yo
6 min read
How to see cache statistics in Linux?
Cache is a very important part of the computer hardware to give superfast response time.Cache PerformanceWhen the processor needs to read or write a location in main memory, it first checks for a corresponding entry in the cache. If the processor finds that the memory location is in the cache, a cac
2 min read
How to Permanently Disable Swap in Linux?
Swapping or swapping space is a physical memory page placed at the top of a disk partition or a special disk file that is used to expand a system's RAM as the physical memory fills up. Inactive memory pages are often dumped into the swap area when no RAM is available, using this method of expanding
3 min read
Check the OS Version in Linux
When we want to install the Software on our system, first we must know whether our current Operating System is supporting this version of the software or not. In Windows, we can easily check it as Windows is based on a GUI-based Operating System.But we prefer to use the Command line instead of the G
4 min read
How to Attach a Swap Partition to Linux?
Virtual memory in Linux OS is RAM + swap space. It is used when memory usage of the system exceeds a certain point then swap space is used all the idle processes are shifted to swap and new processes are assigned to RAM. Now how to allocate swap space ideally swap space should be twice RAM size for
3 min read
How to Check the Size of a Directory in Linux
Many times during working on Linux we may encounter situations, where we want to check the total size occupied by a directory, especially when working with large files and directories. Knowing the file or directory size can help a user perform tasks like storage allocation, size comparison, etc. At
7 min read
How to Check Kernel Version in Linux
The kernel is the core component of the Linux operating system, responsible for managing hardware, running processes, and ensuring system stability. Whether you're updating software, installing new drivers, or troubleshooting issues, knowing your kernel version helps ensure everything works smoothly
7 min read
How to Create a Swap File on Linux?
Linux Operating System has some different features that are unique and not present in any other major operating system like Windows. The Linux Memory Distribution is one of them. The Memory Space in Linux is designed in such a way that the efficiency of the Memory Management could be the best. The L
4 min read
Swapon Command in Linux
The Linux swapon command serves the purpose of activating a swap partition in Linux systems. A swap partition is essentially a dedicated space used when the system's RAM (Random Access Memory) becomes fully utilized. It temporarily holds data that can be retrieved when required, making it particular
5 min read
How to Clear RAM Memory Cache, Buffer and Swap Space on Linux
As you use your Linux system, it constantly manages memory to keep your system running smoothly. Over time, however, certain parts of the memory like cache, buffers, and swap space can build up and slow things down. In this article, weâll explore how to clear RAM Memory Cache, Buffer, and Swap Space
6 min read