4

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?

4

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.

  • thank you, relatime is indeed the culprit based on /proc/mounts. – iruvar Oct 14 '12 at 22:08
1

Metadata cache is usually different from file cache. You can get a list of cached files with the fincore utility, see: http://code.google.com/p/linux-ftools/ .

  • 1
    @wazook, thanks, +1 for the link to fincore. Working on compiling it. As to your point on metadata cache versus file cache, are you suggesting that output from the stat command in the second case represents stale information from the metadata cache? – iruvar Oct 14 '12 at 21:50
  • True, but irrelevant here. Caching doesn't influence the file's metadata. – Gilles Oct 14 '12 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.