Skip to contentSkip to conversation

block cfq: compensate preempted queue even if it has no slice assigned

PATCH In review Shaohua Li 2 participants 3 messages Jan 11, 2011 – Jan 18, 2011 Block layer

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 2/2 block cfq: compensate preempted queue even if it has no slice assigned

If a queue is preempted before it gets slice assigned, the queue doesn't get compensation, which looks unfair. For such queue, we compensate it for a whole slice.

---
 block/cfq-iosched.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
block/cfq-iosched.c +15 -4
Index: linux/block/cfq-iosched.c
===================================================================
@@ -605,8 +605,8 @@ cfq_group_slice(struct cfq_data *cfqd, s
 	return cfq_target_latency * cfqg->weight / st->total_weight;
 }
 
-static inline void
-cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
+static inline unsigned
+cfq_scaled_group_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {
 	unsigned slice = cfq_prio_to_slice(cfqd, cfqq);
 	if (cfqd->cfq_latency) {
@@ -632,6 +632,14 @@ cfq_set_prio_slice(struct cfq_data *cfqd
 				    low_slice);
 		}
 	}
+	return slice;
+}
+
+static inline void
+cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
+{
+	unsigned slice = cfq_scaled_group_slice(cfqd, cfqq);
+
 	cfqq->slice_start = jiffies;
 	cfqq->slice_end = jiffies + slice;
 	cfqq->allocated_slice = slice;
@@ -1672,8 +1680,11 @@ __cfq_slice_expired(struct cfq_data *cfq
 	/*
 	 * store what was left of this slice, if the queue idled/timed out
 	 */
-	if (timed_out && !cfq_cfqq_slice_new(cfqq)) {
-		cfqq->slice_resid = cfqq->slice_end - jiffies;
+	if (timed_out) {
+		if (cfq_cfqq_slice_new(cfqq))
+			cfqq->slice_resid = cfq_scaled_group_slice(cfqd, cfqq);
+		else
+			cfqq->slice_resid = cfqq->slice_end - jiffies;
 		cfq_log_cfqq(cfqd, cfqq, "resid=%ld", cfqq->slice_resid);
 	}
 
#1 lore raw
Quoted 15 lines · Shaohua Li

If a queue is preempted before it gets slice assigned, the queue doesn't get compensation, which looks unfair. For such queue, we compensate it for a whole slice.

---
 block/cfq-iosched.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Index: linux/block/cfq-iosched.c
===================================================================

block/cfq-iosched.c cfq_group_slice(struct cfq_data *cfqd, s · line 610

Quoted 8 lines
block/cfq-iosched.c +2 -2
@@ -605,8 +605,8 @@ cfq_group_slice(struct cfq_data *cfqd, s
 	return cfq_target_latency * cfqg->weight / st->total_weight;
 }
 
-static inline void
-cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
+static inline unsigned
+cfq_scaled_group_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {

Shaohua,

Above name "cfq_scaled_group_slice()" does not seem appropriate. It sounds as if we are calculating scaled group slice length but the fact is we are trying to come up with slice length of cfqq. So a better name might be cfq_scaled_slice_cfqq() or cfqq_scaled_slice() something like that.

Thanks
Vivek

Quoted 32 lines
block/cfq-iosched.c +13 -2
 	unsigned slice = cfq_prio_to_slice(cfqd, cfqq);
 	if (cfqd->cfq_latency) {
@@ -632,6 +632,14 @@ cfq_set_prio_slice(struct cfq_data *cfqd
 				    low_slice);
 		}
 	}
+	return slice;
+}
+
+static inline void
+cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
+{
+	unsigned slice = cfq_scaled_group_slice(cfqd, cfqq);
+
 	cfqq->slice_start = jiffies;
 	cfqq->slice_end = jiffies + slice;
 	cfqq->allocated_slice = slice;
@@ -1672,8 +1680,11 @@ __cfq_slice_expired(struct cfq_data *cfq
 	/*
 	 * store what was left of this slice, if the queue idled/timed out
 	 */
-	if (timed_out && !cfq_cfqq_slice_new(cfqq)) {
-		cfqq->slice_resid = cfqq->slice_end - jiffies;
+	if (timed_out) {
+		if (cfq_cfqq_slice_new(cfqq))
+			cfqq->slice_resid = cfq_scaled_group_slice(cfqd, cfqq);
+		else
+			cfqq->slice_resid = cfqq->slice_end - jiffies;
 		cfq_log_cfqq(cfqd, cfqq, "resid=%ld", cfqq->slice_resid);
 	}
 
author
#2 lore raw
Quoted 27 lines · Vivek Goyal
Quoted 15 lines · Shaohua Li

If a queue is preempted before it gets slice assigned, the queue doesn't get compensation, which looks unfair. For such queue, we compensate it for a whole slice.

---
 block/cfq-iosched.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Index: linux/block/cfq-iosched.c
===================================================================

block/cfq-iosched.c cfq_group_slice(struct cfq_data *cfqd, s · line 610

Quoted 8 lines
block/cfq-iosched.c +2 -2
@@ -605,8 +605,8 @@ cfq_group_slice(struct cfq_data *cfqd, s
 	return cfq_target_latency * cfqg->weight / st->total_weight;
 }
 
-static inline void
-cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
+static inline unsigned
+cfq_scaled_group_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {

Shaohua,

Quoted 4 lines

Above name "cfq_scaled_group_slice()" does not seem appropriate. It sounds as if we are calculating scaled group slice length but the fact is we are trying to come up with slice length of cfqq. So a better name might be cfq_scaled_slice_cfqq() or cfqq_scaled_slice() something like that.

either is ok to me. can you post a patch to fix it, as the patch is already merged.

Thanks,
Shaohua