当前位置:网站首页>linux下清理系统缓存并释放内存
linux下清理系统缓存并释放内存
2022-07-01 21:41:00 【华为云】
当linux频繁读取文件后,物理内存会很快被用完,当程序结束后,内存不会被正常释放,而是一直caching,因此有必要手动清理系统缓存释放内存。
sync
操作系统在运行过程中,会把访问到的文件放到buffer中。为了避免断电,等故障造成数据丢失,我们需要把buffer中的缓存数据写入到磁盘
> sync;sync;sync手动执行sync命令(描述:sync 命令运行 sync 子例程。如果必须停止系统,则运行sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件
手动释放内存的命令
> echo 3>/proc/sys/vm/drop_cachesdrop_caches的值可以是0-3之间的数字,代表不同的含义:
- 0:不释放(系统默认值)
- 1:释放页缓存
- 2:释放dentries和inodes
查看内存
> free -htotal——总物理内存used——已使用内存,一般情况这个值会比较大,因为这个值包括了cache+应用程序使用的内存free——完全未被使用的内存shared——应用程序共享内存buffers——缓存,主要用于目录方面,inode值等(ls大目录可看到这个值增加)cached——缓存,用于已打开的文件恢复默认设置
缓存可以提升系统的运行效率,如果发现系统内存经常不够用,应该考虑添加内存,而不是经常清理
> echo 0>/proc/sys/vm/drop_caches原文链接:https://rumenz.com/rumenbiji/linux_drop_caches.html
微信公众号:入门小站
- 回复【1001】获取 linux常用命令速查手册
- 回复【10010】获取 阿里云ECS运维Linux系统诊断
- 回复【10012】获取 Linux学习笔记【强悍总结值得一看】
- 回复【10013】获取 shell简明教程

边栏推荐
- GCC编译
- Using closures to switch toggle by clicking a button
- Kuberntes云原生实战一 高可用部署架构
- 能升职加薪?PMP证书含金量浅析
- Accelera Systems Initiative是一个独立的非营利组织
- 同花顺股票开户选哪个券商好手机开户是安全么?
- 4. 对象映射 - Mapping.Mapstercover
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
- 从20s优化到500ms,我用了这三招
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
猜你喜欢

人才近悦远来,望城区夯实“强省会”智力底座

Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue

Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan

K-means based user portrait clustering model
![[deep learning] use deep learning to monitor your girlfriend's wechat chat?](/img/03/ecf50eacc91c0633b0d9689cdad2c2.png)
[deep learning] use deep learning to monitor your girlfriend's wechat chat?

leetcode刷题:栈与队列06(前 K 个高频元素)

leetcode刷题:栈与队列02(用队列实现栈)

Spark面试题

杰理之、产线装配环节【篇】

AIDL基本使用
随机推荐
require与import的区别和使用
pytest合集(2)— pytest运行方式
分离字符串中的字母和数字并使得字母在前数组在后
pytest合集(2)— pytest運行方式
What is the difference between consonants and Initials? (difference between initials and consonants)
Go - exe corresponding to related dependency
One of the basic learning of function
"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
leetcode刷题:二叉树02(二叉树的中序遍历)
新版图解网络PDF即将发布
Basic operation of binary tree
Burpsuite simple packet capturing tutorial [easy to understand]
leetcode刷题:栈与队列06(前 K 个高频元素)
打出三位数的所有水仙花数「建议收藏」
ngnix基础知识
选择在同花顺上炒股开户可以吗?安全吗?
Training on the device with MIT | 256Kb memory
Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
Aidl basic use
以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌