relatime, atime, noatime, strictatime, lazytime

The relatime, atime, noatime, strictatime, nodiratime, and lazytime are mount options defining how frequently access time of a file is going to be updated in a file system.

Before you begin, you should know what is the access time. The access time of a file is its last read time. Whenever you use any command like cat, ls, sed, or gawk on any file, your system updates the access time. To find the access time of a file, we can use the stat command.

Example:

Figure: Access Time getting updated.

Table of Contents

1. What is atime

Atime is a mount option which allows the kernel to use its default i.e. the relatime.

2. What is noatime

Given the definition of the access time, it needs to be updated each time a file is just accessed. This leads to huge disk writes causing the performance drop. To eliminate this drop, you can choose noatime mount option while mounting your disk. Now, access times are not updated at all.

This improves the performance but, it also breaks the applications like mutt (an email client) and others which need to know if the access time of a file is earlier than its current modification time.

So, to reduce the disk writes and avoid breaking such applications, you can use another mount option called relatime.

3. What is relatime

Relatime updates the access time only when it is earlier than the current modification time or change time of the file.

To picture it, imagine a Y-axis representing UNIX timestamp (time since 1970). So, relatime updates atime only when the atime (access time) is below the mtime (file modification time).

relatime updating only when atime < mtime
Figure: relatime updating only when atime < mtime

And if atime is above the mtime, it is not updated at all.

Given its efficiency and compatibility with applications like mutt, it is the default mount option since linux kernel 2.6.30.

At the same time, this restriction creates new drawbacks – access time becomes incorrect, and hence sorting based on that gives the wrong result, find -atime does not work, and so on. So, for the system depending heavily on the access time, there is another option – strictatime.

4. What is strictatime

It updates the access time each time a file or its cache is accessed. This increases the disk writes. Hence, personal computer users do not use this. Instead, it is mainly used by the servers.

Personally, I find it very useful in my bookmark script where bookmarks are separated by tags. These tags are nothing but a markdown file. Whenever I want to search/add a bookmark, I want the previously accessed tag at the top. Similarly, I use this in my file opener using the dmenu/fzf with previously opened files at the top.

Sorting based on the access time
Figure: Sorting based on the access time

At the same time, to reduce the number of disk writes without sacrificing the strictatime, I use strictatime with lazytime option in my fstab file /etc/fstab:

# cat /etc/fstab

UUID=d2d9da75-f104-46c8-9ff9-8193f083f2ff / ext4 rw,lazytime,strictatime 0 1

4.1. What is lazytime

This option has been introduced since Linux kernel 4.0. It is used along with one of the options described in this article. If you use it without other access time options, the kernel assumes it with its default option i.e. relatime.

Here, atime, mtime, and ctime (change time) only reside in the RAM. These times are written to the disk later when the file is synced from the memory to the disk or these times have not been written in the last 24 hours. It significantly reduces the disk writes caused by strictatime sometimes even less than that in the standalone relatime.

However, you might lose these times stored in the memory when the system crashes. But nowadays, the systems have become more stable and hence this option can be good for you.

The above are the main mount options I find useful with respect to the access time. But you might be interested in others which are briefly described below.

5. Other Mount Options for Access Times

The option nodiratime prevents updating the access time of a directory when it is accessed. It is implied automatically when you choose the option noatime.

The remaining options norelatime, diratime, nostrictatime, and nolazytime are self-explanatory.

6. Wrapping Up

That’s all. If there are some mistakes or some suggestions, please notify me using the comment section below. And also, please tell me about my writing style. Is it sufficient for you in understanding the article. Thank you in advance. For more information, you can look up the man page using either the command man 8 mount or this web version of it.

1 thought on “relatime, atime, noatime, strictatime, lazytime”

Leave a Comment

Your email address will not be published. Required fields are marked *