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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to manually free memory in Linux. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
Linux commands to free memory:
sync``echo 1 > /proc/sys/vm/drop_caches
drop_caches can be a number between 0 and 3, representing different meanings: 0: do not release (system default) 1: release page cache 2: release entries and inodes 3: release all cache
After freeing memory, change back to let the system automatically reallocate memory.
echo 0 >/proc/sys/vm/drop_caches
free -m #See if memory has been freed.
If we need to release all caches, we can enter the following command:
echo 3 > /proc/sys/vm/drop_caches
##################
On Linux, we generally don't need to free memory because the system already manages memory well. However, there are exceptions to everything. Sometimes memory will be occupied by cache, causing the system to use SWAP space to affect performance. For example, when you frequently access files under linux, physical memory will soon be used up. When the program ends, memory will not be released normally, but will always be used as caching. At this point, you need to perform the operation of releasing memory (cleaning cache).
Linux cache mechanism is quite advanced, he will be for dentry (for VFS, speed file path name to inode conversion), Buffer Cache (for disk block read and write) and Page Cache (for file inode read and write) cache operations But after a lot of file operations, the cache will run out of memory resources. But in fact, our file operation has been completed, and this part of the cache is no longer needed. At this point, can we just watch the cache take up memory space? Therefore, we still need to manually release memory under Linux, in fact, that is, release cache operation./ proc is a virtual file system that we can read and write to as a means of communicating with kernel entities. This means that you can modify the behavior of the kernel by modifying files in/proc. Then we can free up memory by adjusting/proc/sys/vm/drop_caches. To release the cache, we first need to understand the key configuration file/proc/sys/vm/drop_caches. This file records the cache release parameters, the default value is 0, that is, do not release cache.
Generally, after copying files, the available memory will become less and will be occupied by cached. This is the practice of Linux in order to improve the efficiency of file reading: In order to improve the efficiency of disk access, Linux has made some elaborate designs. In addition to caching dentries (used for VFS, accelerating the conversion of file path names to inode), it also adopts two main caching methods: Buffer Cache and Page Cache. The former is for reading and writing disk blocks, while the latter is for reading and writing file inode. These caches effectively shorten the time of I/O system calls (such as read,write,getdents). "
Sync before freeing memory to ensure file system integrity, writing all unwritten system buffers to disk, including modified i-nodes, deferred block I/O, and read-write mapping files. Otherwise, unsaved files may be lost during the cache release process.
[root@fcbu.com ~]# free -m total used free shared buffers cached Mem: 7979 7897 82 0 30 3918 -/ buffers/cache: 3948 4031 Swap: 4996 438 4558
The first line describes the memory used by the system from a global point of view: total memory used The amount of memory already used, usually this value is relatively large, because this value includes the memory used by cache applications free The total amount of memory shared by multiple processes buffers, mainly used for directories,inode values, etc.(ls large directories can see this value increasing) cached cache, used for open files
The second line describes the memory usage of the application: -buffers/cache memory:used-buffers-cached buffers/cache memory:free buffers cached The first value indicates the memory size used by the application, used minus the cache value The second value indicates buffers/cache all memory size available to the application, free plus the cache value
The third line indicates the use of swap: used free unused
Free memory buffers cached.
Why is free so small? Is memory not released after closing the app? But in fact, we all know that this is because Linux memory management is different from Windows, free small does not mean that there is not enough memory, you should look at the second line of free last value: -/ buffers/cache: 3948 4031, this is the system available memory size.
The experience in the actual project tells us that if there is a problem like memory leakage or overflow in the application, it can be judged quickly from the use of swap, but it is more difficult to view free. I feel that since the kernel can quickly empty the buffer or cache, but the kernel does not (default is 0), we should not change it casually.
In general, the application runs stably on the system, and the free value stays at a stable value, although it may seem small. When there is insufficient memory, the application can not obtain available memory, OOM errors and other problems, or should be more to analyze the application of the reasons, such as too large a number of users resulting in insufficient memory, application memory overflow, etc., otherwise, clear the buffer, forced to free the size, may only temporarily shield the problem, so that under normal circumstances linux do not often manually release memory.
Thank you for reading! About "how to manually release memory in Linux system" This article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see 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.