How and why the noatime option improves Linux system performance

The atime update affects system performance. What is happening there and what to do about it - read the article.

How and why the noatime option improves Linux system performance
Whenever I update Linux on my home computer, I have to perform certain tasks. It's become a habit over the years: I back up my files, wipe the system, reinstall everything from scratch, restore my files, then reinstall my favorite apps. I also change the system settings for myself. Sometimes it takes too long. And recently I wondered if I needed this headache.

time is one of the three file timestamps in Linux (more on this later). In particular, I wondered if it's still a good idea to disable atime on more recent Linux systems. Since atime is updated each time the file is accessed, I found 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 investigate this issue and here's what I dug up.

A bit about file timestamps

To understand, you need to take a step back and remember a few things about Linux file systems and how the kernel assigns timestamps to files and directories. You can see the last modified date 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 keeps track of several timestamps for files and directories:

  1. When was the file last modified (mtime)
  2. When was the file's properties and metadata last changed (ctime)
  3. When was the file last accessed (atime)
  4. You can use the command statto view information 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 changed on May 16, 2019, and all other attributes were changed around the same time.

If I copy / etc / fstab to a new file, the dates change to indicate 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 only updates 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 when there is a new message in your email. Now few people use steak, but in the days when mailboxes were local to the system, biff was fairly widespread.

How does the program know if you have new mail in your inbox? biff compares last modified time (when an incoming mail file was updated with a new email message) and last accessed time (last time you read your email). If the change happened later than the access, then biff will understand that a new letter has arrived and will inform you about it. The Mutt mail client works in much the same way.

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

But most modern programs no longer need this label, so it has been proposed not to use it. In 2007, Linus Torvalds and several other kernel developers discussed atime in the context of a performance issue. Linux kernel developer Ingo Molnar made the following remark about atime and the ext3 filesystem:

β€œIt's rather strange that every Linux desktop and server suffers a noticeable decrease in I/O performance due to constant atime updates, although there are only two real users: tmpwatch [which can be configured to use ctime, so this is not a big problem] and some backup tools.

But people still use some programs that need this label. So removing atime will break them. The developers of the Linux kernel must not infringe on the freedom of the user.

Solomonic solution

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

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

atime is only updated if the previous access time is less than the current modification or status change time... Since Linux 2.6.30, the kernel defaults to this option (unless noatime is specified)... Also, since Linux 2.6.30 .1, the file's last access time is always updated if it's more than XNUMX day old.

Modern Linux systems (since Linux 2.6.30, released in 2009) already use relaytime, which should give a really big performance boost. This means you don't need to set up a 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 the best 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 small boost there.

If you know you're not running software that requires atime, you can improve performance slightly by enabling the noatime option in the file /etc/fstab. After that, the kernel will not constantly update atime. Use the noatime option when mounting a filesystem:

/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 on the next reboot.

As advertising

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

How and why the noatime option improves Linux system performance

Source: habr.com

Add a comment