

Patch from Nick Piggin <piggin@cyberone.com.au>

This patch accounts the number of reads a context has
outstanding... Don't anticipate unless it doesn't have
any.




 drivers/block/as-iosched.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff -puN drivers/block/as-iosched.c~as-track-queued-reads drivers/block/as-iosched.c
--- 25/drivers/block/as-iosched.c~as-track-queued-reads	2003-02-27 02:02:06.000000000 -0800
+++ 25-akpm/drivers/block/as-iosched.c	2003-02-27 02:02:06.000000000 -0800
@@ -35,6 +35,7 @@ struct ant_stats {
 	int matching_ids;
 	int broken_by_write;
 	int exitted_tasks;
+	int queued_read;
 
 	int ant_delay_hist[100];	/* milliseconds */
 
@@ -95,6 +96,7 @@ struct as_io_context {
 	atomic_t refcount;
 	pid_t pid;
 	unsigned long state;
+	unsigned long nr_reads; /* outstanding reads */
 };
 
 /* Bits in as_io_context.state */
@@ -412,6 +414,8 @@ static void as_add_request(struct as_dat
 	const int data_dir = rq_data_dir(arq->request);
 
 	arq->as_io_context = get_as_io_context();
+	if (data_dir == READ)
+		arq->as_io_context->nr_reads++;
 
 	as_add_arq_rb(ad, arq);
 
@@ -609,9 +613,11 @@ static void as_move_to_dispatch(struct a
 	ad->last_sector[data_dir] = arq->request->sector
 					+ arq->request->nr_sectors;
 
-	if (data_dir == READ)
+	if (data_dir == READ) {
+		arq->as_io_context->nr_reads--;
 		/* In case we have to anticipate after this */
 		copy_as_io_context(&ad->as_io_context, &arq->as_io_context);
+	}
 	
 	/*
 	 * take it off the sort and fifo list, move
@@ -777,7 +783,9 @@ as_close_req(struct as_data *ad, struct 
  * dispatch it ASAP, because we know that application will not be submitting
  * any new reads.
  *
- * If the task whcih has submitted the request has exitted, break anticipation.
+ * If the task which has submitted the request has exitted, break anticipation.
+ *
+ * If this task has queued some other reads, do not enter enticipation.
  */
 static int as_can_break_anticipation(struct as_data *ad, struct as_rq *arq)
 {
@@ -800,6 +808,11 @@ static int as_can_break_anticipation(str
 		ant_stats.exitted_tasks++;
 		return 1;
 	}
+
+	if (aic && aic->nr_reads > 0) {
+		ant_stats.queued_read++;
+		return 1;
+	}
 	
 	return 0;
 }

_
