Friday, March 28, 2008

(a)Time Is On My Side

When I'm developing and debugging, It helps me to know when files were read and commands were executed.

I take debugging advice from the Rolling Stones.

Linux, like Unix, gives you this information as a file's "atime" (access time). I do ls -ulrt several times a week -- often several times a day -- to find out what files were used most recently.

Think of "-u" as the "useful" flag.

Here's an example experiment:
$ echo hello > foo
$ sleep 120; cat foo; date; ls -l foo; ls -ul foo
$ sleep 120; cat foo; date; ls -l foo; ls -ul foo
Note that ls -l says when the file was created, but ls -ul matches the output of date.

Executing a command requires the system read it, so that, too, updates the command's atime.

I find things being used in a subtree like this:
$ touch /tmp/sentinel
# do some stuff
$ find . -anewer /tmp/sentinel
When I was trying to find out which files were read by kickstart, I just ran kickstart and did an ls -ulrt on my kickstart server ... and found out that Fedora-8 has broken atime.

It's added a real-time hack, relatime (relative atime), in which the *first* ls -ul works, but later ones don't. This gives better performance on running systems, but takes away a traditional, and handy, debugging tool.


Reading documentation, Googling, and begging for help on the BLUG mailing list all failed. Finally, Kevin Fenzi cheerily gave me the solution:
$ sudo bash -c 'echo 0 > /proc/sys/fs/default_relatime'
$ sudo mount -o remount,atime /
Nice. Thanks Kevin.

How did Kevin figure it out? He read the kernel code.

No comments: