25 Oct: When a read implies a write
When you read file of disk, you might assume the file is read and that's all you need to worry about. However any POSIX-compliant OS must also maintain the last access time (atime) of every file as part of stat(). This is along with the mtime (modification time, when the contents was last changed), and ctime (change time, when either the contents or some attribute was last changed). Per
http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html:
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
Maintaining the atime means every time we read from a file, we must then write to the inode to update it's atime metadata. Clearly this is not ideal since a high read rate shouldn't also imply high write load on a filesystem. Linux has developed a few filesystem options over the years to reduce the impact of this feature:
- noatime: completely disable access time updates
- relatime: only update the atime if the previous atime is older than the mtime or ctime, or the previous atime is over 24 hours old
- lazytime: introduced in Linux 4.0, update atime in memory but don't flush to disk until there's some other reason to do so (e.g. an actual write to the file), or when the inode is pushed out of memory (evicted from the cache) or if the previous atime is over 24 hours old (configurable with sysctl vm.dirtytime_expire_seconds, note the worst case is 2 * vm.dirtytime_expire_seconds so this is set to 12 hours by default[1])
So you can turn off atime update entirely if you want to, but its unlikely you'll get much performance gain over relatime (the default) or lazytime. Of course its worth understanding which option is in use as otherwise you might get the wrong impression of what stat is telling you.