How and why the noatime option improves Linux system performance

Updating atime affects system performance. What happens there and what to do about it – read the article.

Whenever I update Linux on my home computer, I have to solve certain problems. Over the years, this has become a habit: I make backup copies of my files, erase the system, install everything from scratch, restore my files, then reinstall my favorite applications. I also change the system settings for myself. Sometimes it takes too much time. And recently, I wondered if I needed this headache.

atime – One of the three timestamps for files on Linux (more on this later). In particular, I wondered if it would still be worthwhile to disable atime on later Linux systems. Since atime is updated every time a file is accessed, I realized that it has a significant impact on system performance.
I recently upgraded to Fedora 32 and out of habit started by disabling atime. I thought: do I really need it? I decided to study this issue and that’s what I dug up.

A little bit about file timestamps

To understand, you need to take a step back and recall a few things about Linux file systems and how the kernel assigns timestamps to files and directories. You can see the date of the last change of files and directories by running the command ls -l (long) or just by looking at the information about it in the file manager. But behind the scenes, the Linux kernel tracks several timestamps for files and directories:

  1. When was the last time the file was modified (mtime)
  2. When was the last time the properties and file metadata were changed (ctime)
  3. When was the last time a file was accessed (atime)
  4. You can use the command statto view data about a file or directory. Here is the file / etc / fstab from one of my test servers:

$ stat fstab
  File: fstab
  Size: 261             Blocks: 8          IO Block: 4096   regular file
Device: b303h/45827d    Inode: 2097285     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2019-04-25 21:10:18.083325111 -0500
Modify: 2019-05-16 10:46:47.427686706 -0500
Change: 2019-05-16 10:46:47.434686674 -0500
 Birth: 2019-04-25 21:03:11.840496275 -0500

Here you can see that this file was created on April 25, 2019, when I installed the system. My file / etc / fstab was last modified on May 16, 2019, and all other attributes were changed at about the same time.

If i copy / etc / fstab to a new file, the dates change, indicating that this is a new file:

$ sudo cp fstab fstab.bak
$ stat fstab.bak
  File: fstab.bak
  Size: 261             Blocks: 8          IO Block: 4096   regular file
Device: b303h/45827d    Inode: 2105664     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_t:s0
Access: 2020-05-12 17:53:58.442659986 -0500
Modify: 2020-05-12 17:53:58.443659981 -0500
Change: 2020-05-12 17:53:58.443659981 -0500
 Birth: 2020-05-12 17:53:58.442659986 -0500

But if I just rename the file without changing its contents, Linux will only update the file modification time:

$ sudo mv fstab.bak fstab.tmp
$ stat fstab.tmp
  File: fstab.tmp
  Size: 261             Blocks: 8          IO Block: 4096   regular file
Device: b303h/45827d    Inode: 2105664     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_t:s0
Access: 2020-05-12 17:53:58.442659986 -0500
Modify: 2020-05-12 17:53:58.443659981 -0500
Change: 2020-05-12 17:54:24.576508232 -0500
 Birth: 2020-05-12 17:53:58.442659986 -0500

These timestamps are very useful for certain Unix programs. For example, biff is a program that notifies you of a new message in an email. Now few use biff, but in those days when mailboxes were local to the system, biff was quite widespread.

How does the program know if you have new mail in your inbox? biff compares the last modified time (when the inbox was updated with a new email) and the last access time (the last time you read your email). If the change occurred later than access, then biff will understand that a new letter has arrived and will notify you of this. Mutt’s email client works in much the same way.

The last access timestamp is also useful if you need to collect statistics on file system usage and tune performance. System administrators need to know which objects are being accessed in order to properly configure the file system.

But most modern programs no longer need this label, so there was a proposal not to use it. In 2007, Linus Torvalds and several other kernel developers discussed atime in the context of performance issues. Linux kernel developer Ingo Molnar made the following remark about atime and the ext3 file system:

“It’s pretty strange that every desktop and Linux server suffers from a noticeable decrease in I / O performance due to constant updates to atime, although there are only two real users: tmpwatch [который можно настроить на использование ctime, так что это не является большой проблемой] and some backup tools. “

But people still use some programs that need this label. So, removing atime will disrupt their work. Linux kernel developers should not infringe on user freedom.

Solomon’s decision

Linux distributions include many applications, and users can also download and install other programs according to their needs. This is a key advantage of an open source OS. But this makes it difficult to optimize the performance of your file system. Removing resource-intensive components can disrupt the system.

As a compromise, Linux kernel developers have introduced the new relaytime option, which aims to strike a balance between performance and compatibility:

atime is updated only if the previous access time is less than the current time for updating or changing status … Starting with Linux 2.6.30, the kernel uses this option by default (if noatime is not specified) … Also, starting with Linux 2.6 .30, the time the file was last accessed is always updated if it is more than 1 day old.

Modern Linux systems (starting with Linux 2.6.30, released in 2009) already use relaytime, which should give a really fast performance boost. This means that you do not need to configure the file. / etc / fstab, and with relaytime you can rely on the default value.

Improving system performance with noatime

But if you want to tune your system to get maximum performance, disabling atime is still possible.

The performance change may not be very noticeable on very fast modern drives (such as NVME or Fast SSD), but there is a slight increase.

If you know that you are not using software that requires atime, you can slightly improve performance by including the noatime option in the file / etc / fstab. After that, the kernel will not constantly update atime. Use the noatime option when mounting the file system:

/dev/mapper/fedora_localhost--live-root /          ext4   defaults,noatime,x-systemd.device-timeout=0 1 1
UUID=be37c451-915e-4355-95c4-654729cf662a /boot    ext4   defaults,noatime        1 2
UUID=C594-12B1                          /boot/efi  vfat   umask=0077,shortname=winnt 0 2
/dev/mapper/fedora_localhost--live-home /home      ext4   defaults,noatime,x-systemd.device-timeout=0 1 2
/dev/mapper/fedora_localhost--live-swap none       swap   defaults,x-systemd.device-timeout=0 0 0

The changes will take effect the next time you reboot.

As an advertisement

Need a server to host the site? Our company offers reliable servers with daily or one-time payment, each server is connected to an Internet channel of 500 Megabits and is free of charge protected from DDoS attacks!

Similar Posts

Leave a Reply

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