Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


rsv_start

grp_goal rsv_end

group_first_block

100 120 140 160 200

reservation
window

curr

Figure 9-15: Check if a desired allocation can be fulfilled with a given
reservation window.

If the file is equipped with a reservation window and a goal block is specified (as checked by the condition
grp_goal > 0), the kernel has to check if the desired allocation will fit into the existing reservation. Starting
from the desired allocation goal that specifies a block numberrelativeto the beginning of the group, the
code computes the number of blocks until the end of the block group. The calculation is illustrated in
Figure 9-15. If the desired allocation as given bycountis larger than the possible region, the reservation
window is increased withtry_to_extend_reservation. The function simply queries the pre-allocation
data structures to see if no other reservation window prevents the current window to grow, and does so
if possible.

Finally, the kernel can pass the allocation request together with the (possibly modified) reservation win-
dow toext2_try_to_allocate. While the function guarantees that a consecutive number of blocks is
allocated if some free space can be found, it cannot guarantee that the desired number of blocks is avail-
able. This has some implications on the returned values. While the first allocated block is returned as the
direct function result, the number of allocated blocks must be passed upward via the pointernum.

If some space could be allocated,retis larger than or equal to zero. The kernel then needs to update the
allocation hit counterrsv_alloc_hitand return the number of allocated blocks via thecountpointer.
If the allocation has failed, the loop needs to start again. Sinceretis negative in this case, the kernel
allocates a new reservation window in the next run as guaranteed by the conditionret<0in the initial
ifconditional. Otherwise, everything runs again as described.

Finally,ext2_try_to_allocateis responsible for the low-level allocation that directly interacts with the
block bitmaps. Recall that the function can work with a reservation window or not. The kernel now needs
to search through the block bitmap, and thus an interval for the search needs to be determined. Note that
the boundaries are specifiedrelative to the current block group. This means that numbering starts from zero.
A number of scenarios is distinguished, and Figure 9-16 illustrates various cases.

search region

block group

goal block

(no reservation
window & goal block)

reservation
window

Figure 9-16: Search interval selection for block allocation in
ext2_try_to_allocate.
Free download pdf