Last active
January 23, 2018 17:13
-
-
Save randomstatistic/1fb376d5454d48d62dc1 to your computer and use it in GitHub Desktop.
Investigate linux filesystem cache usage
This file contains hidden or 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 | |
dir=$1 | |
if [ "$1" == "" ]; then | |
echo "Must provide a directory as an argument" | |
exit 1 | |
fi | |
ftypes=$(find $1 -type f -size +10c | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq) | |
for ft in $ftypes | |
do | |
echo -n "$ft " | |
./pcstat --terse `find $1 -name "*${ft}" -type f -size +10c` | awk -F"," '/^\// { s+=$2; t+=$5; c+=$6 }END{print s " " 100*c/t}' | |
done | |
echo -n "* " | |
./pcstat --terse `find $1 -type f -size +10c` | awk -F"," '/^\// { s+=$2; t+=$5; c+=$6 }END{print s " " 100*c/t}' |
This file contains hidden or 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
# Requires https://code.google.com/p/linux-ftools/ | |
# suggest that linux cache somedir in memory | |
find -L <somedir> -type f -exec linux-fadvise {} POSIX_FADV_WILLNEED \; | |
# check what percentage of somedir is cached in memory | |
linux-fincore -s $(find -L /mnt/<somedir> -type f) | awk '/^\/mnt/ { t+=$2; c+=$6 }END{print 100*c/t}' | |
# Sinc linux-ftools seems to be abandonded and not in modern ubuntu, maybe try this tool? | |
https://github.com/tobert/pcstat | |
curl -L -o pcstat https://github.com/tobert/pcstat/raw/2014-05-02-01/pcstat.x86_64 | |
chmod 755 pcstat | |
./pcstat --terse `find /mnt/<somedir> -type f -size +10c` | awk -F"," '/^\/mnt/ { t+=$5; c+=$6 }END{print 100*c/t}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment