Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@satoshi_iwashita

特定のディレクトリ配下のファイルキャッシュを削除する

More than 5 years have passed since last update.

linux-ftools がとても便利なので、表題のことを実現するスクリプトです。

clear_cache.sh

#!/bin/bash

dir="$1"

if [ -z "${dir}" ]; then
    echo "usage: sh $0 dirname"
    exit 1
elif [[ ! "${dir}" =~ (.*)/$ ]]; then
    dir=`echo "${dir}/"`
fi

tmp="/tmp/cached_files"
log="/tmp/fadvise.log"

create_cache_list()
{
    cached_files_list=`/usr/local/bin/linux-fincore \
        --pages=false \
        --summarize \
        --only-cached "${dir}"* 2> /dev/null`

    echo "${cached_files_list}" | grep "${dir}" | awk {'print $1'} > "${tmp}"
    echo "$1"
    echo "${cached_files_list}" | tail -n 1
    echo ""
}

clear_cache()
{
    while read line
    do
        /usr/local/bin/linux-fadvise "${line}" POSIX_FADV_DONTNEED >> "${log}"
    done < "${tmp}"
}

create_cache_list before
clear_cache
create_cache_list after
rm "${tmp}" "${log}"
exit 0

例えば postgresql の xlog のファイルキャッシュを削除するとして、こんな感じです。

$ sudo clear_cache.sh /var/lib/pgsql/data/pg_xlog
before
total cached size: 452,984,832

after
total cached size: 0

参考にさせていただきました。

4
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
4
Help us understand the problem. What is going on with this article?