Simple understanding of the Linux performance monitoring command free

  • 2021-06-28 09:57:56
  • OfStack

How do we locate errors when the system encounters various IO bottlenecks, high memory usage, and high cpu usage?linux provides many commands to help us quickly locate errors. The free command is one of Linux's most common commands: it can view the system's memory status, including the total memory of the server, the memory that has been used and the remaining unused memory, as well as the memory occupied by buffers and caches.


$ free -m
total used free shared buffers cached
Mem: 994 787 207 0 121 227
-/+ buffers/cache: 437 557
Swap: 0 0 0

To fully understand the three rows above, first figure out what buffer and cache are.

buffer: Buffer

Buffer data to solve slow and fast handover problems;Fast requires buffering data from point 1 to point 1 to slow areas.For example, writing data from memory to the hard disk does not write directly, but buffers to a certain size and then flushes it to the hard disk.

A buffer is something that has yet to be "written" to disk.

cache: Cache

To achieve data reuse, slow devices need to cache frequently used data, which can provide high-speed transmission to fast devices.For example, it is much faster to read out the data from the hard disk and put it in a memory cache so that you can access the same resource again later.

A cache is something that has been "read" from the disk and stored for later use.

buffer is used to store data that will be output to disk (Block Device), while cache is used to store data read from disk.Both are designed to improve IO performance.

Once you understand the roles of buffer and cache, the information presented by free is easy to understand, and now you begin to analyze what each line of the free command output represents:

Line 1: Mem

Total memory 994 (total) = 787 (used) +207 (free). used indicates the memory that the system has used. It includes the total memory used by the application, as well as the total memory used for buffering and caching.

Line 2: -/+ buffers/cache

-buffers/cache:437 (used) = 787 (used) - 121 (buffers) - 227 (cached), 437 indicates that the actual memory consumed by the application is 437M, in addition to buffering and caching.

+buffers/cache:557 (free) = 207 (free) +121 (buffers) +cached (227), 557 indicates that 557 M is available in the system, because the memory occupied by buffer and cache can still be used by applications in case of a memory crisis.

Line 3: Swap

I see many articles that say no, but here I want to explain one thing. Swap means swap partitions, which we usually call virtual memory.You can use a portion of disk space as memory, which is called virtual memory. When the system runs out of memory, it temporarily puts programs that are still in memory but are not currently running in virtual memory.


Related articles: