Recently came across this cool interface in the Linux kernel. Typically, the memory might be over-provisioned on the system. Instead of wasting the memory, the kernel normally utilizes a lot of it for page cache, dentry cache and inodes. These caches speed I/O operations and improves performance. However, there are cases when large amount of memory might actually be needed by the apps. While most of the cache pages could be easily reclaimed, there is obviously some overhead involved (the pages could be dirty and might have to written back to the disk, thus incurring disk write latency). Linux has a neat kernel.. so now, while it uses its smart to utilize the memory well, it also provides a method for people to indicate that they do not want the kernel to use its smarts ;-)
To free memory, just do the following:
# echo 1 > /proc/sys/vm/drop_caches
(the above frees only page cache)
# echo 2 > /proc/sys/vm/drop_caches
(for freeing dentry caches and inodes)
# echo 3 > /proc/sys/vm/drop_caches
(for freeing all of the above)
It would be advisable to first do a 'sync' before dropping the caches, so that all the dirty pages could be acted upon.
To free memory, just do the following:
# echo 1 > /proc/sys/vm/drop_caches
(the above frees only page cache)
# echo 2 > /proc/sys/vm/drop_caches
(for freeing dentry caches and inodes)
# echo 3 > /proc/sys/vm/drop_caches
(for freeing all of the above)
It would be advisable to first do a 'sync' before dropping the caches, so that all the dirty pages could be acted upon.
No comments:
Post a Comment