linux 清内存

 注意:首先我们需要使用sync指令,将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件。否则在释放缓存的过程中,可能会丢失未保存的文件。

的值可以为0~3之间的任意数字,代表着不同的含义:

0 – 不释放

1 – 释放页缓存

2 – 释放dentries和inodes

3 – 释放所有缓存

 

[root@ok Desktop]# cat /proc/sys/vm/drop_caches 
0
[root@ok Desktop]# file /proc/sys/vm/drop_caches 
/proc/sys/vm/drop_caches: empty
[root@ok Desktop]# echo 1 >/proc/sys/vm/drop_caches 
[root@ok Desktop]# free -h
             total       used       free     shared    buffers     cached
Mem:           11G       966M        10G        53M       392K       161M
-/+ buffers/cache:       804M        10G 
Swap:         3.6G         0B       3.6G 

 查看内存条个数:

[root@ok Desktop]# dmidecode | grep -A16 "Memory Device$"
Memory Device
	Array Handle: 0x0005
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 8192 MB
	Form Factor: SODIMM
	Set: None
	Locator: ChannelA-DIMM0
	Bank Locator: BANK 0
	Type: DDR3
	Type Detail: Synchronous
	Speed: 1600 MHz
	Manufacturer: Kingston
	Serial Number: 7633D911
	Asset Tag: None
	Part Number: KHX1600C9S3L/8G   
--
Memory Device
	Array Handle: 0x0005
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 4096 MB
	Form Factor: SODIMM
	Set: None
	Locator: ChannelB-DIMM0
	Bank Locator: BANK 2
	Type: DDR3
	Type Detail: Synchronous
	Speed: 1600 MHz
	Manufacturer: Samsung
	Serial Number: 20A9C496
	Asset Tag: None
	Part Number: M471B5173DB0-YK0  

 清除pagecache:

[root@ok ~]# sync
[root@ok ~]# sysctl -w vm.drop_caches=1
vm.drop_caches = 1
[root@ok ~]# free -h
             total       used       free     shared    buffers     cached
Mem:           11G       1.1G        10G        82M       412K       192M
-/+ buffers/cache:       980M        10G 
Swap:         3.6G         0B       3.6G 

 清空 dentries 和 inodes:

[root@ok ~]# sync
[root@ok ~]# sysctl -w vm.drop_caches=2
vm.drop_caches = 2
[root@ok ~]# free -h
             total       used       free     shared    buffers     cached
Mem:           11G       1.2G        10G        79M       5.7M       224M
-/+ buffers/cache:       959M        10G 
Swap:         3.6G         0B       3.6G 

 清空所有缓存 pagecache、dentries 和 inodes):

[root@ok ~]# sync 
[root@ok ~]# sysctl -w vm.drop_caches=3
vm.drop_caches = 3
[root@ok ~]# free -h
             total       used       free     shared    buffers     cached
Mem:           11G       1.1G        10G       101M       1.5M       210M
-/+ buffers/cache:       956M        10G 
Swap:         3.6G         0B       3.6G 

 

posted @ 2016-07-22 23:38  bass  阅读(356)  评论(0编辑  收藏  举报