Tweak your system performance with ‘noatime’

0

Whenever I install a new Linux system, whether that’s Linux on my desktop computer or a server distribution on my Raspberry Pi, I have a list of tasks that I do every time. These are habits I developed from my time, long ago, as a Unix systems administrator: backup the files, wipe the system, reinstall from scratch, restore the files, and install any extra applications.

I also make a few tweaks to the system to improve performance. One such tweak is atime, one of the three key timestamps that Linux tracks on every file.

Understanding file timestamps

You probably already know about the “Last Modified” timestamp on files and directories. You can see this output when you run the ls -l (long) command to view files ina directory; you’ll also see the “Last Modified” timestamp in any file manager. But behind the scenes, Linux actually tracks several timestamps on files and directories:

  • mtime: When the file was last modified
  • ctime: When the file was last changed
  • atime: When the file was last accessed

You can use the stat command to view these details for any file. Here’s one example for the Apache web server configuration file on my personal web server in my home office:

$ stat /etc/httpd/conf/httpd.conf 
  File: /etc/httpd/conf/httpd.conf
  Size: 12303       Blocks: 32         IO Block: 4096   regular file
Device: 253,0   Inode: 37749479    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:httpd_config_t:s0
Access: 2024-03-31 00:00:01.198883654 -0500
Modify: 2023-12-31 18:12:27.216328620 -0600
Change: 2023-12-31 18:12:27.225328576 -0600
 Birth: 2023-12-31 18:12:27.215328625 -0600

This file was created on December 31, 2023. That’s when I installed Linux on this Raspberry Pi. I haven’t needed to modify the httpd.conf file since then, so the file has remained unchanged since then. But I recently viewed it, to look for a particular setting on the web server; by looking in the file using cat, Linux updated the “Access Time” or atime timestamp.

If I copy the httpd.conf file to a backup file, all of the timestamps change, indicating that this is a new file:

$ cp /etc/httpd/conf/httpd.conf /tmp/httpd.bak
$ stat /tmp/httpd.bak 
  File: /tmp/httpd.bak
  Size: 12303       Blocks: 32         IO Block: 4096   regular file
Device: 0,37    Inode: 253         Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   jhall)   Gid: ( 1000/   jhall)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2024-04-05 12:13:04.247401082 -0500
Modify: 2024-04-05 12:13:04.249401072 -0500
Change: 2024-04-05 12:13:04.249401072 -0500
 Birth: 2024-04-05 12:13:04.247401082 -0500

But if I rename the file, Linux doesn’t update atime or mtime because I didn’t access the file’s contents (atime) or otherwise modify the text (mtime):

$ mv /tmp/httpd.bak /tmp/httpd.tmp
$ stat /tmp/httpd.tmp
  File: /tmp/httpd.tmp
  Size: 12303       Blocks: 32         IO Block: 4096   regular file
Device: 0,37    Inode: 253         Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   jhall)   Gid: ( 1000/   jhall)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2024-04-05 12:13:04.247401082 -0500
Modify: 2024-04-05 12:13:04.249401072 -0500
Change: 2024-04-05 12:14:24.902015034 -0500
 Birth: 2024-04-05 12:13:04.247401082 -0500

Notice that the “Last Changed” time (ctime) has been updated, because I changed the file’s name.

Why ‘atime’?

The “Last Accessed” (atime) is useful for certain legacy programs. For example, biff is an old mail notification program that alerts you when you have a new email message waiting for your attention. You don’t see many people using biff in modern times, but in the days when mailboxes were local to the workstation you were using, biff was quite common.

biff compared the “Last Modified” time (when the Inbox was last updated with a new email message) and the “Last Accessed” time (the last time you read your email). If mtime was more recent than atime, then biff knew that an email had arrived since you last looked at your Inbox, and let you know. The Mutt email client does something similar to alert you to new email messages.

The “Last Accessed” time is also useful if you need to do filesystem maintenance or performance tweaking. On large Linux systems, administrators may need to know what’s being accessed more frequently so they can tune performance appropriately. This might involve moving less-frequently used files to slower, high-density storage and more-frequently used files to faster disks.

But desktop systems and other “personal use” computers don’t need the “Last Accessed” time, so there’s been some argument to not use it at all. For example, Linux kernel developer Ingo Molnar commented about atime and filesystem performance:

It’s kind of weird that every Linux desktop and server is hurt by a noticeable IO performance slowdown due to the constant atime updates, while there’s just two real users of it: tmpwatch [which can be configured to use ctime so it’s not a big issue] and some backup tools. (Ok, and mail-notify too i guess.) Out of tens of thousands of applications.

But some people use a few programs that rely on atime so Linux keeps updating the atime feature.

Tweaking performance with ‘noatime’

If you want to get a boost in desktop performance, you can disable atime on your system. You can also use this method on servers, but be careful that you do not run software that relies on the “Last Accessed” time. In my experience, modern desktop environments don’t use atime so I disable it on the Linux systems I use.

To disable atime, add the noatime filesystem option when your system mounts the storage for your computer. I usually add mine after the defaults entry in /etc/fstab:

UUID=93402b76-22d5-4533-ad1e-b8b94ccb24c0 /                       btrfs   subvol=root,compress=zstd:1,x-systemd.device-timeout=0,noatime 0 0
UUID=aa7dd33b-bd3c-4b12-a2e1-6cb0bf28a2e6 /boot                   ext4    defaults,noatime        1 2
UUID=C594-12B1          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=93402b76-22d5-4533-ad1e-b8b94ccb24c0 /home                   btrfs   subvol=home,compress=zstd:1,x-systemd.device-timeout=0,noatime 0 0

This feature takes effect the next time you reboot. Whenever I reinstall my desktop system at home with a new version of Linux, the first thing I do after installing is add noatime, then reboot before I apply any system updates. Running the first system update after installing a fresh Linux will update many packages and files. Using noatime usually gives a slight but noticeable performance improvement on my computer

However, if you use very fast storage such as a high-performance SSD or NVME for your root and home filesystems, you may not notice as much of an improvement.