NEP 4.3.0
NetCDF Expansion Pack
Loading...
Searching...
No Matches
perf_disk.h File Reference

Helpers that make example benchmarks measure disk-bound I/O. More...

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

Go to the source code of this file.

Functions

static int nep_perf_sync_file (const char *path)
 Flush a closed file's data to the storage device.
static int nep_perf_drop_cache (const char *path)
 Drop a file's pages from the page cache.

Detailed Description

Helpers that make example benchmarks measure disk-bound I/O.

NetCDF/HDF5 writes return once the data is in the operating system's page cache, and a file read right after it was written is served from that cache. To time I/O against the storage device, a benchmark calls nep_perf_sync_file() after nc_close() inside the write timer, and nep_perf_drop_cache() before starting the read timer. Neither function needs root privileges.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Function Documentation

◆ nep_perf_drop_cache()

int nep_perf_drop_cache ( const char * path)
inlinestatic

Drop a file's pages from the page cache.

Opens path read-only, calls fsync() so no dirty pages remain, then posix_fadvise(POSIX_FADV_DONTNEED) on the whole file, so the next read comes from the storage device.

Parameters
pathPath of the file to drop from the cache.
Returns
0 on success, or -1 with errno set (to the posix_fadvise() return value if that call fails).

◆ nep_perf_sync_file()

int nep_perf_sync_file ( const char * path)
inlinestatic

Flush a closed file's data to the storage device.

Opens path read-only, calls fsync() on it and closes it.

Parameters
pathPath of the file to flush.
Returns
0 on success, or -1 with errno set.