cfq-iosched: queue groups more gracefully
PATCH 1/1 cfq-iosched: queue groups more gracefully
This patch queue awakened cfq-groups according its current vdisktime, it try to save upto one group timeslice from unused virtual disk time. Thus group does not loses everything, if it was not continuously backlogged.
--- block/cfq-iosched.c | 36 ++++++++++++++++++++++++++++++------ 1 files changed, 30 insertions(+), 6 deletions(-)
block/cfq-iosched.c +30 -6
@@ -592,6 +592,26 @@ cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg)return cfq_target_latency * cfqg->weight / st->total_weight; } +static inline u64 +cfq_group_vslice (struct cfq_data *cfqd,struct cfq_group *cfqg) +{ +struct cfq_rb_root *st = &cfqd->grp_service_tree; +u64 vslice; + +/* There no group slices in iops mode */ +if (iops_mode (cfqd)) +return 0 ; + +/* +* Equal to cfq_scale_slice(cfq_group_slice(cfqd, cfqg), cfqg). +* Add group weight beacuse it currently not in service tree. +*/ + vslice = (u64 )cfq_target_latency <<CFQ_SERVICE_SHIFT ; + vslice *=BLKIO_WEIGHT_DEFAULT ; +do_div (vslice, st->total_weight + cfqg->weight); +return vslice; +} +static inline unsigned cfq_scaled_cfqq_slice (struct cfq_data *cfqd,struct cfq_queue *cfqq) {
@@ -884,16 +904,20 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)return ;/* -* Currently put the group at the end. Later implement something -* so that groups get lesser vtime based on their weights, so that -* if group does not loose all if it was not continuously backlogged. +* Bump vdisktime to be greater or equal min_vdisktime. +*/ + cfqg->vdisktime =max_vdisktime (cfqg->vdisktime, st->min_vdisktime); + +/* +* Put the group at the end, but save one slice from unused time. */ n =rb_last (&st->rb);if (n) { __cfqg =rb_entry_cfqg (n); - cfqg->vdisktime = __cfqg->vdisktime +CFQ_IDLE_DELAY ; - }else - cfqg->vdisktime = st->min_vdisktime; + cfqg->vdisktime =max_vdisktime (cfqg->vdisktime, + __cfqg->vdisktime - +cfq_group_vslice (cfqd, cfqg)); + }cfq_group_service_tree_add (st, cfqg); }
Quoted 5 lines · Konstantin Khlebnikov
This patch queue awakened cfq-groups according its current vdisktime, it try to save upto one group timeslice from unused virtual disk time. Thus group does not loses everything, if it was not continuously backlogged.
Signed-off-by Konstantin Khlebnikov <[email protected]>
I think this patch is not required till we start preemption across groups? Any more details of actual use will help.
Quoted 19 lines
--- block/cfq-iosched.c | 36 ++++++++++++++++++++++++++++++------ 1 files changed, 30 insertions(+), 6 deletions(-)block/cfq-iosched.c +7
-0@@ -592,6 +592,26 @@ cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg)return cfq_target_latency * cfqg->weight / st->total_weight; } +static inline u64 +cfq_group_vslice (struct cfq_data *cfqd,struct cfq_group *cfqg) +{ +struct cfq_rb_root *st = &cfqd->grp_service_tree; +u64 vslice; + +/* There no group slices in iops mode */
block/cfq-iosched.c cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 611
Quoted 10 lines
block/cfq-iosched.c +10
-0+if (iops_mode (cfqd)) +return 0 ; + +/* +* Equal to cfq_scale_slice(cfq_group_slice(cfqd, cfqg), cfqg). +* Add group weight beacuse it currently not in service tree. +*/ + vslice = (u64 )cfq_target_latency <<CFQ_SERVICE_SHIFT ; + vslice *=BLKIO_WEIGHT_DEFAULT ; +do_div (vslice, st->total_weight + cfqg->weight);
Above is not equivalent to cfq_scale_slice(cfq_group_slice(cfqd, cfqg), cfqg) as comment says.
you are not calculating cfq_group_slice(). Instead using cfq_target_latency.
Also it does not make sense. A higher weight group gets lower vslice and in turn gets put further away on the tree. This is reverse of what you want.
Quoted 7 lines
block/cfq-iosched.c +3
-0+return vslice; +} +static inline unsigned cfq_scaled_cfqq_slice (struct cfq_data *cfqd,struct cfq_queue *cfqq) {
block/cfq-iosched.c cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 910
Quoted 10 lines
block/cfq-iosched.c +4
-3@@ -884,16 +904,20 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)return ;/* -* Currently put the group at the end. Later implement something -* so that groups get lesser vtime based on their weights, so that -* if group does not loose all if it was not continuously backlogged. +* Bump vdisktime to be greater or equal min_vdisktime. +*/ + cfqg->vdisktime =max_vdisktime (cfqg->vdisktime, st->min_vdisktime); +
why do we need to do this?
block/cfq-iosched.c cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 917
Quoted 10 lines
block/cfq-iosched.c +3
-3+/* +* Put the group at the end, but save one slice from unused time. */ n =rb_last (&st->rb);if (n) { __cfqg =rb_entry_cfqg (n); - cfqg->vdisktime = __cfqg->vdisktime +CFQ_IDLE_DELAY ; - }else - cfqg->vdisktime = st->min_vdisktime; + cfqg->vdisktime = max_vdisktime(cfqg->vdisktime,
^^^^^^^
I think you meant st->min_vdisktime here?
block/cfq-iosched.c cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 923
Quoted 6 lines
block/cfq-iosched.c +3
-0+ __cfqg->vdisktime - + cfq_group_vslice(cfqd, cfqg)); + }cfq_group_service_tree_add (st, cfqg); }
Thanks
Vivek
Quoted 9 lines · Vivek Goyal
Quoted 5 lines · Konstantin Khlebnikov
This patch queue awakened cfq-groups according its current vdisktime, it try to save upto one group timeslice from unused virtual disk time. Thus group does not loses everything, if it was not continuously backlogged.
Signed-off-by Konstantin Khlebnikov<[email protected]>I think this patch is not required till we start preemption across groups? Any more details of actual use will help.
I saw some problems with fairness and latency between groups with parallel intensive IO and interactive groups -- cfq always put interactive groups at the end, so its latency is extremely high. With this patch interactive groups got real chance to be scheduled much earlier. I'm sorry, I can not show simple test-cases right now.
Quoted 34 lines
Quoted 20 lines
--- block/cfq-iosched.c | 36 ++++++++++++++++++++++++++++++------ 1 files changed, 30 insertions(+), 6 deletions(-)block/cfq-iosched.c +7
-0@@ -592,6 +592,26 @@ cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg)return cfq_target_latency * cfqg->weight / st->total_weight; } +static inline u64 +cfq_group_vslice (struct cfq_data *cfqd,struct cfq_group *cfqg) +{ +struct cfq_rb_root *st =&cfqd->grp_service_tree; +u64 vslice; + +/* There no group slices in iops mode */ block/cfq-iosched.c cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 611
Quoted 10 lines
block/cfq-iosched.c +10
-0+if (iops_mode (cfqd)) +return 0 ; + +/* +* Equal to cfq_scale_slice(cfq_group_slice(cfqd, cfqg), cfqg). +* Add group weight beacuse it currently not in service tree. +*/ + vslice = (u64 )cfq_target_latency<<CFQ_SERVICE_SHIFT ; + vslice *=BLKIO_WEIGHT_DEFAULT ; +do_div (vslice, st->total_weight + cfqg->weight);Above is not equivalent to
cfq_scale_slice(cfq_group_slice(cfqd, cfqg), cfqg)as comment says.
Quoted 1 line
you are not calculating
cfq_group_slice(). Instead usingcfq_target_latency.
No, this this expression gives the same value as cfq_scale_slice(cfq_group_slice()) after the group will be added to service tree. It is equal to slice that the group will receive if it will be queued immediately after the addition.
Quoted 14 lines
Also it does not make sense. A higher weight group gets lower vslice and in turn gets put further away on the tree. This is reverse of what you want.
Quoted 9 lines
block/cfq-iosched.c +3
-0+return vslice; +} +static inline unsigned cfq_scaled_cfqq_slice (struct cfq_data *cfqd,struct cfq_queue *cfqq) {@@ -884,16 +904,20 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)return ;
Quoted 10 lines
block/cfq-iosched.c cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 910
Quoted 8 lines
block/cfq-iosched.c +4
-3/* -* Currently put the group at the end. Later implement something -* so that groups get lesser vtime based on their weights, so that -* if group does not loose all if it was not continuously backlogged. +* Bump vdisktime to be greater or equal min_vdisktime. +*/ + cfqg->vdisktime =max_vdisktime (cfqg->vdisktime, st->min_vdisktime); +why do we need to do this?
Time should not go back, it's dangerous.
Quoted 12 lines
block/cfq-iosched.c cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 917
Quoted 11 lines
block/cfq-iosched.c +3
-3+/* +* Put the group at the end, but save one slice from unused time. */ n =rb_last (&st->rb);if (n) { __cfqg =rb_entry_cfqg (n); - cfqg->vdisktime = __cfqg->vdisktime +CFQ_IDLE_DELAY ; - }else - cfqg->vdisktime = st->min_vdisktime; + cfqg->vdisktime = max_vdisktime(cfqg->vdisktime,^^^^^^^
Quoted 1 line
I think you meant
st->min_vdisktimehere?
No, I adjust group vdisktime to put it at the end, but save up to one slice. Although there may be a problem with the overlap, with wakeup after looong sleep..
Quoted 9 lines
block/cfq-iosched.c cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) · line 923
Quoted 6 lines
block/cfq-iosched.c +3
-0+ __cfqg->vdisktime - + cfq_group_vslice(cfqd, cfqg)); + }cfq_group_service_tree_add (st, cfqg); }Thanks
Vivek