Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


group = (parent_group + i) % ngroups;
desc = ext2_get_group_desc (sb, group, &bh);
if (!desc || !desc->bg_free_inodes_count)
continue;
if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei)
goto found;
}

...

return -1;

Again, the kernel starts at the parent group. The directories are scanned one after the other. However, this
time the kernel accepts the first group that contains more than the average number of inodes (specified
byavefreei).


This method is modified slightly when a new subdirectory is created in the root directory of the system,
as illustrated by the left-hand branch of the code flow diagram in Figure 9-20 above.


To spread the directory inodes across the filesystem as uniformly as possible, the immediate sub-
directories of the root directory are distributed statistically over the block groups. The kernel uses
get_random_bytesto select a random number that is trimmed to the maximum number of existing
block groups by dividing (without remainder) byngroups. The kernel then iterates as follows over the
randomly selected groups and subsequent groups:


fs/ext2/ialloc.c
get_random_bytes(&group, sizeof(group));
parent_group = (unsigned)group % ngroups;
for (i = 0; i < ngroups; i++) {
group = (parent_group + i) % ngroups;
desc = ext2_get_group_desc (sb, group, &bh);
if (!desc || !desc->bg_free_inodes_count)
continue;
if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir)
continue;
if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei)
continue;
if (le16_to_cpu(desc->bg_free_blocks_count) < avefreeb)
continue;
best_group = group;
best_ndir = le16_to_cpu(desc->bg_used_dirs_count);
best_desc = desc;
best_bh = bh;
}

While, again, the minimum number of free inodes or blocks must not be below the limit set byavefreei
andavefreeb, the kernel also ensures that the number of free directories is not greater than or equal
tobest_ndir. The value is initially set to the value ofinodes_per_groupbut is always updated to the
lowest value encountered by the kernel during its search. The winner is the block group that has the
fewest entries and that also satisfies the other two conditions.


If a suitable group is found, the kernel updates the statistics and returns the group number selected.
Otherwise, the fallback mechanism comes into effect to find a less qualified block group.

Free download pdf