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

What is the introduction of Swap, Cache and Buffer in Linux's memory

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Linux memory Swap and Cache and Buffer introduction is what, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Total: total memory size.

Used: the amount of memory that has been used (this includes cached and buffers and shared sections).

Free: the amount of free memory.

Shared: shared memory between processes (usually not used and can be ignored).

Buffers: things written in memory are cached so that requests are responded quickly, and later data is periodically brushed to disk.

Cached: the amount of content that is cached after reading in memory (this part is for quick return on the next query).

-/ + buffers/cache is regarded as two parts:

-buffers/cache: the amount of memory being used (note that it is not the used section, because buffers and cached are not being used, and organizations and people need them to be freed), with a value of = used-buffers-cached.

+ buffers/cache: the amount of memory available (similarly not the part represented by free), with a value of = free+buffers+cached.

Swap: the size of the swap partition used on the hard disk.

The purpose of the design is that when the available memory indicated by the + buffers/cache mentioned above has been used up, when the new read and write requests come, part of the data in the memory will be written to the disk, thus using part of the disk space as virtual memory.

2. Introduction to Buffer and Cache

Cache (cache), designed to increase the exchange of data between CPU and memory, and Buffer (buffer) is designed to improve the exchange of data between memory and hard disk (or other Imax O devices).

Cache is mainly designed for read operations, but the concept of Cache may be easily confused. I understand that CPU itself has Cache, including first-level cache, second-level cache and third-level cache. We know that all instruction operations of CPU are docked with memory, and the processing power of CPU is much higher than memory speed, so in order not to let CPU resources idle, Intel and other companies have integrated some Cache in CPU, but after all, they can't put too many circuits in it. So this part of the Cache is not very large, mainly used to store some commonly used instructions and data, the real majority of Cache data should take up memory space to cache the requested data, that is, the above Cached part (this part is purely personal understanding, whether it is correct or not remains to be verified).

Buffer is mainly designed for write operations, and more specifically for write operations between memory and hard disk. The purpose is to centralize write operations, reduce disk fragmentation and repeated addressing process of hard disk, and improve performance.

Within the Linux system, there is a daemon that periodically empties the contents of the Buffer and writes it to the hard disk, which is also triggered when the sync command is executed manually.

3. Common symptoms

Symptom 1: frequently accessing files in Linux, physical memory runs out quickly, and cached is growing all the time.

Explanation: Linux caches the requested data in cache. The advantage is that the processing speed of CPU is much higher than that of memory, so it can quickly return the hit result from cache when CPU communicates with memory.

Symptom 2: Swap is occupied.

Explanation: there may not be enough memory to take up Swap, so Swap can be used as an indicator for server monitoring to attract attention.

4. Manually clean up Swap and buffers/cache

(1) Clean up Swap

Swapoff-a & & swapon-a

Operation instructions: if Swap has been used and there is still space under + buffers/cache, when performing the swapoff-an operation, it will trigger swapping the contents of Swap to memory, and the data will not be lost.

(2) Clean up buffers/cache:

Sync; sync; sync;&& echo 3 > / proc/sys/vm/drop_caches sleep 2 echo 0 > / proc/sys/vm/drop_caches

Operation instructions:

Sync-- > write the inner part of the cache back to the hard disk; echo 3 > / proc/sys/vm/drop_caches-- > modify the value of drop_caches to 3, default is 0, and the system will clean up the contents of the cache if changed to 3; sleep 2-- > wait a minute to prevent the previous step from being completed; echo 0 > / proc/sys/vm/drop_caches-- > change it back to the default value

5. Summary

From the above analysis, we can know that when there is not much free physical memory, it does not necessarily mean that the system is running poorly, because the cache and buffer parts of memory can be reused at any time, in a sense, these two parts of memory can also be regarded as additional free memory.

If swap is called frequently and bi,bo is not zero for a long time, it is the basis of whether memory resources are tight. When you look at resources through free, you can tell whether there is enough memory by focusing mainly on the value of-/ + buffers/cache.

After reading the above, have you mastered the introduction of Swap and Cache and Buffer in Linux's memory? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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