Linux Disk Caching – Effects on Access Times Reported by Stat

cachefileslinuxstattime

On Ubuntu 12.04 I did the following

  1. stat a file
  2. cat the same file
  3. stat the file again
  4. cat the file again after 5 min
  5. stat the file

The access time reported at 3. reflects the point at which 2. was run.
However, the access time reported at 5. coincides with 2. and not 4.
Is this because Linux serves the file out of cache and avoids disk access in the second instance?
Also is there a way to retrieve a list of files that are currently resident in disk cache?

Best Answer

Caching is transparent. It does not affect a file's metadata. A file's access date shows when the file was read, never mind whether reading the file caused a read from the disk.

By default, Linux does not update file access times. The default mount option sine kernel 2.6.30 is relatime, which sacrifices the usefulness of file access times for a small performance gain. It seems that your filesystem is mounted with the relatime option, so the second read of the file didn't update its atime.