How to do Managing and monitoring swap space on Linux – Guide

Swap space can play an important role in system performance. Learn how to determine how much swap space your system has available and how much is being used. Most of us don’t always think about swap space unless we have a problem with our systems that suggests we don’t have enough. Still, visualizing and evaluating the adequacy of swap space on a system isn’t very complicated, and knowing what’s normal for your system can help you detect when something is wrong. So let’s look at some commands that can help you examine your swap space. But first, let’s review some fundamentals.

What is swap space and how is it used

Swap space is disk space that acts as an extension of memory. It is used when the system’s physical memory (RAM) is full and the system needs more memory resources. It’s called “swap” because the system will move some inactive pages from memory to swap space so it can accommodate more data in RAM. In another words, provides a way to release up RAM on a busy system. Programs and data use RAM because this is the only way the system can process them. In fact, when a system boots, it moves programs like the kernel and systemd into RAM to continue. Swap space can be configured as its own disk partition or defined up as a file. Currently, most Linux installations create a partition during installation, and this is ideal. You can, however, define up a swap file and use it as your swap space. With inadequate swap space, you can have a problem called “thrashing”, in which programs and data are moved between RAM and swap space so often that the system runs very slowly. Together, RAM and swap are called “virtual memory”.

How much exchange do you need?

The swap space recommendation used to be twice the RAM, but that was when systems didn’t have as much RAM as they usually do today. These recommendations for Ubuntu should probably work well for other distributions as well: The distinction between swapping and swapping with hibernation is important. A hibernating system immediately saves the system state to the hard drive and shuts down. When you wake up up (for example, lifting the “lid” on a laptop), all programs you were running revert to the state they were in when the system went into hibernation. Therefore, more swap space is recommended. Not all systems go to sleep. To determine if your system can hibernate, run this command: $ which pm-hibernate / usr / sbin / pm-hibernate If you get the answer shown above, your system is ready for hibernation. You can test it by running this command: $ sudo pm-hibernate

How can you see the amount of swap space on your Linux system?

You can use the swapon –show command to view swap space on your system. $ swapon – show NAME TYPE PRIO SIZE USED / dev / zram0 partition 5.8G 3.3M 100Another useful command is the free command that displays swap space and memory usage. With -m, results are displayed in MBs instead of KBs. The sar command can report swap space usage.

When you need and don’t need more swap space

If your system has a lot of memory, you may never need to use swap space. But it’s almost always a good idea to have it available. Disk space is relatively cheap compared to memory, and you never know when some process might increase the load. On the other hand, if your swap space is heavily used almost all the time, you should consider adding more RAM to your system as there is some performance cost associated with using it.

Final note

I hope you like the guide How to do Managing and monitoring swap space on Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.

How to do Managing and monitoring swap space on Linux  2022  - 3How to do Managing and monitoring swap space on Linux  2022  - 61How to do Managing and monitoring swap space on Linux  2022  - 98How to do Managing and monitoring swap space on Linux  2022  - 52