Linux memory view command (free -m) using tutorial

  

to view the memory usage under the Linux server, you can use the command free -m. Note that this command is only valid under Linux. There is no such command in FreeBSD. The command is as follows:




used: Number of used memory

free: Number of free memory

shared: Total memory shared by multiple processes

-buffers/cache: (used) memory, ie used-buffers-cached

+buffers/cache:( The amount of memory available, ie free+buffers+cached

, concludes that:

The available memory is calculated as:

Available memory=free+buffers+cached, That is 215MB+11MB+57MB=253MB

Linux memory is used, not to look at it. When I talked to a friend about Linux usage, he asked me why Linux uses so much memory. The 1GB of memory on his machine is only 232MB free, and Windows
XP uses less than 200MB. This is actually confusing by the appearance of Linux's free command, Linux memory usage is very particular. As an example, the following free command shows the current memory usage, -m means to display the content with M bytes, let's take a look.


The following parameters are included in the first part of the Mem line.

total: Total memory, ie 378MB

used: The number of used memory, ie 769MB

free: the number of free memory, ie 232MB

Shared: currently obsolete, always 0

buffers Buffer: cache memory, ie 62MB

cached Page: cache memory, ie 421MB

where, total memory The relationship with the number of used and free memory is:

total(1002M)=used(769M)+free(232M)

In the second part (-/+buffers/The parameters in the cache are as follows.

(-buffers/cache): The number of used memory, which is 286MB (refers to the used-buffers-cached in the first part of the Mem line).

(+buffers/cache): Free memory, ie 715MB (refers to free+buffers+cached in the first part of the Mem line).

Visible -buffers/cache reflects the memory that is actually being used by the program, and +buffers/cache reflects the total amount of memory that can be used.

The third part refers to the swap partition. Everyone should understand that it will not be discussed here.

It is possible that everyone has read the above explanation or not quite understand. For example: the first part (Mem) is related to the result of the second part (-/+buffers/cache). Why is used and free so strange? In fact, we can analyze from two aspects. For operating system
, these two are Mem parameters, buffers/cached are used, so it thinks free is only 232MB; for applications, +buffers/cached is equivalent to available memory, because Buffer/cached can improve the performance of program execution. When the program uses memory, buffer/cached will be used very quickly. So from the application point of view, should be based on (-/+buffers/cache) free and used, that is, we mainly look at the free and used related to it. In addition to tell you some common sense, in order to improve the access efficiency of disk and memory, a lot of careful design for Linux, in addition to the dentry cache (for VFS, speed up file path name to inode conversion), also took two The main Cache methods: Buffer Cache and Page Cache. The former is used for reading and writing of disk blocks, and the latter is used for reading and writing of file inodes. These Caches can effectively reduce the time of I/O system calls (such as read, write, getdents).

In Linux, memory is used, not to look at it. In Windows, no matter how much real physical memory you have, it will use the hard disk to exchange files for reading, even if there is a large part of the memory. This is why Windows often prompts for insufficient virtual space. I can imagine how the hard disk will be faster than the memory, so when we observe the memory usage of Linux, as long as we do not find swap space with swap, we don't have to worry about our own memory. If you often see a lot of swap, then you should consider adding physical memory. This is also the standard for seeing if the memory is sufficient on a Linux server.

Copyright © Windows knowledge All Rights Reserved