Measuring Inode Locality for MCS-378 Lab 3, Fall 2002

We can get some idea how close an inode is to its parent directory's inode by calculating the difference in their inode numbers. The inode numbers are available from the stat system call. I've written a program, distance.c, that you can use to find this difference for any file.

To find these inode distances for all the normal files under /tmp/lib, sorted into numerical order, you could use the following command

find /tmp/lib -type f -exec ./distance '{}' ';' | sort -n >/tmp/filedists
You can find the range of distances by looking at the first and last line of the file, with the commands
head -1 /tmp/filedists
tail -1 /tmp/filedists
Note that the first argument to head and tail has a hyphen followed by the number 1, which indicates that we want to see 1 line of the file (the first 1 or the last 1). You should also be interested in the median value, which you can find by selecting out the middle line. First use
wc -l /tmp/filedists
to count the number of lines; this time the character after the hyphen is the letter l, indicating that it we want to count lines (as opposed to words or characters). Then use a combination of head piped into tail to select out the middle line. (Use head to select out the first half of the file, rather than just the first line, and then use tail to select out the last line of that first half.)

You can find the range and median of the inode distances for directories similarly, but using d rather than f for the -type option to the find command.


Instructor: Max Hailperin