1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

disk_benchmark: Add a -c flag to enable use of disk caches

By default, disk_benchmark will now use the O_DIRECT flag, causing it
to bypass the kernel's disk caches. This gives you "disk performance"
numbers rather than "disk cache performance" numbers.

You can use "disk_benchmark -c" to enable the caches.

Fixes #703.
This commit is contained in:
Andreas Kling 2019-11-05 19:37:23 +01:00
parent 59ed235c85
commit 173ae370db

View file

@ -36,7 +36,7 @@ void exit_with_usage(int rc)
exit(rc); exit(rc);
} }
Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer); Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache);
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -44,13 +44,17 @@ int main(int argc, char** argv)
int time_per_benchmark = 10; int time_per_benchmark = 10;
Vector<int> file_sizes; Vector<int> file_sizes;
Vector<int> block_sizes; Vector<int> block_sizes;
bool allow_cache = false;
int opt; int opt;
while ((opt = getopt(argc, argv, "hd:t:f:b:")) != -1) { while ((opt = getopt(argc, argv, "chd:t:f:b:")) != -1) {
switch (opt) { switch (opt) {
case 'h': case 'h':
exit_with_usage(0); exit_with_usage(0);
break; break;
case 'c':
allow_cache = true;
break;
case 'd': case 'd':
directory = strdup(optarg); directory = strdup(optarg);
break; break;
@ -94,7 +98,7 @@ int main(int argc, char** argv)
while (timer.elapsed() < time_per_benchmark * 1000) { while (timer.elapsed() < time_per_benchmark * 1000) {
printf("."); printf(".");
fflush(stdout); fflush(stdout);
results.append(benchmark(filename, file_size, block_size, buffer)); results.append(benchmark(filename, file_size, block_size, buffer, allow_cache));
usleep(100); usleep(100);
} }
auto average = average_result(results); auto average = average_result(results);
@ -110,9 +114,13 @@ int main(int argc, char** argv)
} }
} }
Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer) Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache)
{ {
int fd = open(filename.characters(), O_CREAT | O_TRUNC | O_WRONLY); int flags = O_CREAT | O_TRUNC | O_WRONLY;
if (!allow_cache)
flags |= O_DIRECT;
int fd = open(filename.characters(), flags);
if (fd == -1) { if (fd == -1) {
perror("open"); perror("open");
exit(1); exit(1);