Skip to content

Commit d48589b

Browse files
Mingming CaoLinus Torvalds
authored andcommitted
[PATCH] ext3_get_blocks: Adjust reservation window size for mblocks
Optimize the block reservation and the multiple block allocation: with the knowledge of the total number of blocks ahead, set or adjust the reservation window size properly (based on the number of blocks needed) before block allocation happens: if there isn't any reservation yet, make sure the reservation window equals to or greater than the number of blocks needed, before create an reservation window; if a reservation window is already exists, try to extends the window size to match the number of blocks to allocate. This could increase the possibility of completing multiple blocks allocation in a single request, as blocks are only allocated in the range of the inode's reservation window. Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent faa5697 commit d48589b

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

‎fs/ext3/balloc.c‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,31 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
10111011
goto retry;
10121012
}
10131013

1014+
static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
1015+
struct super_block *sb, int size)
1016+
{
1017+
struct ext3_reserve_window_node *next_rsv;
1018+
struct rb_node *next;
1019+
spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock;
1020+
1021+
if (!spin_trylock(rsv_lock))
1022+
return;
1023+
1024+
next = rb_next(&my_rsv->rsv_node);
1025+
1026+
if (!next)
1027+
my_rsv->rsv_end += size;
1028+
else {
1029+
next_rsv = list_entry(next, struct ext3_reserve_window_node, rsv_node);
1030+
1031+
if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size)
1032+
my_rsv->rsv_end += size;
1033+
else
1034+
my_rsv->rsv_end = next_rsv->rsv_start - 1;
1035+
}
1036+
spin_unlock(rsv_lock);
1037+
}
1038+
10141039
/*
10151040
* This is the main function used to allocate a new block and its reservation
10161041
* window.
@@ -1095,14 +1120,19 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
10951120
while (1) {
10961121
if (rsv_is_empty(&my_rsv->rsv_window) || (ret < 0) ||
10971122
!goal_in_my_reservation(&my_rsv->rsv_window, goal, group, sb)) {
1123+
if (my_rsv->rsv_goal_size < *count)
1124+
my_rsv->rsv_goal_size = *count;
10981125
ret = alloc_new_reservation(my_rsv, goal, sb,
10991126
group, bitmap_bh);
11001127
if (ret < 0)
11011128
break; /* failed */
11021129

11031130
if (!goal_in_my_reservation(&my_rsv->rsv_window, goal, group, sb))
11041131
goal = -1;
1105-
}
1132+
} else if (goal > 0 && (my_rsv->rsv_end-goal+1) < *count)
1133+
try_to_extend_reservation(my_rsv, sb,
1134+
*count-my_rsv->rsv_end + goal - 1);
1135+
11061136
if ((my_rsv->rsv_start >= group_first_block + EXT3_BLOCKS_PER_GROUP(sb))
11071137
|| (my_rsv->rsv_end < group_first_block))
11081138
BUG();

0 commit comments

Comments
 (0)