shenwei356/drop_file_cache

Recursively evicts cached data for specified files or directories. It is designed for cold-cache benchmarks and does not require root privileges on Linux, macOS, or BSD.

0

stars

2

commits

Go

primary language

Aug 22, 2026

updated

benchmark
benchmarking
cache
file-cache
Browse cluster: Performance benchmarking and profiling tools

README

drop_file_cache

drop_file_cache recursively evicts cached data for specified files or directories. It is designed for cold-cache benchmarks and does not require root privileges on Linux, macOS, or BSD.

It is a path-scoped alternative to the following Linux command:

sync
echo 3 > /proc/sys/vm/drop_caches

It is not identical: drop_caches clears caches system-wide, while this tool only handles regular files under the supplied paths. Directory metadata, filesystem metadata, and device caches are unaffected.

Features

  • Accepts one or more files or directories and walks directories recursively.
  • Runs quietly on success; -v reports cache residency before and after.
  • Supports Linux, macOS, *BSD, and Windows.

Installation

Download the binaries on the release page.

For Go developers:

go install github.com/shenwei356/drop_file_cache@latest

Usage

drop_file_cache v0.1.1

Recursively evict regular-file page-cache data for the supplied paths.
Symbolic links to files and directories are followed.
Directory cycles are detected and skipped.

Usage: drop_file_cache [options] PATH [PATH ...]

Options:
  -allow-global
        allow a system-wide cache flush when per-file eviction is unavailable (Windows)
  -sync
        flush dirty file data before asking the OS to evict it (default true)
  -v    show per-file cache residency as SIZE/PAGES before and after eviction
  -version
        print version and exit

Home: https://github.com/shenwei356/drop_file_cache

Examples

Drop cached data for two files:

drop_file_cache -v \
    GCA_009914755.4_T2T-CHM13v2.0_genomic.fna \
    GCA_009914755.4_T2T-CHM13v2.0_genomic.fna.gz
-------------------------------------------------------------------------------
FILE                                            SIZE          BEFORE      AFTER
-------------------------------------------------------------------------------
GCA_009914755.4_T2T-CHM13v2.0_genomic.fna     1.1 GB     1.1 GB/270K      0 B/0
GCA_009914755.4_T2T...v2.0_genomic.fna.gz   932.7 MB   932.7 MB/228K      0 B/0
-------------------------------------------------------------------------------
TOTAL (2 files)                               2.0 GB     2.0 GB/498K      0 B/0
-------------------------------------------------------------------------------

Byte sizes use decimal units (B, KB, MB, GB, TB, and so on). Residency is shown as size/pages; large page counts are rounded and abbreviated with decimal suffixes such as K, M, or G.

Recursively process a directory:

drop_file_cache /path/to/dataset

Prepare each run of a benchmark:

hyperfine --prepare 'drop_file_cache /path/to/dataset' \
    './program /path/to/dataset'

Platform support

PlatformMethod and limitations
Linuxfsync + posix_fadvise(POSIX_FADV_DONTNEED). This is the primary supported mode.
macOSfsync + msync(MS_INVALIDATE) + F_NOCACHE; best-effort.
FreeBSD, NetBSD, OpenBSD, DragonFly BSDfsync + msync(MS_INVALIDATE); best-effort.
WindowsSystem-wide fallback only. Requires -allow-global and usually an elevated shell.

Linux 6.5 and later use cachestat(2) for -v; older Linux kernels and BSD use mincore(2). OpenBSD residency reporting is available on amd64 and arm64. Windows does not provide per-file residency counts.

Notes

  • Cache eviction is advisory. Pages actively mapped or immediately reused by another process may remain or become cached again.
  • Symbolic links to files and directories are followed. Directory cycles are detected and skipped.
  • Errors are reported per file, processing continues, and the final exit status is non-zero.
  • On Windows, the fallback affects the whole system rather than only the given paths.

License

MIT License

Contributors

shenwei356

2 commits

shenwei356/drop_file_cache

Recursively evicts cached data for specified files or directories. It is designed for cold-cache benchmarks and does not require root privileges on Linux, macOS, or BSD.

0

stars

2

commits

Go

primary language

Aug 22, 2026

updated

benchmark
benchmarking
cache
file-cache
Browse cluster: Performance benchmarking and profiling tools

README

drop_file_cache

drop_file_cache recursively evicts cached data for specified files or directories. It is designed for cold-cache benchmarks and does not require root privileges on Linux, macOS, or BSD.

It is a path-scoped alternative to the following Linux command:

sync
echo 3 > /proc/sys/vm/drop_caches

It is not identical: drop_caches clears caches system-wide, while this tool only handles regular files under the supplied paths. Directory metadata, filesystem metadata, and device caches are unaffected.

Features

  • Accepts one or more files or directories and walks directories recursively.
  • Runs quietly on success; -v reports cache residency before and after.
  • Supports Linux, macOS, *BSD, and Windows.

Installation

Download the binaries on the release page.

For Go developers:

go install github.com/shenwei356/drop_file_cache@latest

Usage

drop_file_cache v0.1.1

Recursively evict regular-file page-cache data for the supplied paths.
Symbolic links to files and directories are followed.
Directory cycles are detected and skipped.

Usage: drop_file_cache [options] PATH [PATH ...]

Options:
  -allow-global
        allow a system-wide cache flush when per-file eviction is unavailable (Windows)
  -sync
        flush dirty file data before asking the OS to evict it (default true)
  -v    show per-file cache residency as SIZE/PAGES before and after eviction
  -version
        print version and exit

Home: https://github.com/shenwei356/drop_file_cache

Examples

Drop cached data for two files:

drop_file_cache -v \
    GCA_009914755.4_T2T-CHM13v2.0_genomic.fna \
    GCA_009914755.4_T2T-CHM13v2.0_genomic.fna.gz
-------------------------------------------------------------------------------
FILE                                            SIZE          BEFORE      AFTER
-------------------------------------------------------------------------------
GCA_009914755.4_T2T-CHM13v2.0_genomic.fna     1.1 GB     1.1 GB/270K      0 B/0
GCA_009914755.4_T2T...v2.0_genomic.fna.gz   932.7 MB   932.7 MB/228K      0 B/0
-------------------------------------------------------------------------------
TOTAL (2 files)                               2.0 GB     2.0 GB/498K      0 B/0
-------------------------------------------------------------------------------

Byte sizes use decimal units (B, KB, MB, GB, TB, and so on). Residency is shown as size/pages; large page counts are rounded and abbreviated with decimal suffixes such as K, M, or G.

Recursively process a directory:

drop_file_cache /path/to/dataset

Prepare each run of a benchmark:

hyperfine --prepare 'drop_file_cache /path/to/dataset' \
    './program /path/to/dataset'

Platform support

PlatformMethod and limitations
Linuxfsync + posix_fadvise(POSIX_FADV_DONTNEED). This is the primary supported mode.
macOSfsync + msync(MS_INVALIDATE) + F_NOCACHE; best-effort.
FreeBSD, NetBSD, OpenBSD, DragonFly BSDfsync + msync(MS_INVALIDATE); best-effort.
WindowsSystem-wide fallback only. Requires -allow-global and usually an elevated shell.

Linux 6.5 and later use cachestat(2) for -v; older Linux kernels and BSD use mincore(2). OpenBSD residency reporting is available on amd64 and arm64. Windows does not provide per-file residency counts.

Notes

  • Cache eviction is advisory. Pages actively mapped or immediately reused by another process may remain or become cached again.
  • Symbolic links to files and directories are followed. Directory cycles are detected and skipped.
  • Errors are reported per file, processing continues, and the final exit status is non-zero.
  • On Windows, the fallback affects the whole system rather than only the given paths.

License

MIT License

Contributors

shenwei356

2 commits

Languages

Go

95.8%

Shell

3.4%