Created
November 22, 2015 10:50
-
-
Save craig-m/e1ccd687a81b3f9a8c30 to your computer and use it in GitHub Desktop.
Drop cached memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Writing to this will cause the kernel to | |
# free pagecache, dentries and inodes. | |
# This causes that memory to become free. | |
# | |
# non-destructive & safe for production: | |
# ref: https://www.kernel.org/doc/Documentation/sysctl/vm.txt | |
freebefore=`free -k | awk '/^Mem:/{print $4}'` | |
# need to sync first | |
sync | |
echo 3 > /proc/sys/vm/drop_caches | |
freeafter=`free -k | awk '/^Mem:/{print $4}'` | |
freekb=`expr $freeafter - $freebefore` | |
let freemb=($freekb/1024) | |
echo "freed $freekb kilobytes ($freemb MB)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment