File access time not updating in ubuntu 12.04

Instead of cat you must use touch (or something that force a write), or explicitly declaring atime in your mount option.


Ubuntu uses relatime as default. The Linux kernel, in fact, uses relatime as the default from version 2.6.30 onwards. This only updates certain values when files are accessed instead of all. This modifies the cat behavior so it won't update the access time. This is the default in Ubuntu mount options. The only way to modify the access time is touching the file (aka forcing a write) instead of a simple read.

The reason behind this is the performance. If each read requires a write as the POSIX requires, the efficiency of disks and flash based devices will be worse. This also seems counter producent in read-only filesystems.

There's a bunch of discussion about this topic in Ask Ubuntu and Super User:

  • https://askubuntu.com/q/2099/169736
  • https://superuser.com/q/464290/235569

There are 3 mount options that you generally have to be aware of when dealing with atime. You're familiar with the first 2, from mount's man page

excerpts

atime  Do not use noatime feature, then the inode access time is controlled 
       by kernel defaults. See also the description for strictatime and  
       relatime mount options.

noatime
          Do not update inode access times on this filesystem (e.g., for 
          faster access on the news spool to speed up news servers).

The other option you're likely not familiar with, and the one causing your grief is this one, which has been the default since kernel 2.6.30:

relatime
          Update  inode  access times relative to modify or change time.
          Access time is only updated if the previous access time was 
          earlier than the current modify or change time. (Similar to 
          noatime, but doesn't break mutt or other applications that need to 
          know if a file has  been  read since the last time it was 
          modified.)

          Since  Linux 2.6.30, the kernel defaults to the behavior provided 
          by this option (unless noatime was  specified), and the 
          strictatime option is required to obtain traditional semantics. In 
          addition, since Linux 2.6.30, the file's last access time is 
          always   updated   if   it   is more than 1 day old.

You can check if these options are set on a filesystem by looking under /proc/mounts.

Example

$ head -5 /proc/mounts
rootfs / rootfs rw 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=3976812k,nr_inodes=994203,mode=755 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0

The difference with relatime vs.noatime is that it will make changes, but only when the current access time is after the previous access time.

Access time is only updated if the previous access time was earlier than the current modify or change time. (Similar to noatime, but doesn't break mutt or other applications that need to know if a file has been read since the last time it was modified.)

Tags:

Linux

Files

Atime