Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Cache memory release

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Recently, there was a kernel error on the server, which caused the real machine to go down and the remote network connection could not be connected, but the virtual machine still worked properly. Found a lot of information, suspected to be a memory problem. # free-m # results are shown in figure

It is found that the value of cache is very large. Because of the kernel mechanism of LINUX, there is no need to release the cache that is already used. The contents of these cache can increase the speed of reading and writing files as well.

Let's first talk about how the free command looks at memory.

The first line describes the memory used by the system from a global point of view:

Total physical memory of total--

Used-- has used memory, which is generally larger because it includes the memory used by cache+ applications

Free-- completely unused memory

Shared-- application shared memory

Buffers-- cache, mainly used for directories, inode value, etc. (this value can be seen in the ls directory)

Cached-- cache for open files

Note:

Total=used+free

Used=buffers+cached (maybe add shared also)

The second line describes the memory usage of the application:

The first value represents-the amount of memory used by the buffers/cache-- application, used minus the cache value

The latter value represents + buffers/cache-- all the memory available to the application, free plus cache value

Note:

-buffers/cache=used-buffers-cached

+ buffers/cache=free+buffers+cached

The third line represents the use of swap:

Used-- has been used

Free-- is not in use

Cache release:

# sync

Execute the sync command manually (description: the sync command runs the sync subroutine. If the system must be stopped, run the sync command to ensure the integrity of the file system. The sync command writes all unwritten system buffers to disk, including the modified i-node, deferred block Imax O, and read-write mapping file)

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

Note: it is best to sync before release to prevent data loss.

View free-h results

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 are problems such as insufficient memory, lack of available memory for applications, and OOM errors, it is more important to analyze the reasons for applications, such as insufficient memory caused by too many users, application memory overflow, etc. Otherwise, clearing buffer and forcing the size of free may only block the problem temporarily.

In my opinion, except in the case of insufficient memory, unless the buffer needs to be temporarily cleared during the software development phase to determine the memory usage of the application, or the application no longer provides support, even if the application does have problems with memory and is unavoidable, consider emptying the buffer regularly. (unfortunately, such applications usually run on the old version of the operating system, and the above operations cannot be solved.)

= =

Technology Exchange QQ:1359962567 (↗ freeda)

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report