Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


avefreeiandavefreebdenote the number of free inodes and blocks (which can be read from the approx-
imative per-CPU counters associated with the superblock) divided by the number of groups. The values
thus specify the average number of free inodes and blocks per group. This explains the prefixave.

max_dirsspecifies the absolute upper limit for the number of directory inodes in a block group.
min_inodesandmin_blocksdefine the minimum number of free inodes or blocks in a group before a
new directory may be created.

debtis a numeric value between 0 and 255. It is saved for each block group in theext2_sb_infofilesys-
tem instance that makes thes_debtsarray available (ext2_sb_infois defined in Section 9.2.2). The value
is incremented by 1 (inext2_new_inode) each time a new directory inode is created, and is decremented
by 1 when the inode is required for a different purpose — usually for a regular file. The value ofdebtis
therefore an indication of the ratio between the number of directories and inodes in a block group.

Starting at the block group of the parent entry, the kernel iterates over all block groups until the following
criteria are met:
❑ There are no more thanmax_ndirdirectories.
❑ No less thanmin_inodesinodes andmin_blocksdata blocks are free.
❑ Thedebtvalue does not exceedmax_debt; that is, the number of directories does not get out of
hand.

If just one of these criteria isnotsatisfied, the kernel skips the current block group and checks the next:

fs/ext2/ialloc.c
for (i = 0; i < ngroups; i++) {
group = (parent_group + i) % ngroups;
desc = ext2_get_group_desc (sb, group, NULL);
if (!desc || !desc->bg_free_inodes_count)
continue;
if (sbi->s_debts[group] >= max_debt)
continue;
if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs)
continue;
if (le16_to_cpu(desc->bg_free_inodes_count) < min_inodes)
continue;
if (le16_to_cpu(desc->bg_free_blocks_count) < min_blocks)
continue;
goto found;
}
Division without a remainder (%) at the beginning of the loop ensures that the search is resumed at the
first block group once the last block group of the partition is reached.

Once a suitable group is found (which is automatically as close as possible to the parent group unless the
inode there has been removed), the kernel need only update the corresponding statistics counters and
return the group number. If no group matches the requirements, the search is repeated with the help of
a less demanding ‘‘fallback‘‘ algorithm:

fs/ext2/ialloc.c
fallback:
for (i = 0; i < ngroups; i++) {
Free download pdf