The swap is the small portion of the secondary memory which is used as a virtual memory. It improves the performance of the system, even if the system memory has low space. The swap is used to store the pending processes so that the main memory can store more processes in it. In Ubuntu 22.04, the swap space is automatically assigned during the installation.
In this article, we will check if the swap is active, or not by using the terminal.
How Can I Check if Swap is Active from the Terminal?
When you are using a system that has low hardware specifications, you can improve the performance of the system by the optimization of the resources. Swap is one of the important resources that works with the main memory to improve the overall performance of the system. If you want to check the swap service in Ubuntu 22.04 follow the methods mentioned below.
Method 1: Using the File proc/meminfo
The “proc/meminfo” file is used to store information about the usage of memory in a system. You can use this file to check the amount of swap space that is being used and free if it is enabled.
Use the following command to open the contents of the file in the terminal:
$ cat /proc/meminfo
The command will display the memory information report:
You can see the SwapTotal and SwapFree fields along with the values. It means that my swap service is active.
Method 2: Using the “swapon -s” Command
The “swapon -s” command is used to check the status of the swap service. If it is active the command displays the swapfile and details of the file.
$ sudo swapon -s
The command will display the following output if the swap service is active:
The output shows the following details:
- Filename: Which displays the filename
- Type: Displays the type either file or partition
- Size: Displays the swap space size
- Used: Displays the used swap space
- Priority: Priority value displays the usage priority of the swap
Method 3: Using the “swapon –show” Command
The “swapon –show” command is used to display the swap usage information more concisely. Use the following command to display the swap usage:
$ swapon -show
The command will display the following output:
The details are as follows:
- NAME: Which displays the filename
- TYPE: Displays the type either file or partition
- SIZE: Displays the swap space size
- USED: Displays the used swap space
- PRIO: Priority value displays the usage priority of the swap
Method 4: Using the “top” Command
The top command is used to monitor the system resources. You can also use this command to check the swap service. Use the following command to check the swap service:
$ top
The following output will be shown:
Note: If the swap service is not active you can enable it by using the following instructions:
- Execute the following command to check whether the swap service is enabled or not
$ swapon -show
If the swapon –show command does not display the output it means that the swap is not active:
- You can enable the service by using the following command:
$ sudo swapon -a
- Run the “swapon –show” command again
$ swapon -show
Now your swap service is active. You will see the following output:
This is how you can check if the swap service is active from the terminal in Ubuntu 22.04.
Conclusion
To check if the swap is active from the terminal in Ubuntu 22.04, you can use the proc/meminfo file, the “swapon -s” command, the “swapon –show” and the “top” command. In this article, we have learned how you can check swap is active from the terminal.
Frequently Asked Questions
How to check if swap space is active in Ubuntu 22.04?
You can use the 'cat /proc/meminfo' command in the terminal to view SwapTotal and SwapFree values, indicating if the swap service is active.
What is the purpose of swap space in a system with low hardware specifications?
Swap space serves as virtual memory, allowing the system to store pending processes when the main memory is low on space, thereby enhancing system performance.
How does swap space work with the main memory to improve system performance?
Swap space collaborates with the main memory by offloading less-used data to the secondary memory, enabling the main memory to accommodate more active processes.
How is swap space automatically assigned during Ubuntu 22.04 installation?
During the Ubuntu 22.04 installation process, the system automatically assigns swap space to ensure optimal performance and resource utilization.
What command can be used to check the status of the swap service?
You can utilize the 'swapon -s' command in the terminal to verify the status of the swap service and view details of the swapfile.
Why is it essential to optimize swap space in a system with limited resources?
Optimizing swap space is crucial for enhancing system performance by efficiently managing memory resources, especially in systems with low hardware specifications.
Can swap space be disabled in Ubuntu 22.04 for performance optimization?
While swap space can be disabled, it is not recommended as it may lead to system instability and decreased performance, especially in resource-constrained environments.
What role does the 'proc/meminfo' file play in checking swap space utilization?
The 'proc/meminfo' file contains information on memory usage, including swap space details, making it a useful resource for monitoring and managing system memory.