How to Check Swap Space in Ubuntu Linux

When your system’s physical memory or RAM reaches full capacity, the swap space comes into play, providing a reservoir for inactive memory pages. This mechanism involves transferring these inactive pages from the RAM to the swap space, effectively expanding available memory resources. While swap space is a valuable resource during RAM shortages, it’s essential to note that it resides on the hard drive, resulting in slower access times. Consequently, swap space is not an ideal substitute for RAM.

In this guide, we’ll walk you through various methods to examine available swap space on your Ubuntu system.

1. The Linux ‘free’ Command

To quickly assess memory and swap utilization, employ the ‘free’ command:

free

free command

By default, this command presents output in kilobytes. For a more readable format with memory and swap details in a three-digit format, use the ‘-h’ switch:

free -h

free -h command

2. The swapon command

Utilize the ‘swapon’ command with the ‘-s’ (summary) switch to inspect swap details for a specific partition, logical volume, or file:

swapon -s

swapon command

3. The top command

For a comprehensive overview that includes swap space information, leverage the ‘top’ command:

top

top command

The header section of the ‘top’ command output displays swap space details in kilobytes. Other alternatives with similar functionality include ‘htop,’ ‘glances,’ and ‘itop.’

Also Read:  Spectator API Tester Application

4. The vmstat command

Explore swap in and swap out information using the ‘vmstat’ command:

vmstat

vmstat command

While it provides specific details, note that total swap values are not visible through this command.

5. The /proc/swaps file

Examine swap size information through the ‘/proc/swaps’ file, revealing device-wise swap details, including device name, type, and its contribution to the system:

cat /proc/swaps

cat swap

By using these commands, you can effectively monitor swap space on your Ubuntu system when faced with low RAM resources.

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Leave a Reply