
{{ $('Map tags to IDs').item.json.title }}
How to Use free and vmstat Commands
Monitoring system performance is crucial for effective system administration, and the free
and vmstat
commands are essential tools for assessing memory usage and performance in Linux. This tutorial will guide you through the basics of using these commands.
1. Using the free Command
The free
command is used to display the total amount of free and used physical and swap memory in the system:
free -h
The -h
flag provides output in a human-readable format (e.g., MB or GB).
1.1. Understanding the Output
The output will look something like this:
total used free shared buff/cache available
Mem: 16Gi 2.5Gi 1.2Gi 589Mi 12Gi 13Gi
Swap: 2.0Gi 0B 2.0Gi
This table breaks down memory usage into several categories:
- total: Total memory available.
- used: Memory in use by processes.
- free: Memory not in use.
- shared: Memory used by tmpfs.
- buff/cache: Memory used for buffers and cache.
- available: Memory available for new processes without swapping.
2. Using the vmstat Command
The vmstat
command reports information about processes, memory, paging, block IO, traps, and CPU activity:
vmstat 1
The parameter 1
specifies that the command should update every second.
2.1. Understanding the Output
The output displays multiple rows, with the first line showing averages since the last reboot:
procs -----------memory---------- ---swap-- -----io---- -system-- --cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 12345678 23456 34567 0 0 1 0 100 200 30 1 69 0
Here’s what each column means:
- procs: The number of processes.
- memory: Statistics about the system’s memory usage.
- swap: Information about swap space usage.
- io: Input/output operations.
- system: System-wide statistics.
- cpu: CPU states (user, system, idle, wait).
3. Conclusion
By following this tutorial, you have learned how to use the free
and vmstat
commands to monitor memory and system performance in Linux. These commands are essential for performance tuning and troubleshooting. Continuously explore these tools and others to maintain an optimal Linux environment!