1. 频繁的文件访问会导致系统的Cache使用量大增 
  2. free -m 
  3.              total       used       free     shared    buffers     cached 
  4. Mem:          8054       5008       3045          0        364       1218 
  5. -/+ buffers/cache:       3426       4627 
  6. Swap:         4102          5       4097 
  7.  
  8. free内存减少到几十兆,系统运行缓慢 
  9. 运行sync将dirty的内容写回硬盘 
  10. $sync 
  11.  
  12. 通过修改proc系统的drop_caches清理free的cache 
  13. $echo 3 > /proc/sys/vm/drop_caches 
  14.  
  15. drop_caches的详细文档如下: 
  16. Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free
  17. To free pagecache: 
  18. * echo 1 > /proc/sys/vm/drop_caches 
  19. To free dentries and inodes: 
  20. * echo 2 > /proc/sys/vm/drop_caches 
  21. To free pagecache, dentries and inodes: 
  22. * echo 3 > /proc/sys/vm/drop_caches 
  23. 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. 
  24. This tunable was added in 2.6.16. 
  25.  
  26. 修改/etc/sysctl.conf 添加如下选项后就不会内存持续增加 
  27. vm.dirty_ratio = 1 
  28. vm.dirty_background_ratio=1 
  29. vm.dirty_writeback_centisecs=2 
  30. vm.dirty_expire_centisecs=3 
  31. vm.drop_caches=3 
  32. vm.swappiness =100 
  33. vm.vfs_cache_pressure=163 
  34. vm.overcommit_memory=2 
  35. vm.lowmem_reserve_ratio=32 32 8 
  36. kern.maxvnodes=3