{"id":1569,"date":"2021-12-25T22:29:32","date_gmt":"2021-12-25T16:59:32","guid":{"rendered":"https:\/\/smarttech101.com\/?p=1569"},"modified":"2023-03-19T16:05:24","modified_gmt":"2023-03-19T10:35:24","slug":"relatime-atime-noatime-strictatime-lazytime","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/relatime-atime-noatime-strictatime-lazytime\/","title":{"rendered":"relatime, atime, noatime, strictatime, lazytime"},"content":{"rendered":"\n
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. <\/p>\n\n\n\n
Before you begin, you should know what is the access time. The access time of a file is its last read time<\/strong>. Whenever you use any command like cat, ls, sed, or gawk<\/strong> on any file, your system updates the access time. To find the access time of a file, we can use the stat <\/strong>command.<\/p>\n\n\n\n Example:<\/p>\n\n\n\n Atime is a mount option which allows the kernel to use its default i.e. the relatime<\/strong>. <\/p>\n\n\n\n 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 <\/strong>mount option while mounting your disk. Now, access times are not updated at all. <\/p>\n\n\n\n This improves the performance but, it also breaks the applications like mutt<\/strong> (an email client) and others which need to know if the access time of a file is earlier than its current modification time. <\/p>\n\n\n\n So, to reduce the disk writes and avoid breaking such applications, you can use another mount option called relatime<\/strong>.<\/p>\n\n\n\n Relatime updates the access time only when it is earlier than the current modification time or change time of the file.<\/p>\n\n\n\n To picture it, imagine a Y-axis representing UNIX timestamp<\/a> (time since 1970). So, relatime updates atime only when the atime (access time) is below the mtime (file modification time).<\/p>\n\n\n\n And if atime is above the mtime, it is not updated at all.<\/p>\n\n\n\n Given its efficiency and compatibility with applications like mutt, it is the default mount option since linux kernel 2.6.30.<\/p>\n\n\n\n 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<\/strong> does not work, and so on. So, for the system depending heavily on the access time, there is another option – strictatime<\/strong>.<\/p>\n\n\n\n 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. <\/p>\n\n\n\n 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<\/a>\/fzf<\/strong> with previously opened files at the top. <\/p>\n\n\n\nTable of Contents<\/h2>\n\n\n\n
\n
\n
1. What is atime<\/h2>\n\n\n\n
2. What is noatime<\/h2>\n\n\n\n
3. What is relatime<\/h2>\n\n\n\n
4. What is strictatime<\/h2>\n\n\n\n