diff --git a/README.md b/README.md index c5c2dd8..750fd12 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ See [tools/sync_drop_caches.cpp](tools/sync_drop_caches.cpp) ``` * `Result sync()`: flush filesystem caches to disk -* `Result drop_caches(DropCaches_t mode)`: remove file system caches +* `Result drop_caches(DropCaches_t mode = DropCaches_t(PAGECACHE | ENTRIES))`: remove file system caches * `mode = PAGECACHE`: drop page caches * `mode = ENTRIES`: drop dentries and inodes * `mode = PAGECACHE | ENTRIES`: both diff --git a/include/perfect/drop_caches.hpp b/include/perfect/drop_caches.hpp index 84de9cd..27c9782 100644 --- a/include/perfect/drop_caches.hpp +++ b/include/perfect/drop_caches.hpp @@ -24,7 +24,7 @@ Result sync() { return Result::SUCCESS; } -Result drop_caches(const DropCaches_t mode) { +Result drop_caches(const DropCaches_t mode = DropCaches_t(PAGECACHE | ENTRIES)) { using detail::write_str; const std::string path = "/proc/sys/vm/drop_caches"; if (mode & PAGECACHE & ENTRIES) { diff --git a/tools/perfect.cpp b/tools/perfect.cpp index fa46d0d..3d224e8 100644 --- a/tools/perfect.cpp +++ b/tools/perfect.cpp @@ -15,6 +15,7 @@ #include "perfect/cpu_turbo.hpp" #include "perfect/os_perf.hpp" #include "perfect/detail/os/linux.hpp" +#include "perfect/drop_caches.hpp" // argv should be null-terminated int fork_child(char *const *argv) { @@ -72,6 +73,7 @@ int main(int argc, char **argv) { bool aslr = false; bool cpuTurbo = false; bool maxOsPerf = true; + bool dropCaches = true; std::vector program; @@ -83,6 +85,7 @@ int main(int argc, char **argv) { auto cli = (shieldGroup, + option("--no-drop-cache").set(dropCaches, false).doc("do not drop filesystem caches"), option("--no-max-perf").set(maxOsPerf, false).doc("do not max os perf"), option("--no-aslr").set(aslr, false).doc("disable ASLR"), option("--no-cpu-turbo").set(cpuTurbo, false).doc("disable CPU turbo"), @@ -167,6 +170,12 @@ int main(int argc, char **argv) { } } + // handle file system caches + if (dropCaches) { + std::cerr << "clearing file system cache\n"; + PERFECT(perfect::drop_caches()); + } + // parent should return std::cerr << "exec "; for (size_t i = 0; i < args.size() - 1; ++i) {