A computer's virtual memory is a high-priority resource and, as such, must be properly controlled and monitored using the tools we offer. This includes knowing how to view the used and free RAM , as well as the swap space , which stores all the data and processes that are not high-priority and have not been loaded into RAM or have been removed from it to make room for higher-priority ones. This is a simple explanation of how it works, without going into too much detail.
To learn how to control, or rather, monitor these memories in our Linux system, there are numerous possibilities. You can do it directly by using the `--` command to view one of the files in the `/proc` interface provided by Linux, or you can use the tools we'll mention that can use these or other types of files to obtain this information and present it in a more user-friendly or organized way. You can even use commands like `top` and others related to processes that provide certain data about memory. First, let's look at the `free` command . With it, you can see the used and free RAM and swap space, buffer, etc. You can also use the `-h` option, which displays the units in a somewhat more understandable way, in my opinion.
free -h
With the swapon command we can activate partitions or swap files, but with the -s option we can also see its capacity:
swapon -s
We continue with vmstat which, as its name suggests, shows the status of virtual memory:
vmstat
Another option would be memstat , similar to the previous one:
memstat
Let's now look at the /proc files that we can consult to obtain information about memory:
cat /proc/swaps
cat /proc/meminfo
And finally, we're going to use another command, which simply uses the DMI tables to obtain hardware information, in this case filtering only the memory-related information using this option:
sudo dmidecode --type memory