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 ...
随机推荐
- 桥接 brctl
把eth0和wlan0桥接在一起 作用:测试wlan0网卡的并发性能 两个网卡桥接后把linux主机模拟成一个“无线路由交换机” Vi br0.sh #!/bin/bash ifconfig ...
- 79.常用的返回QuerySet对象的方法使用详解: filter, exclude,annotate
返回新的QuerySet的常用方法: 1.filter: 将满足条件的数据提取出来,返回一个新的QuerySet 以下所使用的模型article,category,定义模型models.py文件中,示 ...
- 雅可比行列式【2】Jacobian行列式的意义
2.1 线性变换将面积伸缩 对于一个\(\R^2\to\R^2\)的线性变换: \[ T(x,y)= \left[ \begin{array}{c} 4x-2y\\ 2x+3y \end{array} ...
- TypeError: TF_SessionRun_wrapper: expected all values in input dict to be ndarray.
在用Embedding时出现了这个问题,具体的代码: model.add(Embedding(input_dim = vocab_size, output_dim = embedding_vector ...
- java查看简单GC日志
测试代码: public class GCtest { public static void main(String[] args) { for (int i = 0; i < 10000; i ...
- Spring(一)——IOC和DI的简单理解
Spring是一个IOC(DI)和AOP容器框架,并且是开源的. 1.IOC和DI 比较官方的说法: •IOC(Inversion of Control):其思想是反转资源获取的方向. 传统的资源查找 ...
- Unity中的事件监听
Unity3D的uGUI系统的将UI可能触发的事件分为12个类型,即EventTriggerType枚举的12个值.如下图所示: 先以PointerClick为例.这个是用于某点点击事件.其他事件都可 ...
- ZJNU 1069 - 表达式的转换——中级
栈运用的模板题,对于符号进行出入栈操作,每次与栈顶的符号进行优先级判断,得出第一行后缀表达式. 在其后的化简计算中,每次用一个特殊符号(代码中使用了'?')代替原来的计算结果引用,并开一个数组表示每次 ...
- 两个tomcat使用同一个jvm可能会出错
如果两个tomcat中的项目的某些类具有完全相同的包路径和类名的话,jvm可能会“弄混”这两个类,所以一般要求包名“必须”唯一. 当然,如果两个类中的代码和import的类完全一样,弄混了也就弄混了, ...
- python学习Day08--文件操作
[主要内容] 文件操作: 1. r 2. w 3. a 4. r+ 读写模式. 需要移动光标进行反复读写 5. w+ 6. a+ 7. b bytes 读写操作的是字节. 用在非文本上 8. seek ...