[Reprint] Linux in the buff / cache memory usage is too high solution on Linux buff / cache memory usage is too high solution

Linux in the buff / cache memory usage is too high solution

 

HTTPS: // www.cnblogs.com/rocky-AGE-24/p/7629500.html
 
/ proc / SYS / vm / drop_caches 

knowledge of the contents of linux is still very complex learning needs on the line.

 

On Linux systems, we often use the free command to view the system memory use. A centos7 on the system, the command displays the contents free of something like a state:

 

 

This command is almost every person must be used Linux commands, but more so the command, the less it seems really understand people (I mean the less proportion). In general, the understanding of this command's output can be divided into several levels:

  1. Do not understand. The first reaction is that such people: God, with a lot of memory, more than 14 G, but I have almost no big running ah? Why is this so? Linux accounted for a good memory!

  2. I think very understanding. Such people are generally assessed will say: ah, my professional eye to see out of memory only spent about 1.7G, there are a lot of free memory available. buffers / cache occupied large, indicating that the system has the process been used to read and write files, but it does not matter, this memory when idle to use.

  3. Really understand. Such people's reaction but people feel most do not understand Linux, their reaction was: is this free show, well I know. What? You ask me these memory enough, I certainly do not know it! I know how special it how to write your program?

According to the contents of the current technical documentation on the Web, I believe most people should understand that Linux is in the second level. It was widely felt, buffers and cached memory occupied space can be released as a free space in the larger memory pressure when used. But really the case? Prior to demonstrate this problem, we first briefly describe buffers and cached what it means:

What is the buffer / cache?

buffer cache and there will be two different meanings under indiscriminate use of the term, on the barrier in the context of computer technology. In the Linux memory management, buffer here refers to the Linux memory: Buffer cache. cache here refers to the Linux memory: Page cache. Translated into Chinese can be called the buffer cache and page cache. Historically, they are a (buffer) is used as a cache to write io equipment, while the other (cache) is used as read caching devices io, io equipment here, mainly referring to the block device file and ordinary file on the file system. But now, they have not the same meaning. In the current kernel, the name suggests is for the cache page cache memory page, it means that if there is a memory page allocation management, you can use the page cache as a cache to manage its use. Of course, not all memory is in pages (page) managed, many are managed for the block (block), this part of the memory usage If you want to cache function, are concentrated in the buffer cache to use. (From this point of view, is not called a block cache buffer cache renamed better?) However, not all blocks (block) has a fixed length, the length of the block on the system mainly based on block devices used by the decision, and the page X86 length in either 32-bit or 64-bit is 4k.

Understand the difference between these two sets of system cache, we can understand what exactly they can be used to do.

What is the page cache?

Page cache is mainly used as a cache file data on the file system to use, especially when the process there is a time for file read / write operations. If you think about it, you can map the file into memory as a system call: mmap is not very natural should also use page cache? In the current system implementation where, as a page cache is also another type of file caching device to use, so in fact the cache page cache is also responsible for most of the work block device file.

What is the buffer cache

Buffer cache is mainly used when the system is designed to block read and write device, the block data cache system to use. This means that some of the operations will use the buffer cache block cache, such as when we are in the format of the file system. Under normal circumstances, together with two cache system is used, such as when we write to a file, the contents page cache will be changed, and the buffer cache can be used to mark different page buffers, and which is a record buffer was changed. In this way, the kernel in the subsequent execution of dirty data write-back (writeback), would not the entire page write back, but just need to write back the modified part can be.

How to recycle cache?

Linux kernel when the memory will be depleted, triggering garbage collection work in order to release the much-needed memory to the memory used by the process. In general, this operation comes from the main memory to the release of the release buffer / cache is. Especially by using more cache space. Since it is mainly used for caching, just speed up the process of file read and write speeds at the time of memory enough, then in larger memory pressure, of course, it is necessary to empty the release of cache, and give the relevant process used as a free space. Therefore, under normal circumstances, we believe buffer / cache space can be released, this understanding is correct.

But this clear the cache work is not without cost. Understand the cache is doing can understand the clear cache must be consistent with the data in the cache data corresponding to the file, in order for the cache to be released. So along with the cache cleared of behavior are generally system IO skyrocketed. Because data on whether the kernel cache in comparison to the corresponding data and hard disk file, and if not need to write back before you can recover.

Except when memory is exhausted outside can clear the cache, we can use the following file system cache clearing operation to manually trigger:

[root@tencent64 ~]# cat /proc/sys/vm/drop_caches 
1

the way is:

echo 1 > /proc/sys/vm/drop_caches

Of course, the value of this file can be set 1,2,3, respectively. Meaning that they represent are:

echo 1> / proc / sys / vm / drop_caches: Clears pagecache. 
echo 2> / proc / sys / vm / drop_caches: represents scavenged slab allocator object (including a cache directory entry and the inode cache). The slab allocator is a mechanism in the kernel memory management, cache data to achieve many of which are used in pagecache. 
echo 3> / proc / sys / vm / drop_caches: clears the cache object and pagecache slab dispenser.

After optimization shots are as follows:

 

 

On Linux systems, we often use the free command to view the system memory use. A centos7 on the system, the command displays the contents free of something like a state:

 

 

This command is almost every person must be used Linux commands, but more so the command, the less it seems really understand people (I mean the less proportion). In general, the understanding of this command's output can be divided into several levels:

  1. Do not understand. The first reaction is that such people: God, with a lot of memory, more than 14 G, but I have almost no big running ah? Why is this so? Linux accounted for a good memory!

  2. I think very understanding. Such people are generally assessed will say: ah, my professional eye to see out of memory only spent about 1.7G, there are a lot of free memory available. buffers / cache occupied large, indicating that the system has the process been used to read and write files, but it does not matter, this memory when idle to use.

  3. Really understand. Such people's reaction but people feel most do not understand Linux, their reaction was: is this free show, well I know. What? You ask me these memory enough, I certainly do not know it! I know how special it how to write your program?

According to the contents of the current technical documentation on the Web, I believe most people should understand that Linux is in the second level. It was widely felt, buffers and cached memory occupied space can be released as a free space in the larger memory pressure when used. But really the case? Prior to demonstrate this problem, we first briefly describe buffers and cached what it means:

What is the buffer / cache?

buffer cache and there will be two different meanings under indiscriminate use of the term, on the barrier in the context of computer technology. In the Linux memory management, buffer here refers to the Linux memory: Buffer cache. cache here refers to the Linux memory: Page cache. Translated into Chinese can be called the buffer cache and page cache. Historically, they are a (buffer) is used as a cache to write io equipment, while the other (cache) is used as read caching devices io, io equipment here, mainly referring to the block device file and ordinary file on the file system. But now, they have not the same meaning. In the current kernel, the name suggests is for the cache page cache memory page, it means that if there is a memory page allocation management, you can use the page cache as a cache to manage its use. Of course, not all memory is in pages (page) managed, many are managed for the block (block), this part of the memory usage If you want to cache function, are concentrated in the buffer cache to use. (From this point of view, is not called a block cache buffer cache renamed better?) However, not all blocks (block) has a fixed length, the length of the block on the system mainly based on block devices used by the decision, and the page X86 length in either 32-bit or 64-bit is 4k.

Understand the difference between these two sets of system cache, we can understand what exactly they can be used to do.

What is the page cache?

Page cache is mainly used as a cache file data on the file system to use, especially when the process there is a time for file read / write operations. If you think about it, you can map the file into memory as a system call: mmap is not very natural should also use page cache? In the current system implementation where, as a page cache is also another type of file caching device to use, so in fact the cache page cache is also responsible for most of the work block device file.

What is the buffer cache

Buffer cache is mainly used when the system is designed to block read and write device, the block data cache system to use. This means that some of the operations will use the buffer cache block cache, such as when we are in the format of the file system. Under normal circumstances, together with two cache system is used, such as when we write to a file, the contents page cache will be changed, and the buffer cache can be used to mark different page buffers, and which is a record buffer was changed. In this way, the kernel in the subsequent execution of dirty data write-back (writeback), would not the entire page write back, but just need to write back the modified part can be.

How to recycle cache?

Linux kernel when the memory will be depleted, triggering garbage collection work in order to release the much-needed memory to the memory used by the process. In general, this operation comes from the main memory to the release of the release buffer / cache is. Especially by using more cache space. Since it is mainly used for caching, just speed up the process of file read and write speeds at the time of memory enough, then in larger memory pressure, of course, it is necessary to empty the release of cache, and give the relevant process used as a free space. Therefore, under normal circumstances, we believe buffer / cache space can be released, this understanding is correct.

But this clear the cache work is not without cost. Understand the cache is doing can understand the clear cache must be consistent with the data in the cache data corresponding to the file, in order for the cache to be released. So along with the cache cleared of behavior are generally system IO skyrocketed. Because data on whether the kernel cache in comparison to the corresponding data and hard disk file, and if not need to write back before you can recover.

Except when memory is exhausted outside can clear the cache, we can use the following file system cache clearing operation to manually trigger:

[root@tencent64 ~]# cat /proc/sys/vm/drop_caches 
1

the way is:

echo 1 > /proc/sys/vm/drop_caches

Of course, the value of this file can be set 1,2,3, respectively. Meaning that they represent are:

echo 1> / proc / sys / vm / drop_caches: Clears pagecache. 
echo 2> / proc / sys / vm / drop_caches: represents scavenged slab allocator object (including a cache directory entry and the inode cache). The slab allocator is a mechanism in the kernel memory management, cache data to achieve many of which are used in pagecache. 
echo 3> / proc / sys / vm / drop_caches: clears the cache object and pagecache slab dispenser.

After optimization shots are as follows:

 

 

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11982536.html