linux 内存清理/释放命令

1.清理前内存使用情况 
free -m

2.开始清理  
echo 1 > /proc/sys/vm/drop_caches

3.清理后内存使用情况 
free -m

4.完成!

查看内存条数命令:

dmidecode | grep -A16 "Memory Device$"

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# sync
# echo 1 > /proc/sys/vm/drop_caches
  echo 2 > /proc/sys/vm/drop_caches
  echo 3 > /proc/sys/vm/drop_caches

cache释放:
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

说明,释放前最好sync一下,防止丢数据。

因为LINUX的内核机制,一般情况下不需要特意去释放已经使用的cache。这些cache起来的内容可以增加文件以及的读写速度。
先说下free命令怎么看内存

[[email protected] proc]# free

total   used   free     shared buffers cached
Mem: 515588 295452 220136 0      2060   64040
-/+ buffers/cache: 229352 286236
Swap: 682720 112 682608

其中第一行用全局角度描述系统使用的内存状况:
total——总物理内存
used——已使用内存,一般情况这个值会比较大,因为这个值包括了cache+应用程序使用的内存
free——完全未被使用的内存
shared——应用程序共享内存
buffers——缓存,主要用于目录方面,inode值等(ls大目录可看到这个值增加)
cached——缓存,用于已打开的文件
note:
    total=used+free
    used=buffers+cached (maybe add shared also)

第二行描述应用程序的内存使用:
前个值表示-buffers/cache——应用程序使用的内存大小,used减去缓存值
后个值表示+buffers/cache——所有可供应用程序使用的内存大小,free加上缓存值
note:
   -buffers/cache=used-buffers-cached
   +buffers/cache=free+buffers+cached

第三行表示swap的使用:
used——已使用
free——未使用

手动执行sync命令(描述:sync 命令运行 sync 子例程。如果必须停止系统,则运行 sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件)

[[email protected] test]# echo 3 > /proc/sys/vm/drop_caches
[[email protected] test]# cat /proc/sys/vm/drop_caches
3

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

有关/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

linux 内存清理/释放命令

时间: 2024-07-31 12:15:30

linux 内存清理/释放命令的相关文章

linux 内存清理释放命令

linux 内存清理/释放命令 1.清理前内存使用情况 free -m 2.开始清理  echo 1 > /proc/sys/vm/drop_caches 3.清理后内存使用情况 free -m 4.完成! 查看内存条数命令: dmidecode | grep -A16 "Memory Device$" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # sync # echo 1 > /proc/s

linux memory release commands内存清理/释放命令

linux 内存清理/释放命令 You could find reference from here: http://jingyan.baidu.com/article/597a06436a687f312b5243f3.html Basically it looks like this: ---------------------------------- 清理前内存使用情况 free –m 或者 free 清理内存 echo 1 > /proc/sys/vm/drop_caches 清理后内存

free命令-linux内存cached释放

在工作中经常会遇到Linux内存很大,却被cached占了大部分的内存空间,导致linux开始启用swap的情况. 下图就是这样情况: 总内存有128G,cached占用了108G,造成系统不得不使用swap内存,而导致性能下降,速度变慢 buffer,cached的作用: cached主要负责缓存文件使用, 日志文件过大造成cached区内存增大把内存占用完 .     Free中的buffer和cache:(它们都是占用内存):     buffer : 作为buffer cache的内存,

Linux内存(手动释放cache)

项目的扩容申请了一台机器,到手之后看一下机器的指标,看到内存使用情况是这样的. 1.查看内存 free $ free -h total used free shared buffers cached Mem: 125G 89G 36G 92K 212M 74G -/+ buffers/cache: 14G 111G Swap: 7.5G 1.8G 5.6G cat /proc/meminfo  如果你想得到更加相近的信息可以使用cat /proc/meminfo,直接看硬件的统计数据. MemT

查看Linux内存状况的命令及工具

1.cat  /proc/meminfo cat  /proc/<pid>/statm  和 cat  /proc/<pid>/status  获取特定的进程的内存信息: 2.atop 命令是用于终端环境的基于ncurses的交互式的系统和进程监测工具.它展示了动态更新的系统资源摘要(CPU.内存.网络.输入\输出.内核),并用醒目的颜色把系统高负载的部分以警告信息标注出来.(sudo atop)//red hat 版本下没有该命令: 3.free 命令是一个用来获取内存使用概况的

linux内存

在Linux的世界中,从大的方面来讲,有两块内存,一块叫做内存空间,Kernel Space,另一块叫做用户空间,即User Space.它们是相互独立的,Kernel对它们的管理方式也完全不同 驱动模块和内核本身运行在Kernel Space当中 一 linux内存模型 Linux内存管理系统主要解决以下三个大的问题 1.    进程地址空间不能隔离 由于程序直接访问的是物理内存,这个时候程序所使用的内存空间不是隔离的.举个例子,就像上面说的A的地址空间是0-10M这个范围内,但是如果A中有一

手动清理linux缓存,释放内存

free -m 这个命令大家应该很熟悉 系统真正用的内存我们需要看第二行,因为有一部分缓存还没有被释放 linux内存可使用的计算方法:可用内存=free+buffers+cached 手动释放linux缓存: free -m sync (一定要在第三部之前) echo 3>/proc/sys/vm/drop_caches fee -m echo 0>/proc/sys/vm/drop_caches

linux下清理缓存,以释放内存

[[email protected] src]# free total used free shared buffers cached Mem: 1920472 1845892 74580 180 462708 338068 -/+ buffers/cache: 1045116 875356 Swap: 0 0 0 [[email protected] ~]# sync [[email protected] ~]# echo 1 > /proc/sys/vm/drop_caches [[emai

[转]手工释放linux内存——/proc/sys/vm/drop_caches

另一篇:http://www.linuxfly.org/post/320/ ? 1.清理前内存使用情况?free -m 2.开始清理??echo 1 > /proc/sys/vm/drop_caches 3.清理后内存使用情况?free -m 4.完成! 查看内存条数命令: dmidecode?|?grep?-A16?"Memory?Device$" ? ? ? ? ? +++++++++++++++++++++++++++++++++++++++++++++++++++++++