From 8caf7b77450d906f231508836dc2d55e1c4b313e Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Thu, 6 Jan 2022 22:26:22 -0800 Subject: [PATCH] Avoid unnecessary I/O to track files' 'last access' timestamp: Unless the underlying filesystem is mounted with `noatime` then the system will keep track of and update a file's 'last access' time stamp with every `read` operation. Even if the filesystem optimizes this, it makes little sense to track this information for NuDB files that can be accessed tens of thousands of times per second. If the `O_NOATIME` option is defined, we set it when attempting to open or create files. --- include/nudb/impl/posix_file.ipp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/nudb/impl/posix_file.ipp b/include/nudb/impl/posix_file.ipp index cb33b82..b840a84 100644 --- a/include/nudb/impl/posix_file.ipp +++ b/include/nudb/impl/posix_file.ipp @@ -240,6 +240,13 @@ flags(file_mode mode) #endif break; } + +#ifdef O_NOATIME + // Avoid updating the file's "last access time" with every + // read, if that's an option. + result.first |= O_NOATIME; +#endif + return result; }