Hint of the day: noatime and relatime in fstab

It’s been written about everywhere, but since we keep spotting installations in the wild where people don’t know about it, it probably deserves another mention.

By default, Linux uses the atime option on a disk mount, which means it writes a timestamp (e.g. a write to the drive) every time it reads anything. So in this case, reads cause writes – and also disk seeks, because a read from a file will then trigger having to write to the directory that contains the file. This even occurs if a file is read from the file system’s page cache (reading from the machine’s memory rather than the drive).

Unless you require an audit trail of users reading files, you generally you don’t want this. Thus, you want to add the noatime option to the disk mount in /etc/fstab. If you have just the defaults in there, you just make it defaults,noatime. It’ll doesn’t necesarily require a reboot as you can use umount/mount, but that gets tricky when dealing with the root filesystem so a reboot is generally easier. Setting these options is one of the first things we do when configuring a server.

Some user applications, such as Mutt (mail reader) do use the read access time. In that case, you can use the relatime option instead, which only writes a timestamp when a file or directory is written to. This is just for completeness of this story, as it’s still sub-optimal for a database server.

If you require read details for auditing (security) of the operating system, make sure all database-related files (database directories, InnoDB log files, binary logs, etc) are on a separate mount where you can use noatime.

Using noatime also makes a lot of sense on a web server, as it does a lot of reads. Remember, the fact that most files are in the filesystem cache doesn’t make a difference. As a general guide, it makes sense to set on most server installations. Quick win.

10 Responses to “Hint of the day: noatime and relatime in fstab”

  1. “By default, Linux uses the atime option on a disk mount”

    This hasn’t been the case for a long time now (2009 to be more exact). “relatime” has been made the default for all filesystems in kernel 2.6.30:

    commit 0a1c01c9477602ee8b44548a9405b2c1d587b5a2
    Author: Matthew Garrett
    Date: Thu Mar 26 17:53:14 2009 +0000

    Make relatime default

    Change the default behaviour of the kernel to use relatime for all
    filesystems. This can be overridden with the “strictatime” mount

    Signed-off-by: Matthew Garrett
    Signed-off-by: Linus Torvalds

  2. Just a note, as of kernel 2.6.30, relatime is the default option.

    man mount shows:
    “Since Linux 2.6.30, the kernel defaults to the behavior provided by relatime (unless noatime was specified), and the strictatime option is required to obtain traditional semantics. In addition, since Linux 2.6.30, the file’s last access time is always updated if it is more than 1 day old.”

  3. Thanks for the updates, Rob & Dennis.
    Horay for Matthew Garrett eh, he does a lot of good.

    It’s still relevant because there are an awful lot of older systems about. Of course it’d be better to have them upgraded/replaced, but that’s not always possible. And thus any extra performance we can get out of the system, is worthwhile.

    For instance, a Debian 6 installation may be at kernel version 2.6.26
    A RHEL 5 installation will be around 2.6.18

  4. It’s also not such a big deal with Mutt. It only affects mbox, not maildir, and there is a workaround with $check_mbox_size (http://dev.mutt.org/trac/wiki/MuttFaq/Folder).

  5. “So in this case, reads cause writes – and also disk seeks, because a read from a file will then trigger having to write to the directory that contains the file.”
    The directory contains only file names and inode numbers. So how could writes to directory happen?

  6. You write “directory contains only file names”. This means that there are files in that directory. If any of those files are opened, read or written, that means access and it’ll cause the directory entry for that file to get updated as well (depending on the atime setting).

  7. “If any of those files are opened, read or written, that means access…” This is not true, as I know. You can refer to The Linux Programming Interface, Page 286. None of open(), read(), write() would cause the change of atime of parent directory. Furthermore, open() (without O_CREAT) and write() even won’t update the atime of the file.

  8. The atime of the specific file will be updated.

    A possible source of confusion might have arisen from the fact that the file of course exists in a directory.
    The specific directory entries of the file will be updated, not the parent directory itself.

  9. Changes are afoot in the way timestamps work with mmapped files:

  10. awesome – thanks for that additional info.

Leave a Comment