Some time ago a project was written in C, and the performance test found a memory leak. Free is a good command for how to observe memory usage issues.
parameter Explanation
bash-3.00$ Free
Total used free shared buffers Cached
mem:1572988 1509260 63728 0 62800 277888
-/+ buffers/cache:1168572 404416
swap:2096472 16628 2079844
Mem: Indicates physical memory statistics
Total: Indicates the amount of physical memory (totals = used + Free)
Used: Represents the amount that the total is allocated to the cache (including buffers and cache), but may not be actually used in some of the caches.
Free: Memory that has not been allocated.
GKFX: Shared memory, general system will not be used, nor discussed here.
Buffers: The number of buffers that are allocated but not used by the system.
Cached: The number of caches that the system allocates but has not been used.
-/+ Buffers/cache: Cache statistics representing physical memory
Used2: The used–buffers-cached in the first row is also the amount of memory actually used. Used2 as the second row
Free2= buffers1 + cached1 + free1//free2 for the second row, buffers1, etc. as the first row
Free2: The sum of unused buffers with the cache and unallocated memory, which is the current actual memory available to the system.
Swap: Indicates the usage of the swap partition on the hard disk, we don't care about it here.
Total physical memory of the system: 255268Kb (256M), but the system is currently really available memory B is not the first line of the free Mark 16936Kb, it represents only unallocated memory.
the difference between buffers and cached
A buffer is something that have yet to being "written" to disk. A cache is something that have been "read" from the disk and stored for later use
For applications, buffers/cached is equal to available, because buffer/cached is designed to improve the performance of file reads, and buffer/cached is quickly recycled when applications need to use memory.
So, from the application's point of view, available memory = System Free memory+buffers+cached.
Buffers is the buffer size used to make a block device, and he only records the metadata of the filesystem and tracking in-flight pages.
Cached is used to buffer files.
That is to say: buffers is used to store, what content inside the directory, permissions and so on.
and cached directly to the memory of our open files, if you want to know if he is really effective, you can try, successively executed two times the command #man X, you can obviously feel that the second opening is much faster.
Cached Experiment : doing something on a machine with no application can be seen more clearly. Remember that the experiment can only be done once, if you want to do more please change a file name.
#free
#man X
#free
#man X
#free
You can compare the size of the buffers after the free.
Buffers Experiment :
#free
#ls/dev
#free
You compare the size of two, of course, this buffers is increasing at any time, but you have the LS, the increase in speed will become faster, this is the difference between buffers/chached.
Because Linux uses your temporary unused memory as a file and data cache to improve system performance, when you need these memory, the system will automatically release (unlike Windows, even if you have a lot of free memory, he will have access to the disk pagefiles)
briefly on swap
When the available memory is less than the rated value, the Exchange begins.
How to look at the rated value (RHEL4.0):
#cat/proc/meminfo
The exchange will reduce the number of physical pages used in the system in three ways:
1. Reduce the buffer and the size of the page cache,
2. Swap out the memory page of the System V type
3. Swap out or discard the page. (Application occupies a memory page, that is, insufficient physical memory).
In fact, a small amount of swap use does not affect the performance of the system.
use the free command
Subtracting the value of buffer and cache from the value of used is your current real memory usage ———— – A parameter that is mem for the operating system . Buffers/cached all belong to be used, so it thinks free is only 16936 .
For the application (-/+ buffers/cach). buffers/cached is equivalent, because buffer/cached is to improve the performance of the program execution, when the program uses memory, buffer/ Cached will be used very quickly. So, take a look at the application, to (-/+ Buffers/cache) of the free and used-based. That's why we look at this. In addition to tell you some common sense. In order to improve disk and memory access efficiency, Linux has done a lot of careful design, in addition to the Dentry cache (for VFS, speed up the file path name to Inode conversion), but also adopted two main cache mode: Buffer cache and Page cache. The former is for the disk block read and write, the latter for the file inode read and write. These caches can effectively shorten the time for I/O system calls (such as read,write,getdents). Remember that the memory is for use, not to take a look. Unlike windows, no matter how much of your real physical memory, he will have to take the hard disk swap files to read. This is why Windows often prompts for a lack of virtual space. You think, how boring, in memory and most of the time, Take out some of the hard disk space to act as memory. So we look at Linux, as long as the swap space without swap, there is no need to worry about their memory too little. If you use a lot of swap, you might want to consider adding physical memory. This is the standard for Linux to see if memory is adequate.
Syntax: free [-bkmotv][-s < interval of seconds;]
Additional Note: The free instruction shows memory usage, including physical memory, virtual swap file memory, shared memory segments, and buffers used by the system core.
Parameters
-B Displays memory usage in bytes.
-K displays memory usage in kilobytes.
-m displays memory usage in megabytes.
-O does not display buffer throttling columns.
-s< interval seconds > Continuous observation of memory usage.
-T displays the memory sum column.
-V Displays version information.
Common operations:
Free//In kilobytes, explicit system memory usage
Free-ml-s 1/Per second in M, explicit system memory detail usage.
Free-c 4-s 2//KB, explicit system memory usage every 2 seconds, total display 4 times
Linux free Command Detailed