centos 清理内存缓存
读写文件时,Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这就是Cache Memory(缓存内存)。
即使程序运行结束后,Cache Memory也不会自动释放。这就会导致程序频繁读写文件后,可用物理内存会很少。
其实这缓存内存(Cache Memory)在你需要使用内存的时候会自动释放,所以不必担心没有内存可用。
如果你希望手动去释放Cache Memory(缓存内存)的话也是有办法的。
清理缓存(drop_caches)的官方文档:http://www.kernel.org/doc/Documentation/sysctl/vm.txt
==============================================================
drop_caches
Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.
This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...) These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.
Use of this file can cause performance problems. Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use. Because of this,
use outside of a testing or debugging environment is not recommended.
You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3
These are informational only. They do not mean that anything is wrong
with your system. To disable them, echo 4 (bit 3) into drop_caches.
==============================================================
# cat /proc/sys/vm/drop_caches
0 //默认是0;1-清空页缓存;2-清空inode和目录树缓存;3-清空所有缓存
[root@bak ~]# sync //注意:在清空缓存之前使用sync命令同步数据到磁盘
[root@bak ~]# free -m
total used free shared buffers cached
Mem: 15898 3029 12869 0 191 1064
-/+ buffers/cache: 1772 14125
Swap: 31999 0 31999
[root@bak ~]# echo 3 > /proc/sys/vm/drop_caches
[root@bak ~]# free -m //发现缓存明显减少了
total used free shared buffers cached
Mem: 15898 1770 14128 0 1 30
-/+ buffers/cache: 1738 14160
Swap: 31999 0 31999
centos 清理内存缓存的更多相关文章
- 如何在Linux上清理内存缓存、缓冲与交换空间
如何在Linux上清理内存缓存.缓冲与交换空间 与其他类型的操作系统一样,GNU/Linux已经有效的实现了内存管理,甚至更加优秀.但是如果任何进程正在吃光你的内存,并且你想清理它,Linux提供了一 ...
- Centos清理内存 内存回收释放及内存使用查看的相关命令
在清理前内存使用情况 free -m 用以下命令清理内存 echo 1 > /proc/sys/vm/drop_caches 清理后内存使用情况再用以下命令看看. free –m 多出很多内存了 ...
- linux清理内存缓存cache
Linux服务器有自己先进的内存管理机制,有时候会发现我们系统的buff/cache内存占用会越来越高,操作系统也有卡顿的情况,遇到这种情况,不妨试试下面的方法. 1步骤一:我们先查看物理内存占用情况 ...
- linux 过滤内存使用率并于计划任务结合来自动清理内存缓存
过滤出内存使用率并进行判断 #!/bin/bash echo "###cleand free_cache script########" #memory usage mem_pus ...
- [sh]清理memcached缓存
#!/bin/bash ###author xxx ###date xxx ###清理内存缓存 used=`free -m | awk 'NR==2' | awk '{print $3}'` free ...
- CentOS7清理yum缓存和释放内存方法
清理yum缓存 清理yum缓存使用yum clean 命令,yum clean 的参数有headers, packages, metadata, dbcache, plugins, expire-ca ...
- Android Glide数据更新及内存缓存、硬盘缓存清理
[转] 原文 Android Glide数据更新及内存缓存.硬盘缓存清理 Android的Glide在加载图片时候内部默 ...
- Centos下查看cpu、磁盘、内存使用情况以及如何清理内存
核查服务器基本情况 查看内存使用情况 free -m 查看cpu使用情况 top #查看进程运行情况 查看磁盘以及分区情况 df -h 查看网络情况 ifconfig 查看端口使用情况 #1.方法一 ...
- Memcache内存缓存框架
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10923221.html 一:Memcache是什么,为什么要用它 MemCache是一个高性能.“分布式”的 ...
随机推荐
- JavaWeb 学习003-简单登录页面功能实现
先说下题外话:学习不是看你学了多久,重点是学到多少: 这就要求 效率.我在这三个小时,但是有效率的又有多久?只是做了这么一点简单的事. 登录页面 跟数据库交互,进行判断是否登陆成功.我只是实现了一 ...
- android中的requestFocus标签
<requestFocus />标签用于指定屏幕中的焦点View 用法:置于Views标签内部 ex: <EditText android:id=" ...
- laravel之缓存配置文件
清除之前配置文件缓存,并生成新的配置文件缓存, get bash: php artisan config:cache 如下图,以上命令会将config文件夹下所有的文件内容缓存到bootstrap/c ...
- Java中从控制台输入数据的几种常用方法
Java中从控制台输入数据的几种常用方法 一.使用标准输入串System.in //System.in.read()一次只读入一个字节数据,而我们通常要取得一个字符串或一组数字 //System.in ...
- linux下查看cpu物理个数、核数、逻辑cpu数
一.首先要明确物理cpu个数.核数.逻辑cpu数的概念 1.物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id) 2.cpu核数:单块CP ...
- TSuperEnumerator、TSuperAvlIterator、ObjectFindFirst
通过 ISuperObject.GetEnumerator 可获取一个 TSuperEnumerator 对象. TSuperEnumerator 主要有: MoveNext 方法.Current 属 ...
- c# dotfuscator 混淆后无法使用
在实体类中忘记给字段加上 get ;set ;导致编译后程序无法使用. 下面这个(A代码)是可以正常混淆的. public class PhoneUsedStatus { ...
- Sprint3(12.18)总结
Sprint3第三阶段 1.类名:软件工程-第三阶段 2.时间:至12.18 3.选题内容:web版-餐厅到店点餐系统 4.团队博客地址: http://www.cnblogs.com/queenju ...
- jxl 处理 Excel 样式
jxl 能够操作的 excel 样式: 1. Workbook的格式设置(代表一个excel文件) 2. Sheet的格式设置(代表一个表格) 3. Cell的格式设置(代表一个单元格) PS:此jx ...
- 通过反射及注解的运用获取SQL语句
import java.lang.reflect.*; public class BeanUtil { //这是拼接查询SQL语句的方法(getDelectSQL) public static Str ...