If you ever want to
empty it you can use this chain of commands.
# free && sync && echo 3 >
/proc/sys/vm/drop_caches && free
total used free
shared buffers cached
Mem:
1018916 980832 38084 0
46924 355764
-/+ buffers/cache: 578144
440772
Swap:
2064376 128 2064248
total used free
shared buffers cached
Mem:
1018916 685008 333908
0 224
108252
-/+ buffers/cache: 576532
442384
Swap:
2064376 128 2064248
You can signal the
Linux Kernel to drop various aspects of cached items by changing the numeric
argument to the above command.
·
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
The above are meant
to be run as root. If you're trying to do them using sudo then you'll need
to change the syntax slightly to something like these:
$ sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'
$ sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'
$ sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'
NOTE: There's a more esoteric version of the above command if you're into
that:
$ echo "echo 1 >
/proc/sys/vm/drop_caches" | sudo sh
Why the change in
syntax? The /bin/echo program is running as root, because
of sudo, but the shell
that's redirecting echo's output to the root-only file is still running as you.
Your current shell does the redirection before sudo starts.
Seeing what's in the buffers and
cache
Take a look at linux-ftools if you'd like to analyze the contents of the buffers & cache.
Specifically if you'd like to see what files are currently being cached.
hands-on
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 1550 81 0 89
542
-/+
buffers/cache: 918 713
Swap: 4000 0 4000
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 1550 81 0 89
542
-/+
buffers/cache: 917 714
Swap: 4000 0 4000
[root@rhel51 ~]#
echo 1 > /proc/sys/vm/drop_caches
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 1278 353 0 0 360
-/+
buffers/cache: 917 714
Swap: 4000 0 4000
[root@rhel51 ~]#
echo 2 > /proc/sys/vm/drop_caches
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 1142 489 0 1 422
-/+
buffers/cache: 718 913
Swap: 4000 0 4000
[root@rhel51 ~]#
echo 3 > /proc/sys/vm/drop_caches
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 976 655 0 0 394
-/+
buffers/cache: 580 1051
Swap: 4000 0 4000
[root@rhel51 ~]#
sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'
[root@rhel51 ~]#
sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'
[root@rhel51 ~]#
sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'
[root@rhel51 ~]#
free -m
total used free
shared buffers
cached
Mem: 1632 846 785 0 0 177
-/+
buffers/cache: 668 963
Swap: 4000 0 4000
[root@rhel51 ~]#
echo "echo 1 > /proc/sys/vm/drop_caches" | sudo sh
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 834 797 0 0 165
-/+
buffers/cache: 668 963
Swap: 4000 0 4000
[root@rhel51 ~]#
swapoff -a
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 833 798 0 0 166
-/+
buffers/cache: 666 965
Swap: 0
0 0
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 834 797 0 0 166
-/+
buffers/cache: 666 965
Swap: 0 0 0
[root@rhel51 ~]#
swapon -a
[root@rhel51 ~]#
free -m
total used free
shared buffers cached
Mem: 1632 836 795 0 0 166
-/+ buffers/cache: 668 963
Swap: 4000 0 4000
[root@rhel51 ~]#
Comments
Post a Comment