Chinaunix首页 | 论坛 | 博客
  • 博客访问: 502684
  • 博文数量: 65
  • 博客积分: 2925
  • 博客等级: 上尉
  • 技术积分: 1306
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-01 10:56
个人简介

2013

文章分类

全部博文(65)

分类: LINUX

2011-12-10 11:27:51

当在Linux下频繁存取文件后,物理内存会很快被用光 ……
出于某种考虑,想手工释放cache、swap,可以手工执行如下操作(尽量少用比较好,呵呵……)


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


虚拟内存的释放一般都是伴随着关闭应用程式来说的

可以通过命令刷新swap还原到初始状态:
swapoff -a
swapon -a


例如:
[root@wjlcn1026 vm]# free -m
             total       used       free     shared    buffers     cached
Mem:          1744        913        830          0          0        491
-/+ buffers/cache:        422       1321
Swap:         2015       1097        918

[root@wjlcn1026 vm]# swapoff -a
[root@wjlcn1026 vm]# free -m
             total       used       free     shared    buffers     cached
Mem:          1744       1109        634          0          5        694
-/+ buffers/cache:        410       1333
Swap:            0          0          0


[root@wjlcn1026 vm]# swapon -a
[root@wjlcn1026 vm]# free -m
             total       used       free     shared    buffers     cached
Mem:          1744       1116        627          0          5        694
-/+ buffers/cache:        417       1326
Swap:         2015          0       2015
阅读(8699) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~