当前位置:网站首页>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)]
边栏推荐
- 文件的下载与图片的预览
- JSON serialization and parsing
- West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
- js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
- Modular commonjs es module
- How can attribute mapping of entity classes be without it?
- Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud
- 上手报告|今天聊聊腾讯目前在用的微服务架构
- Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
- C modifier
猜你喜欢

阿里发布的Redis开发文档,涵盖了所有的redis操作
![Jerry's watch time synchronization [chapter]](/img/64/a48772b4e503ae0a2d36fc292e4e0d.jpg)
Jerry's watch time synchronization [chapter]

The redis development document released by Alibaba covers all redis operations

Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)

Unity SKFramework框架(十四)、Extension 扩展函数

Browser node event loop

传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE

Five best software architecture patterns that architects must understand

Heap acwing 838 Heap sort

Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
随机推荐
Everyone wants to eat a broken buffet. It's almost cold
PR usage skills, how to use PR to watermark?
nohup命令
Jerry's weather code table [chapter]
Some sudden program ideas (modular processing)
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
Modular commonjs es module
Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)
Js5day (event monitoring, function assignment to variables, callback function, environment object this, select all, invert selection cases, tab column cases)
百款拿来就能用的网页特效,不来看看吗?
Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
moon
Unity skframework framework (XV), singleton singleton
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
Jerry's watch reads the alarm clock [chapter]
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
SAP MM 因物料有负库存导致MMPV开账期失败问题之对策
Unity SKFramework框架(十五)、Singleton 单例
阿里发布的Redis开发文档,涵盖了所有的redis操作
挥发性有机物TVOC、VOC、VOCS气体检测+解决方案