
From: Mingming Cao <cmm@us.ibm.com>

If we could not allocate a block in the "goal" group, we continue the
search in the rest groups:find a new reservation window, allocate a block
from there.  Since we could not allocate a block from the goal group
anyway, skip the group where the number of free blocks is less than half of
window size, there could be a better place to make a reservation.

Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/fs/ext3/balloc.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff -puN fs/ext3/balloc.c~ext3-reservation-skip-allocation-in-a-full-group fs/ext3/balloc.c
--- 25/fs/ext3/balloc.c~ext3-reservation-skip-allocation-in-a-full-group	Mon Oct 18 16:46:13 2004
+++ 25-akpm/fs/ext3/balloc.c	Mon Oct 18 16:46:13 2004
@@ -1137,6 +1137,7 @@ int ext3_new_block(handle_t *handle, str
 	struct ext3_sb_info *sbi;
 	struct reserve_window_node *my_rsv = NULL;
 	struct reserve_window_node *rsv = &EXT3_I(inode)->i_rsv_window;
+	unsigned short windowsz = 0;
 #ifdef EXT3FS_DEBUG
 	static int goal_hits, goal_attempts;
 #endif
@@ -1166,9 +1167,9 @@ int ext3_new_block(handle_t *handle, str
 	 * command EXT3_IOC_SETRSVSZ to set the window size to 0 to turn off
 	 * reservation on that particular file)
 	 */
+	windowsz = atomic_read(&rsv->rsv_goal_size);
 	if (test_opt(sb, RESERVATION) &&
-		S_ISREG(inode->i_mode) &&
-		(atomic_read(&rsv->rsv_goal_size) > 0))
+		S_ISREG(inode->i_mode) && (windowsz > 0))
 		my_rsv = rsv;
 	if (!ext3_has_free_blocks(sbi)) {
 		*errp = -ENOSPC;
@@ -1218,7 +1219,12 @@ retry:
 			goto out;
 		}
 		free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
-		if (free_blocks <= 0)
+		/*
+		 * skip this group if the number of
+		 * free blocks is less than half of the reservation
+		 * window size.
+		 */
+		if (free_blocks <= (windowsz/2))
 			continue;
 
 		brelse(bitmap_bh);
_
