当前位置:网站首页>Causes of server buffer/cache and buffer/cache release
Causes of server buffer/cache and buffer/cache release
2022-07-22 17:15:00 【qq_ duhai】
Catalog
- One 、 What is? buffer/cache?
- Two 、 What is? page cache?
- 3、 ... and 、buffer/cache Some features needing attention
- Four 、 How to manually buffer/cache Recycling ?
- 5、 ... and 、buffer/cache How to check high is caused by those processes
One 、 What is? buffer/cache?
buffer/cache In fact, it is used as the file data cache of the server system , Especially for the process of file existence read/write During operation , So when your service process is reading and writing files ,Linux In order to improve the reading and writing speed of services , The file will be placed here buffer/cache For caching , because Linux The characteristic of service is that everything will exist in the form of documents , So you will find that whether or not you have done large-scale reading and writing to the file , Mechanical buffer/cache It always exists , And keep increasing , This is because the network connection generated by the server is good , User agreement (UDP) Socket, too , The data system in this part will create corresponding file descriptors for the application , And the use of these file descriptors , Will re-enter buffer/cache For reading and writing , So this is also your machine will always exist higher buffer/cache Why !( Because all documents will be used for reading and writing buffer/cache, When the memory is reasonable )
Two 、 What is? page cache?
Page cache It is mainly used as the cache of file data on the file system , Especially when the process has read/write During operation . If you think about it , As a system call that can map files to memory :mmap Is it natural to use page cache? In the current system implementation ,page cache It is also used as a cache device of other file types , So in fact page cache Also responsible for most of the block device file cache work .
3、 ... and 、buffer/cache Some features needing attention
When the service memory is sufficient ,Linux In order to speed up the efficiency of reading and writing files, the kernel will put files in buffer/cache in To ensure reading and writing efficiency , But in fact , Although when your application finishes reading and writing files ,buffer/cache This part of memory will not be released automatically , It is reserved as a buffer , Wait until your service process reads and writes the same file the next time , All operations of re initializing the memory are omitted ; So this will lead to , When your application process frequently reads and writes to different files , You will find that the service can be used directly free An important reason why memory will be less and less ; Don't buffer/cache In this endless cache, it will not be automatically released ? Of course not. , When the server is under high memory pressure , The memory will be recycled automatically , As free Space is allocated to other processes , One of the main memory reclaimed is buffer/cache Buffer memory block for ;
Four 、 How to manually buffer/cache Recycling ?
In addition to reclaiming memory when the system process memory is under great pressure , We can also do it manually buffer/cache Recycling , But because of buffer/cache It is mainly used for reading and writing files , So when you recycle files , Usually associated with a system IO Puma is high , Because the system kernel is also compared cache Whether the data in is consistent with the data in the hard disk , If inconsistent, write , Then the memory can be recycled ;
$ sync
# Force the data in memory to be flushed to disk first
clear Buffer Buffer area
$ echo 1 > /proc/sys/vm/drop_caches # Said clear pagecache.
$ echo 2 > /proc/sys/vm/drop_caches # Represents clean recovery slab The object in the allocator ( Includes directory item cache and inode cache ).slab An allocator is a mechanism for managing memory in the kernel , Many of these cache data implementations are used pagecache.
$ echo 3 > /proc/sys/vm/drop_caches # Said clear pagecache and slab The cache object in the allocator
If you have to clear the disk cache , The first command is the safest in the enterprise and production environment ,"...echo 1> ..."
It will only clear the page cache . The third option above is not recommended in production environments "...echo 3 > ..."
, Unless you know what you're doing , Because it will clear the cache page , Catalog entries and inodes.
stay Linux Release buffers that may be used by the kernel (Buffer) And caching (Cache) Is it a good idea ?
When you set many settings and want to check the effect , If it is actually specific to I/O Scope benchmarking , Then you may need to clear the buffer and cache . You can delete the cache as shown above , There is no need to restart the system ( That is, no shutdown is required ).
Linux It is designed to look in the disk cache before looking for the disk . If it finds the resource in the cache , Then the request will not be sent to disk . If we clean up the cache , Disk caching doesn't work , The system will look for resources on the disk .
Besides , When the cache is cleared, it will also slow down the system , The system will load each requested resource into the disk cache again .
Now? , We're going to create one shell Script , Through one cron Scheduling tasks every afternoon 2 Automatic clearing of points RAM cache . Create a shell Script clearcache.sh And add the following line :
#!/bin/bash
# Be careful , We use "echo 3", However, it is not recommended to use in the product environment , You should use echo 1
echo 3 > /proc/sys/vm/drop_caches"
to clearcache.sh File set execution permissions
# chmod 755 clearcache.sh
Now? , When you need to clear the memory cache, just call the script .
Now set a daily afternoon 2 Click the scheduled task to clear RAM cache , open crontab Editing .
# crontab -e
Add the following lines , Save and exit .
0 3 * * * /path/to/clearcache.sh
5、 ... and 、buffer/cache How to check high is caused by those processes
5.1 hcache install
$ wget https://silenceshell-1255345740.cos.ap-shanghai.myqcloud.com/hcache -O /usr/local/bin/hcache ;\
chmod +x /usr/local/bin/hcache
5.2 hcache Common commands
$ hcache --top 10 # Global display 10 The largest cached file
$ lsof /usr/lib/vmware-tools/lib64/libxerces-c-3.1.so/libxerces-c-3.1.so
# Find the corresponding process according to the file 、pid
$ hcache -pid 1070 # Get all the file information opened by the current process number
$ lsof -p 1070 # Get all the file information opened by the current process number ( A choice )
lsof Command use reference URL :https://man.linuxde.net/lsof
边栏推荐
- 一文带你了解redux的工作流程——action/reducer/store
- 力扣刷题:dfs递归解决二叉树剪枝
- 【转载】UE4 面试基础知识(一)
- codeforce D2. RGB Substring (hard version) 滑动窗口
- pytorch优化器: optim.SGD && optimizer.zero_grad()
- PyGame electronic warfare simulation effect
- JSON_ Incorrect problem returned by extract
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- Xshell Plus6下载及安装使用的方法
- Anaconda download link
猜你喜欢
一文带你了解redux的工作流程——action/reducer/store
工作流引擎在vivo营销自动化中的应用实践 | 引擎篇03
Vivo official website app full model UI adaptation scheme
Crack PLSQL by deleting the registry
写一个定序器插件 sequence 字幕(一)
Hande enterprise digital PAAS platform hzero version 1.9.0 was officially released!
MySQL中的日志“binlog”的三种格式这么好玩
Server network performance tuning tool
Shell (I) (updating)
[open hand] hande enterprise PAAS platform hzero heavy open source!
随机推荐
Application of workflow engine in vivo marketing automation | engine 03
MATLAB函数:filtfilt——零相位数字滤波
Base64、Blob、File 三种类型的相互转换 最详细
UE4 build terrain with grayscale map
使用OpenCV实现哈哈镜效果
Blob URL DataURL
Vivo official website app full model UI adaptation scheme
服务器buffer/cache 的产生原因和释放buffer/cache
@The difference between resource and @autowired
numpy.ascontiguousarray
Angr principle and Practice (I) -- principle
Repair version of Dynamic Video Wallpaper wechat applet source code download, supporting various types of traffic main revenue
MySQL中的日志“binlog”的三种格式这么好玩
线程和进程
论文阅读【6】Autoaugment: Learning augmentation strategies from data
NVIDIA hardware architecture
Ffmpeg-rk3399 ffplay learning analysis
一文带你了解redux的工作流程——action/reducer/store
JSON_EXTRACT返回不正确问题
Atomicinteger class is used in multithreading to ensure thread safety