How to Check Swap Space/Memory/Size on Linux VPS Server

In Linux, swap space plays a pivotal role as a backup to physical memory, providing an overflow area. This is crucial for two primary reasons.

Firstly, when the system demands more memory than physically available, the swap space steps in to provide memory to the current application that requires it immediately. Secondly, a substantial number of pages utilized by an application during its startup phase may only be used for initialization and then never used again.

The system can swap out these pages, freeing the memory for other applications or even for the disk cache.

In this tutorial, we will delve into how to check swap space, memory, or size on a Linux server. This tutorial is applicable to CentOS 6, CentOS 7, RHEL 6, and RHEL 7.

Checking Swap Space/Memory/Size using “swapon -s”

The first method to check the swap space involves using the “swapon -s” command. This command displays the allocated swap disk or disks, if any. Here’s how you can use it:

[root@centos63 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       2064376 0       -1

Checking Swap Space/Memory/Size using “cat /proc/swaps”

The second method to check the swap space is by using the “cat /proc/swaps” command. This command also shows the allocated swap disk or disks, if any. Here’s how you can use it:

[root@centos63 ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       2064376 0       -1

Checking Swap Space/Memory/Size using “free -m”

The third method to check the swap space is by using the “free -m” command. This command provides a snapshot of the total, used, and free memory in the system. Here’s how you can use it:

[root@centos63 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1006        121        885          0          7         71
-/+ buffers/cache:         41        964
Swap:         2015          0       2015

Checking Swap Space/Memory/Size using “cat /proc/meminfo | grep Swap”

The fourth method to check the swap space is by using the “cat /proc/meminfo | grep Swap” command. This command filters out the swap-related information from the /proc/meminfo file. Here’s how you can use it:

[root@centos63 ~]# cat /proc/meminfo | grep Swap
SwapCached:            0 kB
SwapTotal:       2064376 kB
SwapFree:        2064376 kB

Commands Mentioned

  • swapon -s – Displays the allocated swap disk or disks
  • cat /proc/swaps – Shows the allocated swap disk or disks
  • free -m – Provides a snapshot of the total, used, and free memory in the system
  • cat /proc/meminfo | grep Swap –Filters out the swap-related information from the /proc/meminfo file
See also  How to Install “man” Command on CentOS 5.8

Conclusion

Understanding how to check swap space, memory, or size on a Linux VPS server is a critical skill for any webmaster or website administrator. It allows you to monitor your server’s memory usage and ensure that your applications have enough resources to run efficiently. By using the commands “swapon -s”, “cat /proc/swaps”, “free -m”, and “cat /proc/meminfo | grep Swap”, you can gain a comprehensive overview of your server’s swap space.

Remember, a well-monitored and managed server contributes significantly to the performance of your dedicated, VPS, or cloud hosting environments.

See also  How to Fix _default_ VirtualHost overlap on port 80, the first has precedence

Whether you’re running a Apache, Nginx, or LiteSpeed server, understanding the ins and outs of your server’s memory usage is a vital part of maintaining optimal performance.

By following this guide, you’ve taken a significant step towards becoming a more proficient webmaster or website administrator. Keep exploring, keep learning, and remember: knowledge is the key to mastering the digital world.

FAQ Section

  1. What is swap space in Linux?

    Swap space in Linux is a form of memory that is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.

  2. Why is swap space important?

    Swap space is important because it provides a buffer for when your system runs out of RAM. This allows your system to continue functioning smoothly even when your memory resources are being heavily utilized.

  3. How can I check the swap space on my Linux server?

    You can check the swap space on your Linux server by using commands like “swapon -s”, “cat /proc/swaps”, “free -m”, or “cat /proc/meminfo | grep Swap”. These commands display information about the allocated swap disk or disks.

  4. What does the “free -m” command do?

    The “free -m” command in Linux provides information about total, used, and free memory (including swap) in the system, displayed in megabytes.

  5. What does the “cat /proc/meminfo | grep Swap” command do?

    The “cat /proc/meminfo | grep Swap” command in Linux filters out and displays only the swap-related information from the /proc/meminfo file.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *