Linux释放cache内存

简介:

Linux释放cache内存

/proc是个虚拟文档系统,我们能够通过对他的读写操作做为和kernel实体间进行通信的一种手段。也就是说能够通过修改/proc中的文档,来对当前kernel的行为做出调整。

那么我们能够通过调整/proc/sys/vm/drop_caches来释放内存。操作如下:

1、查看 /proc/sys/vm/drop_caches的值,默认为0:

 
 
  1. [root@server test]# cat /proc/sys/vm/drop_caches
  2. 0

2、手动执行sync命令:

 
 
  1. [root@server test]# sync

sync 命令运行 sync 子例程。假如必须停止系统,则运行 sync 命令以确保文档系统的完整性。sync 命令将任何未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文档。

3、将/proc/sys/vm/drop_caches值设为3

 
 
  1. [root@server test]# echo 3 > /proc/sys/vm/drop_caches
  2. [root@server test]# cat /proc/sys/vm/drop_caches
  3. 3

4、再来运行free命令:

 
 
  1. [root@server test]# free -m
  2. total used free shared buffers cached
  3. Mem: 249 66 182 0 0 11
  4. -/+ buffers/cache: 55 194
  5. Swap: 511 0 511

发现现在的used为66MB,free为182MB,buffers为0MB,cached为11MB。有效的释放了buffer和cache。

 

有关/proc/sys/vm/drop_caches的用法在下面进行了说明:

/proc/sys/vm/drop_caches (since Linux 2.6.16)
Writing to this file causes the kernel to drop clean caches,
dentries and inodes from memory, causing that memory to become
free.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to
free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 >
/proc/sys/vm/drop_caches.
Because this is a non-destructive operation and dirty objects
are not freeable, the user should run sync(8) first.


原文发布时间:2014-09-11

本文来自云栖合作伙伴“linux中国”
目录
相关文章
|
27天前
|
存储 Linux 编译器
Linux C/C++ 编程 内存管理之道:探寻编程世界中的思维乐趣
Linux C/C++ 编程 内存管理之道:探寻编程世界中的思维乐趣
50 0
|
Linux
【Linux】—— 共享内存
【Linux】—— 共享内存
|
20天前
|
存储 算法 Linux
【Linux 应用开发 共享内存】深入理解和实践 ftruncate:共享内存的有效管理
【Linux 应用开发 共享内存】深入理解和实践 ftruncate:共享内存的有效管理
52 5
|
25天前
|
Shell Linux C语言
【Shell 命令集合 磁盘维护 】Linux 创建一个初始化内存盘 mkinitrd命令使用教程
【Shell 命令集合 磁盘维护 】Linux 创建一个初始化内存盘 mkinitrd命令使用教程
32 0
|
8天前
|
Prometheus 监控 Cloud Native
【Linux】查看系统内存命令(详细讲解)
【Linux】查看系统内存命令(详细讲解)
|
12天前
|
存储 缓存 监控
深入解析linux内存指标:快速定位系统内存问题的有效技巧与实用方法(free、top、ps、vmstat、cachestat、cachetop、sar、swap、动态内存、cgroops、oom)
深入解析linux内存指标:快速定位系统内存问题的有效技巧与实用方法(free、top、ps、vmstat、cachestat、cachetop、sar、swap、动态内存、cgroops、oom)
|
20天前
|
存储 缓存 监控
Linux 系统 内存通用指标以及查询方式
Linux 系统 内存通用指标以及查询方式
16 0
|
20天前
|
存储 Linux 程序员
【Linux C/C++ 堆内存分布】深入理解Linux进程的堆空间管理
【Linux C/C++ 堆内存分布】深入理解Linux进程的堆空间管理
66 0
|
20天前
|
存储 算法 Linux
深入理解Linux内存管理brk 和 sbrk 与以及使用C++ list实现内存分配器
深入理解Linux内存管理brk 和 sbrk 与以及使用C++ list实现内存分配器
31 0
|
22天前
|
缓存 Linux iOS开发
【C/C++ 集成内存调试、内存泄漏检测和性能分析的工具 Valgrind 】Linux 下 Valgrind 工具的全面使用指南
【C/C++ 集成内存调试、内存泄漏检测和性能分析的工具 Valgrind 】Linux 下 Valgrind 工具的全面使用指南
61 1