In general, it will improve performance if inodes that are commonly accessed in close succession are located near one another on disk. Because it is common to access multiple files in the same directory one after another, and in close proximity to accessing the directory itself, the ext2 filesystem normally tries to place inodes nearby to the parent directory's inode. In particular, it tries to place the new inode in the same block group as the parent directory's inode.
However, of this policy were always followed, even for (sub)directory inodes, it would try to bunch all the inodes in the whole filesystem in a single block group, which clearly isn't possible if the whole disk (consisting of multiple block groups) is going to be used. Some countervailing policy is clearly needed to spread the filesystem across the disk.
Therefore, the ext2 filesystem uses a different policy for placing a new inode if the new inode is for a (sub)directory. This alternative policy puts considerably greater emphasis on even spreading across the disk than on locality.
These policies are implemented in the ext2_new_inode
procedure in the file /usr/src/linux/fs/ext2/ialloc.c
.
In particular, there is a conditional statement near the top of the
procedure controlled by
if (S_ISDIR(mode)) {The two branches of this conditional statement provide the two policies. You should read this part of the procedure to understand the two policies. (The rest of the procedure concerns other mechanical details that aren't relevant to this lab.)
There is almost zero programming to do in this lab and the basic experimental procedure is relatively simple and is spelled out for you (though you are invited to expand on it), so the key is going to be for your group to write a good lab report that reports what you observed and provides some interpretation of those observations.
time sh -c 'tar Ccf /usr - lib | tar Cxf /tmp -'This copies the directory tree
/usr/lib
to
/tmp/lib
, by using the tar
program twice:
once to pack up all the files in the original directory, and then again
to unpack them into the new directory. You should look for the
elapsed time reported by the time
command.
/tmp/lib
directory tree. A separate web page explains
how to do this.
/tmp/lib
directory tree
itself. That way the filesystem should be back the way it started.
Instructor: Max Hailperin