In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Linux command to free memory:
Syncecho 1 > / proc/sys/vm/drop_caches
The value of drop_caches can be a number between 0 and 3, representing different meanings:
0: no release (system default)
1: release the page cache
2: release dentries and inodes
3: release all caches
After releasing the memory, change it back and let the system reallocate the memory automatically.
Echo 0 > / proc/sys/vm/drop_cachesfree-m # to see if memory has been freed.
If we need to release all caches, enter the following command:
Echo 3 > / proc/sys/vm/drop_caches
# knowledge of Linux freeing memory #
Under the Linux system, we generally do not need to release memory, because the system has managed the memory very well. But there are exceptions to everything. Sometimes the memory will be occupied by the cache, causing the system to use SWAP space to affect performance. For example, when you access files frequently under linux, the physical memory will be used up quickly. When the program is finished, the memory will not be released normally, but will always be used as caching. At this point, you need to free memory (clean up the cache).
The caching mechanism of the Linux system is quite advanced, caching for dentry (for VFS to accelerate file pathname to inode conversion), Buffer Cache (for disk block read and write), and Page Cache (for file inode read and write). However, after a large number of file operations, the cache will basically use up memory resources. But in fact, our file operation has been completed, this part of the cache is no longer needed. At this time, can we just watch the cache take up the memory space? Therefore, it is still necessary for us to manually free memory under Linux, which is actually the operation of freeing the cache. / proc is a virtual file system, and we can read and write it as a means to communicate with kernel entities. In other words, the current kernel behavior can be adjusted by modifying the file in / proc. Then we can free up memory by adjusting / proc/sys/vm/drop_caches. To achieve the goal of releasing slow storage, we first need to understand the key configuration file / proc/sys/vm/drop_caches. The parameter of cache release is recorded in this file, and the default value is 0, that is, the cache is not released.
Generally copy the file, the available memory will be less, are occupied by cached, this is linux to improve file reading efficiency: in order to improve disk access efficiency, Linux has done some careful design, in addition to caching dentry (for VFS, accelerate file pathname to inode conversion), but also adopted two main Cache methods: Buffer Cache and Page Cache. The former is for the read and write of disk blocks, and the latter is for the read and write of file inode. These Cache effectively shorten the time it takes to make system calls such as read,write,getdents. "
Use the sync command to synchronize before freeing memory to ensure the integrity of the file system, writing all unwritten system buffers to disk, including modified i-node, delayed block Imax O, and read-write mapping files. Otherwise, unsaved files may be lost during the release of the cache.
[root@fcbu.com] # free-m total used free shared buffers cachedMem: 7979 7897 82 0 30 3918 buffers/cache: 3948 4031Swap: 4996 438 4558
The first line describes the memory used by the system from a global perspective:
Total total memory
The amount of memory already used by used, which is generally larger because it includes the memory used by cache applications
Number of free memory in free
Total memory shared by multiple processes in shared
Buffers cache, mainly used for directories, inode value, etc. (this value can be seen in the ls directory)
Cached cache for open files
The second line describes the memory usage of the application:
-memory of buffers/cache: used-buffers-cached
Number of memory in buffers/cache: free buffers cached
The first value represents-the amount of memory used by the buffers/cache application, used minus the cache value
The latter value represents all the memory available to the application in buffers/cache, free plus the cache value
The third line represents the use of swap:
Used has been used
Free is not in use
Available memory = free memory buffers cached.
Why is the free so small that the memory is not freed after closing the application?
But in fact, we all know that this is because Linux manages memory differently from Windows. Just because free is small doesn't mean there is not enough memory. We should look at the last value in the second line of free:-/ buffers/cache: 3948 4031, which is the amount of memory available to the system.
Experience in the actual project tells us that if the application has problems such as memory leaks or overflows, it can be judged quickly from the usage of swap, but it is more difficult to check on free. I think since the core can quickly empty buffer or cache, but the core does not do so (the default is 0), we should not change it casually.
In general, when the application runs steadily on the system, the free value will remain at a stable value, although it may seem small. When there is insufficient memory, applications can not get available memory, OOM errors and other problems, it is more important to analyze the reasons for applications, such as insufficient memory caused by too many users, application memory overflow and so on. Otherwise, emptying buffer and forcing the size of free can only shield the problem temporarily, so linux generally does not have to release memory manually.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.