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.) Note that a large chunk of the first branch of this conditional statement is commented out. Also, there are lots of grungy details that I don't want to stand between you and understanding the overall policies; be sure to ask me for help. In particular, the procedures
le16_to_cpu
and le32_to_cpu
just return
unchanged the number they are given; you can pretend they aren't even
there. (They exist for the sake of running Linux on other processor
architectures; the goal is to always store the bytes on disk in the
same order, even though processors differ on the order they use
internally.)
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 - src | tar Cxf /tmp -'This copies the directory tree
/usr/src
to
/tmp/src
, 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/src
directory tree. A separate web page explains
how to do this.
/tmp/src
directory tree
itself. That way the filesystem should be back the way it started.
Instructor: Max Hailperin