Linux free-m Detailed description

Source: Internet
Author: User

The free command provides a more concise view of system memory usage relative to top:
$ free

Total used free shared buffers Cached
mem:255268 238332 16936 0 85540 126384
-/+ buffers/cache:26408 228860
swap:265000 0 265000 some of the relevant notes:Mem: Indicates physical memory statistics
-/+ buffers/cached: Cache statistics representing physical memory
Swap: Indicates the usage of the swap partition on the hard disk (we don't care here)
Total physical memory of the system: 255268Kb (256M), but the actual memory currently available to the system is not the 16936Kb of the first line of the free tag, it represents only unallocated memory.
We use names such as Total1, Used1, Free1, Used2, and free2 to represent the values of the above statistics, and 1 and 2 represent the data for the first row and the second row respectively. Total1: Represents the total amount of physical memory.
Used1: 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.
FREE1: Memory that has not been allocated.
SHARED1: Shared memory, the general system will not be used, nor discussed here.
Buffers1: The number of buffers that are allocated but not used by the system.
Cached1: The number of caches that the system allocates but has not been used. The difference between buffer and cache is shown later. USED2: The total amount of buffers and caches actually used, as well as the amount of memory actually used.
Free2: The sum of unused buffers with the cache and unallocated memory, which is the current actual memory available to the system. You can sort out the following equation:
Total1 = used1 + free1
Total1 = Used2 + free2
used1 = buffers1 + cached1 + used2
Free2 = buffers1 + cached1 + free1 buffer differs from cache
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 a more detailed explanation reference: difference between Buffer and Cache
For shared memory, which is primarily used to share data between different processes in a UNIX environment, is a method of interprocess communication, and the general application does not request the use of shared memory, nor does the author verify the effect of shared memory on the above equation.  If you are interested, please refer to: What is Shared Memory? The difference between cache and buffer:
Cache: Caching is a small but high-speed memory that sits between the CPU and the main memory. Because the CPU speed is much higher than the main memory, the CPU accesses the data directly from memory to wait for a certain period of time, the cache holds the CPU just used or recycled part of the data, when the CPU again use the part of the data can be directly called from the cache, which reduces the CPU waiting time, The efficiency of the system is high. The cache is also divided into one-level cache (L1 cache) and level two cache (L2 cache), L1 cache is integrated within the CPU, L2 cache is usually soldered to the motherboard, and is now integrated into the CPU, with a common capacity of 256KB or 512KB L2 Cache.
Buffer: An area where data is transferred between devices that are not synchronized or that have different priority levels.  Through buffers, you can reduce the number of waits between processes, so that when you read data from a slow device, the operating process of a fast device is uninterrupted. Buffer and cache in free: (They are all memory-intensive):
Buffer: Memory as buffer cache, is BlockRead and write buffers for devices
Cache: As page cache memory, the file system cache if the cache value is large, the cache has a lot of files. If the files that are frequently accessed are available to the cache, the disk's read Io bi is very small. The buffer and cache differential caches (cached) are to take the data that has been readSave it, re-read if hit (find the required data) do not read the hard disk, if not hit the hard drive.    The data will be organized according to the frequency of reading, the most frequently read content in the most easily found in the location, the content is no longer read to the back row, until removed from it. Buffering (buffers) is based on disk Read and writeDesigned to centralize distributed write operations, reducing disk fragmentation and repeated seek of hard drives to improve system performance. Linux has a daemon that periodically empties buffered content (that is, writes like a disk) or manually empties the buffer via the Sync command. For example: I have a ext2 u disk here, I went to the inside CP a 3M MP3, but the U disk's light does not beat, after a while (or manually input sync) u disk light will beat up. The buffering is emptied when the device is uninstalled, so there are times when uninstalling a device takes a few seconds.

Modifying the number to the right of vm.swappiness in/etc/sysctl.conf can adjust the swap usage policy at the next boot. The number range is 0~100, and the larger the number, the more likely it is to use swap. The default is 60, you can change it to try.
Both are data in RAM. In a nutshell, buffer is about to be written to disk, and the cache is read from disk.
Buffer is allocated by various processes and is used in areas such as input queues, a simple example where a process requires multiple fields to be read, and before all fields are read into full, the process saves the previously read-in fields in buffer.
The cache is often used on disk I/O requests, and if more than one process accesses a file, the file is made into a cache for next access, which provides system performance.

Linux memory management, in fact, and Windows memory management has a very similar place, are using the concept of virtual memory, said here have to scold MS, why in many times there is a lot of physical memory, but still use the pagefile. So often to argue with a bunch of people say the size of the pagefile, and how to assign this problem, in Linux we do not have to fight what swap size problem, I personally think, swap set a 512M is enough, if you ask that 512M swap is not enough to do? Can only say eldest brother you still add memory bar, or check your application, is not really appear memory leak.

View memory under Linux We generally use command free
[[Email Protected]namelinux ~]# Free
Total used free shared buffers Cached
mem:386024 3771168908021280 155468
-/+ buffers/cache:200368185656
swap:393552 0 393552
Here is an explanation of these values:
Second line (MEM):
Total: The amount of physical memory.
Used: How large is used.
Free: How much is available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third line (-/+ buffers/cached):
Used: How large is used.
Free: How much is available.
There is not much to explain in line four.
Difference:
The used/free of the second line (MEM) differs from the third row (-/+ Buffers/cache) used/free.
The difference between the two is that the first line is from the OS point of view, because for the os,buffers/cached are all belong to be used, so his available memory is 8908KB, the used memory is 377116KB, which includes, the kernel (OS) uses + The +buffers+cached used by Application (X,ORACLE,ETC).
The third line refers to the application from the point of view, buffers/cached is equal to the availability of the application, because buffer/cached is to improve the performance of the file read, when the application needs to use memory, buffer/cached will be quickly recycled.
So from the application's point of view, available memory = System free (memory+buffers+cached.)
As in the above example:
185656=8908+21280+155468
Next, explain when the memory will be exchanged, and by what side.
When the available memory is less than the rated value, a meeting is exchanged.
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.

Linux free-m Detailed description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.