linux清除cache的方法
1 Linux下内存占用多的原因
当linux第一次读取一个文件运行时,一份放到一片内存中cache起来,另一份放入运行程序的内存中,正常运行,当程序运行完,关闭了,cache中的那一分却没有释放,第二次运行的时候,系统先看看在内存中是否有一地次运行时存起来的cache中的副本,如果有的话,直接从内存中读取,那样,速度就快多了。
说明这种情况的很典型的例子是启动firefox,由于firefox程序很大,因此第一次读取运行的时候很慢,尤其在速度不快的机器上,但是当你彻底关闭了firefox,ps看不到一个firefox进程,第二次再启动的时候就比第一次明显快很多,这是由于这次系统是直接从cache中读取的firefox来运行,并不是从磁盘上读取的。
再有一个例子:我们频繁使用的ls命令等基本命令,你运行的时候根本看不到硬盘灯闪,因为这些常用的命令都是再第一次运行后就保存在cache中的,以后就一直从内存中读出来运行。
如果cache占用的内存过多了,影响正常运行程序需要的内存,那么会释放掉一部分cache内存,但是总量会保持一个很高的值,所以,linux总是能最大限度的使用内存,就算加到16G,32G内存,也会随着不断的IO操作,内存的free值会慢慢减少到只有几M,想要内存不发生这种情况,只有一个办法:把内存加到比硬盘大。
2 手动释放方法
2.1 使用free查看一下当前内存使用情况(可略过):
[root@*** ~]# free -m
total used free shared buffers cached
Mem: 512 488 23 0 57 157
-/+ buffers/cache: 273 238 Swap: 1055 0 1055
2.2 执行sync同步数据
[root@*** ~]# sync
2.3 清理cache
[root@*** ~]#echo 3 > /proc/sys/vm/drop_caches
2.4 drop_cache的详细文档如下,以便查阅
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:
* echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
* echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
* echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation, and dirty objects are notfreeable, the user should run "sync" first in order to make sure allcached objects are freed.
This tunable was added in 2.6.16.
网上查了查资料,整理一下:
关于drop_caches文件:系统默认为0
在Documentation/sysctl/vm.txt中有如下描述:
drop_caches
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:仅清除页面缓存(PageCache)
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:清除目录项和inode
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:清除页面缓存,目录项和inode
echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation and dirty objects are not freeable, the user should run `sync' first.
linux清除cache的方法的更多相关文章
- linux中清除cache的方法
在进行测试文件导入的时候,发现内存占用很大,如下所示: [root@python ~]# vmstat 1 -S M 3 procs -----------memory---------- ---sw ...
- Linux 常用命令使用方法大搜刮
Linux 常用命令使用方法大搜刮 1.# 表示权限用户(如:root),$ 表示普通用户 开机提示:Login:输入用户名 password:输入口令 用户是系统注册用户成功登陆后,可以进入 ...
- Linux 释放cache化缓存
Linux 释放cache化缓存 free -g查看空余内存以及已使用内存 原文 https://blog.csdn.net/tomspcc/article/details/78131468 机械硬 ...
- 转:Linux环境变量设置方法总结 PATH、LD_LIBRARY_PATH
转: https://www.linuxidc.com/Linux/2017-03/142338.htm 文章写比较全 转载记录 Linux环境变量设置方法总结 PATH.LD_LIBRARY_P ...
- Linux Buffer/Cache 的区别
以前经常使用free -h命令来查看当前操作系统的内存使用情况,同时也注意过返回信息中有一列是buff/cache,来公司之前,面试官还问过我这两个的区别,当时没有回答出来,现在特意回顾记录下: ...
- Ubuntu Linux系统三种方法添加本地软件库
闲着没事教教大家以Ubuntu Linux系统三种方法添加本地软件库,ubuntu Linux使用本地软件包作为安装源——转2007-04-26 19:47新手重新系统的概率很高,每次重装系统后都要经 ...
- (转)Linux I/O 调度方法
Linux I/O 调度方法 转自https://blog.csdn.net/theorytree/article/details/6259104 操作系统的调度有 CPU调度 CPU sche ...
- linux dentry cache 转自:http://blog.csdn.net/denzilxu/article/details/9188003
Linux dentry cache学习 每个dentry对象都属于下列几种状态之一: (1)未使用(unused)状态:该dentry对象的引用计数d_count的值为0,但其d_inode指针仍然 ...
- [转载]linux 清除系统cached
FROM: http://cqfish.blog.51cto.com/622299/197230 linux 清除系统cached top查看系统内存使用情况 Mem: 16432180k ...
随机推荐
- c++ 排序 冒泡 插入 选择 快速
//冒泡 #include <iostream> using namespace std; void bubbleSort(int* list,int index) { ;i--) //i ...
- Windows下MariaDB数据搬家问题
背景:公司买了一台服务器要将原来老服务器数据库数据导入新的服务器上,两台服务器环境如下 做好准备后开始实施,老数据库进行停库 找到MariaDB的安装目录下的整data目录进行拷贝,然后到新服务器进行 ...
- PAT Advanced 1043 Is It a Binary Search Tree (25) [⼆叉查找树BST]
题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following proper ...
- 洛谷P1257(暴力超时)
1.先输入再求勾股定理会超时 2.需要一边输入一边求. #include<iostream> #include<cmath>#include<cstdio> usi ...
- Django2.0——中间件
Django中间件middleware本质是一个类,在请求到返回的中间,类中不同的方法会在指定的时机中被触发.setting.py的变量MIDDLEWARE_CLASSES中的每一个元素都是中间件,且 ...
- Django模型基础——(二)
上篇博客主要讲了django中对数据库的增删改查,下面深入再讲解下对数据库的操作. 常用的查询方法 下面以表名为User为例 User.object.first() :返回表中第一条数据 User.o ...
- selenium浏览器内核监测处理
一.代码 from selenium.webdriver import Chrome from selenium.webdriver import ChromeOptions option = Chr ...
- mybatis框架快速入门
通过快速入门示例,我们发现使用mybatis 是非常容易的一件事情,因为只需要编写 Dao 接口并且按照 mybatis要求编写两个配置文件,就可以实现功能.远比我们之前的jdbc方便多了.(我们使用 ...
- jquery判断字符串中是否包含特定字符的方法总结
方法一:使用indexOf() 和lastIndexOf()方法 案例: var Cts = "bblText"; if(Cts.indexOf("Text") ...
- 17.3.10--C语言运行的步骤
编译-->生成-->调试-->链接-->运行 编译就是:将你编写的C语言程序翻译成机器能识别运行的指令集 生成就是:根据编译完成的指令集制造出机器可以具体执行的指令序列 调试就 ...