free -h
total used free shared buff/cache available
Mem: 3.7G 1.1G 1.4G 1.0M 1.2G 2.4G
Swap: 0B 0B 0B
used: Used memory
free: Memory left at present
shared: Memory shared by multiple programs
buff/cache: File search ,inode, Cache like that , Improve performance
available: Represents the memory that an application can apply for
buff(Buffer Cache) It's a kind of IO cache , Buffer for memory and hard disk , yes io The device's read / write buffer . According to the disk read and write design , Centralize distributed write operations , Reduce disk fragmentation and hard disk repeat seek , To improve system performance .
cache(Page Cache) It's a kind of cache , be used for CPU Buffer between and memory , It's the file system cache.
Save the read data , Re read if hit ( Find the data you need ) Don't read the hard disk , If you don't hit the learning hard disk . The data is organized according to the frequency of reading , Put the most frequently read content in the easiest place to find , Keep going back to the back of what you no longer read , Until you remove .
They all take up memory . Both are RAM Data in . Simply speaking ,buff Is about to be written to disk , and cache It's read from the disk .
Available memory = free + buff/cache
Used memory = used + shared + buff/cache
eliminate buff/cache ( Use it carefully , eliminate cache, Reading the hard disk directly can cause too much pressure , Something bad happened )
* sync: Write all unwritten system buffers to disk , Include modified i-node、 Delayed block I/O And read-write mapping files
* echo 1 > /proc/sys/vm/drop_caches: eliminate page cache
* echo 2 > /proc/sys/vm/drop_caches: Clear and recycle slab The object in the allocator ( Includes directory item cache and inode cache ).slab An allocator is a mechanism for managing memory in the kernel , Many of these cache data implementations are used pagecache.
* echo 3 > /proc/sys/vm/drop_caches: eliminate pagecache and slab The cache object in the allocator .
/proc/sys/vm/drop_caches Value , The default is 0