Reprinted -Linux cached issue is too high

Command Linux release memory:
Sync
echo SYS 1> / proc / / vm / drop_caches

value drop_caches can be a number from 0-3, representing different meanings:
0: Do not release (the default value)
1: released page cache
2: release dentries and inodes
3: release all cache

release complete change it back after memory let the system automatically re-allocate memory.
0 echo> / proc / SYS / vm / drop_caches

as Free # -m to see if the memory has been freed.

If we need to release all the cache, enter the following command:
echo 3> / proc / SYS / vm / drop_caches

######### Knowledge ########### Linux release memory ####

in the Linux system, we generally do not need to free up memory, because the system has a very good memory management. But there are exceptions to everything, sometimes out of the cache memory will be occupied, causing the system to use SWAP space affect performance, such as when you frequently accessed files in linux, physical memory will soon be exhausted, when the program ends, the memory It will not be a normal release, but has been used as caching. , Then you need to perform a free memory (to clear the cache) of the operation.

Caching mechanism Linux system is quite advanced, he will for the dentry (for VFS, accelerated file pathname to inode conversion), Buffer Cache (for read and write disk blocks) and Page Cache (read-write file for the inode) cache operation. But after carrying out a large number of file operations, cache memory will run out of basic resources. But in fact we file operation has been completed, this part of the cache has been less than the. This time, we not only watch the cache memory space occupied off? So, we still need to manually release the memory to operate under Linux, in fact, is releasing a cache of operation. / proc is a virtual file system, we can serve as a means to communicate with the kernel between entities through its read and write operations. That can modify the proc file / to make the behavior of the current kernel adjustment. then we can release memory by adjusting the / proc / sys / vm / drop_caches . To achieve the purpose of freeing the cache, we first need to understand the key configuration files under / proc / sys / vm / drop_caches . This document records the release of cache parameters, the default value is 0, that is, do not release the cache.

After copying the files generally, less memory will become available, are cached occupied, this is linux file read in order to improve the efficiency of the practice: To improve the efficiency of disk access, Linux made some careful design, in addition to the dentry cache (for VFS, accelerated file pathname to inode conversion), Cache also taken two main ways: Buffer Cache and Page Cache. The former disk blocks for reading and writing, which read and write file for the inode. These Cache effectively shortening the time I / O system calls (such as read, write, getdents) of. "

Before releasing memory to use the sync command to synchronize and to ensure the integrity of the file system, all unwritten system buffers written to disk, containing the modified i-node, it has been delayed block I / O read and write mapping file. otherwise the process of releasing the cache, you may lose unsaved files.

[[email protected] ~] # -m Free
             Total Free Used Shared buffers cached
Mem: 3918. 7979 7897 82 0 30
- / buffers / Cache: 3948 4031 is
Swap: 4996 438 4558

The first row of the memory system using a global perspective described by status:
total memory total
amount of memory used already in use, in general, the value will be relatively large, because it includes the value of the cache memory used by the application
number of memory free free
memory shared by multiple processes total shared
buffers cached, mainly for directory aspects, inode values, etc. (ls large directories can see this value increases)
cached cache for open file

memory using a second-line description of the application:
-buffers / cache amount of memory: used - buffers - cached
buffers / cache the amount of memory: free buffers cached
former value represents -buffers memory size / cache used by the application, used by subtracting the value of the cache
after value represents buffers / cache memory size available to all applications use, free plus cache the value of

the third row indicates the use of the swap:
used used
free unused 

available memory = free memory buffers cached.

Why free is so small, whether the application is closed after the memory is not released?
But in fact, we all know that this is because different Linux memory management and Windows, free small does not mean that memory is not enough, it should be the last to see the value of the second row free of: - / buffers / cache: 3948 4031 , this is available to the system memory size.

The actual project experience tells us that if the application is because there is like a memory leak, overflow problem, from the use of swap that can be relatively quick to judge, but free above would be more difficult to see. I feel that since the core can be quickly emptied buffer or cache, but the core has not done so (the default value is 0), we should not just go and change it.

Under normal circumstances, the application running on the system a stable, free value will remain at a stable value, although may seem relatively small. In the event of insufficient memory, applications get less available memory, OOM errors and other problems, or should go to analyze the reasons applications, such as user too big lead to insufficient memory, application memory overflow situation occurs, otherwise empty the buffer, forced make free size, it may be just the issue to temporarily shield, so that linux under normal circumstances do not often manually release the memory.

 

 

1, cached responsible for use cache files, log files, caused by too much cached memory area to increase the memory footprint finish.

Free buffer and the cache memory for which are :():
buffer: a buffer cache memory, the block is read device buffer
cache: a page cache memory, a file system cache
if the cache is large values, Description number many files cache live.

Linux memory management do a lot of careful design, in addition to the dentry cache (for VFS, accelerated file pathname to inode conversion), Cache also taken two main ways: Buffer Cache and Page Cache, the purpose is to enhance the disk the IO performance. Block read from the low-speed device data temporarily stored in the memory, even when the data is no longer needed at the time, but the time to access the data in the application, it can be read directly from memory, thereby bypassing the low speed block device, thereby improving overall system performance. And Linux can take advantage of these free memory, design memory is not as good as idle bring multi-cache some data, such as access to the program again next time these data speed is fast, but if you want to use the system memory and the memory is inadequate , then instead of using a swap partition, but quickly recovered part of the cache, they are left to the user program.

Therefore, it can be seen, buffers / cached is really everything to gain and no harm, real harm could allow users to produce an illusion --Linux memory consumption! In actual fact, Linux did not eat your memory, as long as not been used to the swap partition, when your memory is running out, you should feel lucky, because Linux caches a lot of data, maybe next time you will benefit from it!

2, manual release cached

To free pagecache:  echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:  echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:  echo 3 > /proc/sys/vm/drop_caches

 
 
 

 

When you frequently accessed files in Linux, physical memory will soon be exhausted, when the program ends, the memory will not be a normal release, but has been as caching. This problem looks like there are a lot of people asking, but did not see any good solution. well, I'll talk about this issue. 

First is that the free command 

[root@server ~]# free -m  
total used free shared buffers cached  
Mem: 249 163 86 0 10 94  
-/+ buffers/cache: 58 191  
Swap: 511 0 511 

among them: 

total amount of memory 

The amount of memory used already in use 

free number of free memory 

The total shared memory shared by multiple processes 

buffers Buffer Cache and cached Page Cache disk cache size 

-buffers / cache amount of memory: used - buffers - cached 

+ Buffers / cache amount of memory: free + buffers + cached 

可用的memory=free memory+buffers+cached 

With this foundation after, you can learn, I'm used to 163MB, free to 86, buffer, respectively 10, 94 and cached 

So let's see if I execute copying files, memory what happens. 

[root@server ~]# cp -r /etc ~/test/  
[root@server ~]# free -m  
total used free shared buffers cached  
Mem: 249 244 4 0 8 174  
-/+ buffers/cache: 62 187  
Swap: 511 0 511 

After the command execution, used to 244MB, free to 4MB, buffers to 8MB, cached to 174MB, my God are cached eaten. Do not be nervous, which is to improve the efficiency of document reading practice. 

Reference http://www.wujianrong.com/archives/2007/09/linux_free.html "In order to improve the efficiency of disk access, Linux made some careful design, in addition to the dentry cache (for VFS, accelerated file path name to inode conversion), Cache also taken two major ways:.. Buffer Cache and Page Cache read and write disk blocks for the former, the latter for read and write these files inode Cache effectively reduce the I / O system calls (such as read, write, getdents) time. " 

It has been said time period, linux will automatically freed memory is used, we use a free to try again to see if there release>? 

[root@server test]# free -m  
total used free shared buffers cached  
Mem: 249 244 5 0 8 174  
-/+ buffers/cache: 61 188  
Swap: 511 0 511 

MS has not changed, then I can be manually relieved these memory? The answer is yes! 

/ Proc is a virtual file system, we can serve as a means to communicate with the kernel between entities through its read and write operations. That can modify the proc file / to make the behavior of the current kernel The adjustment then we can free up memory by adjusting the / proc / sys / vm / drop_caches as follows: 

[Test Server the root @] CAT # / proc / SYS / VM / drop_caches  
0  
values First, / proc / sys / vm / drop_caches default is 0 

[root@server test]# sync 

Perform a manual sync command (Description:. Sync command to run the sync subroutine If you must stop the system, run the sync command to ensure the integrity of the file system .sync command of all unwritten system buffers written to disk, it contains the modified the i-node, the delayed block I / O read and write, and mapping file) 

[root@server test]# echo 3 > /proc/sys/vm/drop_caches 
[root@server test]# cat /proc/sys/vm/drop_caches 
3 
  • 1
  • 2
  • 3

The / proc / sys / vm / drop_caches value is set to 3 

[root@server test]# free -m 
total used free shared buffers cached 
Mem: 249 66 182 0 0 11 -/+ buffers/cache: 55 194 Swap: 511 0 511 
  • 1
  • 2
  • 3
  • 4
  • 5

Again run free command, found now used as 66MB, free for the 182MB, buffers as 0MB, cached to 11MB. So effectively release the buffer and cache. 

About the / proc / sys / vm / drop_caches usage are described below 

/proc/sys/vm/drop_caches (since Linux 2.6.16) 
Writing to this file causes the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. To free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches; to free pagecache, dentries and inodes, use echo 3 > /proc/sys/vm/drop_caches. Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync(8) first

Guess you like

Origin www.cnblogs.com/doufy/p/11198802.html
Recommended