Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


ext2_make_emptyfills the inode with the default.and..entries by generating the corresponding file
structures and writing them to the data block. Thenext2_add_linkadds the new directory to the existing
directory data of the initial inode in the format described in Section 9.2.2.

New files are created in a similar way. Thesys_opensystem call arrives atvfs_create, which again
invokes theext2_createlow-level function of the Ext2 filesystem.

Once it has allocated a new inode on the hard disk by means ofext2_new_inode, the appropriate file,
inode, and address space structures are added, this time using the variants for regular files, that is,
ext2_file_inode_operationsandext2_file_operations.

There is no difference between the address space operations for directory inodes

File and Directory Operations


Responsibility for adding the new file to the directory hierarchy is assumed byext2_add_nondir,which
immediately invokes the familiarext2_add_linkfunction.

Registering Inodes


When directories and files are created, theext2_new_inodefunction is used to find a free inode for the
new filesystem entry. However, the search strategy varies according to situation — this can be distin-
guished by themodeargument (S_IFDIRis set for directories but not for regular files).

The search itself is not performance-critical, but itis very important for filesystem performance that the
inode be optimally positioned to permit rapid access to data. For this reason, this section is devoted to an
examination of the inode distribution strategy adopted by the kernel.

The kernel applies three different strategies:


  1. Orlov allocation for directory inodes.

  2. Classic allocation for directory inodes. This is only used if theoldallocoption is passed to
    the kernel, which disables Orlov allocation. Normally, Orlov allocation is the default strat-
    egy.

  3. Inode allocation for regular files.


The three options are investigated below.

Orlov Allocation


A standard scheme proposed and implemented forthe OpenBSD kernel by Grigoriv Orlov is used to
find a directory inode. The Linux version was developed later. The goal of the allocator is to ensure that
directory inodes of child directories are in the same block group as the parent directory so that they are
physically closer to each other and costly hard disk seek operations are minimized. Of course, notall
directory inodes should end up in the same block group because they would then be too far away from
their associated data.

The scheme distinguishes whether a new directory is to be created directly in the (global) root directory or
at another point in the filesystem, as the code flow diagram forfind_group_orlovin Figure 9-20 shows.
Free download pdf