Skip to content

Instantly share code, notes, and snippets.

@randomstatistic
Last active January 23, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomstatistic/1fb376d5454d48d62dc1 to your computer and use it in GitHub Desktop.
Save randomstatistic/1fb376d5454d48d62dc1 to your computer and use it in GitHub Desktop.
Investigate linux filesystem cache usage
#!/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}'
# 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