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

ext3_rsv_dw.patch: adjust the reservation window size dynamically.

Start from the deault reservation window size, if the hit ration of the
reservation window is more than 50%, we will double the reservation window
size next time up to a certain upper limit.


---

 25-akpm/fs/ext3/balloc.c          |   13 ++++++++++++-
 25-akpm/fs/ext3/ialloc.c          |    3 ++-
 25-akpm/fs/ext3/super.c           |    1 +
 25-akpm/include/linux/ext3_fs_i.h |    1 +
 4 files changed, 16 insertions(+), 2 deletions(-)

diff -puN fs/ext3/balloc.c~ext3_rsv_dw fs/ext3/balloc.c
--- 25/fs/ext3/balloc.c~ext3_rsv_dw	2004-04-13 19:35:07.956560752 -0700
+++ 25-akpm/fs/ext3/balloc.c	2004-04-13 19:35:07.965559384 -0700
@@ -151,6 +151,7 @@ static inline void rsv_window_remove(str
 {
 	rsv->rsv_start = 0;
 	rsv->rsv_end = 0;
+		rsv->rsv_alloc_hit = 0;
 	list_del(&rsv->rsv_list);
 	INIT_LIST_HEAD(&rsv->rsv_list);
 }
@@ -552,7 +553,8 @@ repeat:
 			goto fail_access;
 		goto repeat;
 	}
-
+	if (my_rsv)
+		my_rsv->rsv_alloc_hit++;
 	return goal;
 fail_access:
 	return -1;
@@ -739,6 +741,15 @@ static int alloc_new_reservation(struct 
 			start_block = my_rsv->rsv_end + 1;
 		search_head = list_entry(my_rsv->rsv_list.prev,
 				struct reserve_window, rsv_list);
+		if ((my_rsv->rsv_alloc_hit > (my_rsv->rsv_end - my_rsv->rsv_start + 1) / 2)) {
+			/*
+			 * if we previously allocation hit ration is greater than half
+			 * we double the size of reservation window next time
+			 * otherwise keep the same
+			 */
+			size = size * 2;
+			atomic_set(&my_rsv->rsv_goal_size, size);
+		}
 		rsv_window_remove(my_rsv);
 	}
 	else {
diff -puN fs/ext3/ialloc.c~ext3_rsv_dw fs/ext3/ialloc.c
--- 25/fs/ext3/ialloc.c~ext3_rsv_dw	2004-04-13 19:35:07.958560448 -0700
+++ 25-akpm/fs/ext3/ialloc.c	2004-04-13 19:35:07.966559232 -0700
@@ -582,8 +582,9 @@ got:
 	ei->i_dir_acl = 0;
 	ei->i_dtime = 0;
 	ei->i_rsv_window.rsv_start = 0;
-	ei->i_rsv_window.rsv_end= 0;
+	ei->i_rsv_window.rsv_end = 0;
 	atomic_set(&ei->i_rsv_window.rsv_goal_size, EXT3_DEFAULT_RESERVE_BLOCKS);
+	ei->i_rsv_window.rsv_alloc_hit = 0;
 	INIT_LIST_HEAD(&ei->i_rsv_window.rsv_list);
 	ei->i_block_group = group;
 
diff -puN fs/ext3/super.c~ext3_rsv_dw fs/ext3/super.c
--- 25/fs/ext3/super.c~ext3_rsv_dw	2004-04-13 19:35:07.959560296 -0700
+++ 25-akpm/fs/ext3/super.c	2004-04-13 19:35:07.967559080 -0700
@@ -1472,6 +1472,7 @@ static int ext3_fill_super (struct super
 	INIT_LIST_HEAD(&sbi->s_rsv_window_head.rsv_list);
 	sbi->s_rsv_window_head.rsv_start = 0;
 	sbi->s_rsv_window_head.rsv_end = 0;
+	sbi->s_rsv_window_head.rsv_alloc_hit = 0;
 	atomic_set(&sbi->s_rsv_window_head.rsv_goal_size, 0);
 
 	/*
diff -puN include/linux/ext3_fs_i.h~ext3_rsv_dw include/linux/ext3_fs_i.h
--- 25/include/linux/ext3_fs_i.h~ext3_rsv_dw	2004-04-13 19:35:07.960560144 -0700
+++ 25-akpm/include/linux/ext3_fs_i.h	2004-04-13 19:35:07.968558928 -0700
@@ -23,6 +23,7 @@ struct reserve_window {
 	__u32			rsv_start;
 	__u32			rsv_end;
 	atomic_t		rsv_goal_size;
+	__u32			rsv_alloc_hit;
 };
 
 /*

_