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 :
6. Using Linux GUI Tool
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.
How to Check Swap Space in Linux
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?
- Methods to Check Swap Space in Linux
- 1. Using swapon Command
- 2. Using /proc/swaps Command
- 3. Using free command
- 4. Using vmstat Command
- 5. Using top/atop/htop/glances Command
- 6. Using Linux GUI Tool