+4 votes
70 views
Swap Memory Linux | Linux Swap Memory

in Linux/Unix by (552k points)
reopened | 70 views

1 Answer

+5 votes
Best answer

1 See Memory Swap or using swapon
2 View Swap Memory or using /proc/swaps
3 See Memory Swap or using Free
4 See Memory Swap or using Top
5 See Memory Swap or using Atop
6 See Memory Swap or using Htop
7 See Memory Swap or using Glances
8 See Memory Swap or from using Vmstat

In Linux there are certain configurations that will help the system and in general the performance to be as complete and optimal as possible, one of the best known configurations (and that we can configure from the installation) is the swap memory or swap memory. You have to know how to monitor Linux memory to be able to manage hardware and logical resources well to prevent our system from collapsing..

 

The exchange memory (swap), comes into action at the moment in which the amount of physical memory (RAM) has reached its limit, with it, in case Linux requires memory resources and as such the RAM memory is full, all inactive pages in memory will be moved to the swap space, this swap memory is available on hard drives since it has a slower access time than directly in the physical memory of the equipment.

 

 

Swap memory configuration
It should be noted that this swap memory can be configured in three ways, which are:
  • As a dedicated swap partition (recommended)
  • As a swap file
  • As a combination of swap partitions and swap files

 

 

To take into account that Btrfs does not allow swap space..

 

RAM for swap memory
TechnoWikis will advise you the space to use for the swap memory based on the physical RAM, these values ​​are:
  • Less than 2 GB 2 times the amount of RAM is recommended
  • Between 2 GB and 8 GB we can use the same amount for swap
  • Between 8 GB and 64 GB it will be possible to use at least 4 GB
  • Greater than 64 GB we will use a minimum of 4 GB

 

 

There are some commands in Linux that are ideal for seeing the space available for swap memory.

 

To stay up to date, remember to subscribe to our YouTube channel!
SUBSCRIBE ON YOUTUBE

 

 


1 See Memory Swap or using swapon

 

The swapon command is used to indicate which devices will use the paging and racking tasks, these calls to swapon are executed in the system startup file /etc/rc, this command will give us the opportunity to see the swap space and if we want to see all the devices marked as swap in the /etc/fstab file we will use the -all parameter..

 

Step 1

To do this we open the terminal and execute:
 swapon-all 
Step 2

Then we will see the details by entering the --summary parameter. There we see the file, type, size, used space and priority level.
 swapon-summary 
image

 

 


2 View Swap Memory or using /proc/swaps


The /proc file system in Linux has been implemented as a virtual file system where we will see details about system information at run time about things like system memory, mounted devices, hardware configuration, etc.

 

 

Step 1

For its use we open the terminal and execute:
 cat /proc/swaps 
Step 2

We see the already mentioned details of swap.

 

 

 

image

 

 


3 See Memory Swap or using Free

 

Free is a command with which it is possible to see the amount of free and used system memory, we can add the -h parameter so that the result is a readable format.

 

Step 1

In this case we open the terminal and execute:
 free -h 
Step 2

We can see the indicated details of total, used and free memory.

 

 

 

image

 

 


4 See Memory Swap or using Top


The top command allows us to view Linux processes by giving a real-time dynamic view of the running system, we normally use it for a list of processes or threads that are managed by the Linux Kernel.

 

Step 1

To use this command we open the terminal and execute:
 top 
Step 2

We can see a series of columns with details but in this case at the top you will find the swap details.

 

 

 

image

 


5 See Memory Swap or using Atop


The atop command is a full-screen ASCII performance monitor in which the activity of all the processes on the computer is recorded and reported, atop will be active in the background so that the results are always available, some of its advantages are:

 

  • Shows the resource usage of all processes
  • Highlight critical resources through colors (red)
  • Monitors threads within processes
  • Makes use of the netatop kernel module to monitor TCP, UDP, and network bandwidth
  • Integrates disk I/O and network usage

 

Step 1

We open the terminal and execute:
 atop 
image

 

 

Step 2

If it is not, we execute:
 sudo apt install atop 
image

 

Step 3

Enter the password and wait for it to be installed. We run "atop" again to see the swap memory at the top:

 

image

 

Note
we must look at the SWP line associated with the swap memory.

 


6 See Memory Swap or using Htop


With the htop command we will have the possibility to see processes in an interactive mode as well as see information about the use of memory, for its use we open the terminal and execute:
 htop 
At the top you will see the swap details.

 

 

 

 

image

 

 


7 See Memory Swap or using Glances

 

Glances has been developed as a system monitoring utility where we will have access to information about running processes, CPU load, storage space usage, memory usage and many more details, we access the terminal and we execute:

 glances 
image

 

We will see the swap details in the respective line indicating its total, used and free.

 


8 See Memory Swap or from using Vmstat

 

Finally, we can make use of the vmstat command which generates information about virtual memory statistics, running processes, memory usage and much more, if this command is not available (in most cases it comes by default).

 

Step 1

You can install it with the following commands:
 sudo apt install vmstat (Debian, Ubuntu and Mint) sudo yum install vmstat (RHEL/CentOS/Fedora) 
Step 2

Now run:
 vmstat 
Step 3

We will see the swap statistics:

 

 

 

 

image

 

So each of these commands is ideal for knowing everything related to the swap space in Linux.

 


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Nov 16, 2019 in Linux / Unix by backtothefuture (552k points) | 652 views
+5 votes
1 answer
asked Mar 9, 2023 in Windows11 by backtothefuture (552k points) | 96 views
+5 votes
1 answer
asked Oct 19, 2023 in Linux/Unix by backtothefuture (552k points) | 53 views
+5 votes
1 answer
asked Oct 13, 2023 in Linux/Unix by backtothefuture (552k points) | 59 views
+4 votes
1 answer
asked Oct 12, 2023 in Linux/Unix by backtothefuture (552k points) | 47 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users