Welcome to the part 4 of “Installing Linux on USB” series. In part 3 we discussed which filesystems to use for USB hard drives and USB flash drives respectively. In this part we will discuss what are the differences between atime, noatime and relatime mount options for filesystems and how can they be used in case of USB flash drives to get better performance and extend the  life of your USB flash drive. Although we are focusing on USB devices in this series, the content that is discussed in this post is almost true for any PATA/SATA drives also if you want to get better performance.

atime, noatime and relatime are basically mount options for file system like ext2, ext3, etc. By default all the file systems in Debian are mounted with atime option implicitly.

Let’s understand the meaning of these options:

1. atime – This option causes Linux to record the last (or latest) time when a particular file was accessed.  This information is particularly helpful for sysadmins or some programs (specially mail programs) to know when a particular file was last used/accessed.

Downside of atime: However there is a big performance issue associated with using atime – too many unnecessary writes are being generated. For example, every time when is accessed (say read) a write to disk is made to update it’s last accessed time which indeed is a very expensive operation. Imagine a write for every read operation. This is true for files which are read from disk and cache. This causes a notable performance issue which often gets ignored by a novice Linux user.

Famous kernel developer Ingo Molnar said the following:

Atime updates are by far the biggest IO performance deficiency that Linux has today. Getting rid of atime updates would give us more everyday Linux performance than all the pagecache speedups of the past 10 years, _combined_.

2. noatime – This option stops recording the last file access time when the file is just read. The noatime option eliminates all the writes to the disk each time a file was just read which previously used to happen with atime. However a write is made to a disk in case if a file is being changed/written.

However some people say that this can causes some program to break:

Unfortunately, turning off atime unconditionally will occasionally break software. Some mail tools will compare modification and access times to determine whether there is unread mail or not. The tmpwatch utility and some backup tools also use atime and can misbehave if atime is not correct. For this reason, distributors tend not to make noatime the default on installed systems.

Also Debian’s popularity contest program (popcon) make use of last access time. So it might report bad data to Debian servers.

By turning this option on (= turning off atime), you can see a significant increase in performance of your Linux system. Linus Torvalds, creator of Linux kernel, said the following:

But yeah, “noatime,data=writeback” will quite likely be *quite* noticeable (with different effects for different loads), but almost nobody actually runs that way.

3. relatime – A filesystem mount with this option causes the access time to be updated if they are (before the update has occurred) earlier than the modification time. This significantly cuts down the writes caused by atime updates. However not many people use this option because they are simply not aware of it. Linus Torvalds noted the following:

The “relatime” thing that David mentioned might well be very useful, but it’s probably even less used than “noatime” is. And sadly, I don’t really see that changing (unless we were to actually change the defaults inside the kernel).

There was a patch written by Ingo Molar to make this option this the default option (for ext filesystems) in the kernel itself rather than relying on userspace tool like mount. However it still hasn’t made to the mainline kernel as of 2.6.28.

To summarize, relatime is a good compromise between  atime (most expensive) and noatime (least expensive).

If you are looking for a technical discussion on atime and performance issues, please read this LKML thread.

If you are looking for a further technical discussion on relatime v/s noatime, please read this LKML thread.

How do I make my filesystem to use relatime or noatime feature?

There are many ways to do this. I will list some of them.

Method 1: Select the mount options during installation itself

In Debian Lenny:

Mount default options

Mount default options

As you can see the “defaults” are selected for your filesystem which basically means atime is enabled by default. Simply click on “defaults” line and you will get following options:

Select filesystem mount options

Select filesystem mount options

After select when you hit continue you will see something like this:

Mount options selected

Mount options selected

Now upon finishing installation when you boot your system your filesystem will use noatime and relatime attributes and should give you better performance.

Method 2: Through mount command

To use noatime give following command:

mount -o remount,noatime /

To use relatime give following command:

mount -o remount,relatime /

However these changes are not permanent and will be gone once you reboot/shutdown your system. To make these changes permanent you need to make changes to your /etc/fstab file as follow:

Method 2:: Through fstab file

Generally your fstab file will look like this if you did not select the mount options in Method 1 (during installation) above:

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/sda1       /               ext2    errors=remount-ro 0       1
/dev/sda5       none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto     0       0

The above output means atime is enabled even though it is not listed anywhere because it is the default behavior.

Now we need to add the noatime or relatime option like this:

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/sda1       /               ext2    noatime,relatime,errors=remount-ro 0       1
/dev/sda5       none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto     0       0

Note: You don’t need to give both the options (noatime and relatime) at the same time. You can either give noatime or relatime. However it seems that both the options can be given together.

Now after saving the fstab file in order to make these changes take effect you can either:

1. Reboot your system

2. Give the following command:

mount -o remount /

You can verify if the changes took effect or not by following command:

# cat /proc/mounts
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec 0 0
none /proc proc rw,nosuid,nodev,noexec 0 0
udev /dev tmpfs rw,size=10240k,mode=755 0 0
/dev/sda1 / ext2 rw,noatime,relatime,errors=remount-ro 0 0
tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0
usbfs /proc/bus/usb usbfs rw,nosuid,nodev,noexec 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,nosuid,noexec,gid=5,mode=620 0 0
#

Hopefully this post has shed enough light as to how to get more performance out of your computer of which you weren’t aware.

As usual, please leave a comment/feedback if you have any. Comments encourages bloggers to post more and keep their spirits high.

Also please don’t forget to rate this post below.

Part 5: Installing Debian Linux on USB flash memory drives

Be Sociable, Share!