Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


❑ If a reservation window is available and the reservation starts within the block group, the abso-
lute block number needs to be converted into a relative start position. For instance, if the block
group starts at block 100 and the reservation window at block 120, the relative start block within
the group is block 20.
If the reservation window startsbeforethe block group, block number 0 is used as the starting
point.
If the reservation window goes beyond the currentblock group, the search interval is restricted
to the last block of the block group.
❑ If no reservation window is present, but a goal blockisgiven,thegoalcanbedirectlyusedasthe
start block.
If no reservation window is available and no goalblock is specified, the search starts from block


  1. In both cases, the end of the block group is used as the end block of the search.


ext2_try_to_allocatethen proceeds as follows:


fs/ext2/balloc.c
# static int
# ext2_try_to_allocate(struct super_block *sb, int group,
# struct buffer_head *bitmap_bh, ext2_grpblk_t grp_goal,
# unsigned long *count,
# struct ext2_reserve_window *my_rsv)
#{
...
ext2_grpblk_t start, end;
...
/* Determine start and end */
...
repeat:
if (grp_goal < 0) {
grp_goal = find_next_usable_block(start, bitmap_bh, end);
...
if (!my_rsv) {
int i;

for (i = 0; i < 7 && grp_goal > start &&
!ext2_test_bit(grp_goal - 1,
bitmap_bh->b_data);
i++, grp_goal--)
;
}
}
start = grp_goal;
...

If no goal block was given (grp_goal < 0), the kernel usesfind_next_usable_blockto find the first free
bit in the previously selected interval in the block allocation bitmap.


find_next_usable_blockfirst performs a bitwise search up to the next 64-bit boundary.^17 This tries to
find a free block near the allocation goal. If one is available, the function returns the bit position.


(^17) If the starting block is zero, thenfind_next_usable_blockassumes that no goal block was given and does not perform the
near-goal search. Instead, it starts immediately with the next search step.

Free download pdf