我希望目录能够快速读取,就像在 tmpfs 上读取一段时间一样。
最接近的是:
vmtouch -L -m 2G /path/to/mydir
但这不会检测新的或已删除的文件。
答案1
已实施的解决方法:https://gist.github.com/vi/77717d7076618af92344
镜像在这里:
#!/bin/bash
# vmtouchpoll: Keep some files locked in memory (including new files, dropping deleted files)
# Usage: vmtouchpoll '/path/to/some/files/*.idx'
# Works by periodically restarting vmtouch with a new set of files
# Implemented by Vitaly "_Vi" Shukela in 2015, License=MIT
F=($(eval echo $1))
vmtouch -L -m 2G "${F[@]}"&
P1=$!
P2=0
disown
trap 'kill $P1; [[ $P2 -gt 0 ]] && kill $P2' EXIT
while true; do
sleep 55;
F=($(eval echo $1))
vmtouch -q -L -m 2G "${F[@]}"&
P2=$!
disown
sleep 5;
kill $P1
P1=$P2
P2=0
done