当前位置:网站首页>linux下清理系统缓存并释放内存
linux下清理系统缓存并释放内存
2022-07-02 09:46:00 【入门小站】
当linux频繁读取文件后,物理内存会很快被用完,当程序结束后,内存不会被正常释放,而是一直caching,因此有必要手动清理系统缓存释放内存。
sync
操作系统在运行过程中,会把访问到的文件放到buffer中。为了避免断电,等故障造成数据丢失,我们需要把buffer中的缓存数据写入到磁盘
> sync;sync;sync
手动执行sync命令(描述:sync 命令运行 sync 子例程。如果必须停止系统,则运行sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件
手动释放内存的命令
> echo 3>/proc/sys/vm/drop_caches
drop_caches的值可以是0-3之间的数字,代表不同的含义:
- 0:不释放(系统默认值)
- 1:释放页缓存
- 2:释放dentries和inodes
查看内存
> free -h
total——总物理内存
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简明教程
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dZ6RN2GC-1656667753466)(https://rumenz.com/static/cimg/wx_rumenz.png)]
边栏推荐
- [opencv learning] [contour detection]
- Fundamentals of face recognition (facenet)
- net share
- 3 a VTT terminal regulator ncp51200mntxg data
- Linear DP acwing 898 Number triangle
- Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
- Async/await asynchronous function
- Lucky numbers in the [leetcode daily question] matrix
- 阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
猜你喜欢
Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
spfa AcWing 852. SPFA judgement negative ring
C modifier
js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
屠榜多目标跟踪!BoT-SORT:稳健的关联多行人跟踪
Unity skframework framework (XIV), extension extension function
[error record] cannot open "XXX" because Apple cannot check whether it contains malware
随机推荐
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
[opencv learning] [moving object detection]
Async/await asynchronous function
Linear DP acwing 897 Longest common subsequence
Obtain file copyright information
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
日本赌国运:Web3.0 ,反正也不是第一次失败了!
Unity SKFramework框架(二十一)、Texture Filter 贴图资源筛选工具
Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
无向图的桥
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
国内首款、完全自主、基于云架构的三维CAD平台——CrownCAD(皇冠CAD)
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
net share
正确遍历EntryList方法
Heap acwing 839 Simulated reactor
Traverse entrylist method correctly
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)