From: Kiyoshi Ueda Subject: dm-mpath: interface change for service-time dynamic load balancer References: FATE#303862,FATE#302108 This patch changes path selector interfaces for service-time oriented dynamic load balancer. To calculate the service time for an incoming I/O correctly, the load balancer needs the size of the incoming I/O when selecting the next path. Signed-off-by: Kiyoshi Ueda Signed-off-by: Jun'ichi Nomura Signed-off-by: Hannes Reinecke --- drivers/md/dm-least-pending.c | 4 ++-- drivers/md/dm-mpath.c | 27 ++++++++++++++++----------- drivers/md/dm-path-selector.h | 9 ++++++--- drivers/md/dm-queue-length.c | 8 +++++--- drivers/md/dm-round-robin.c | 2 +- 5 files changed, 30 insertions(+), 20 deletions(-) --- a/drivers/md/dm-least-pending.c +++ b/drivers/md/dm-least-pending.c @@ -172,7 +172,7 @@ static int lpp_reinstate_path(struct pat } static struct dm_path *lpp_select_path(struct path_selector *ps, - unsigned *repeat_count) + unsigned *repeat_count, size_t nr_bytes) { struct selector *s = ps->context; struct path_info *pi, *next, *least_io_path = NULL; @@ -199,7 +199,7 @@ static struct dm_path *lpp_select_path(s return least_io_path->path; } -static int lpp_end_io(struct path_selector *ps, struct dm_path *path) +static int lpp_end_io(struct path_selector *ps, struct dm_path *path, size_t nr_bytes) { struct path_info *pi = NULL; --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c @@ -99,6 +99,7 @@ struct multipath { */ struct dm_mpath_io { struct pgpath *pgpath; + size_t nr_bytes; }; typedef int (*action_fn) (struct pgpath *pgpath); @@ -246,11 +247,12 @@ static void __switch_pg(struct multipath m->pg_init_count = 0; } -static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg) +static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg, + size_t nr_bytes) { struct dm_path *path; - path = pg->ps.type->select_path(&pg->ps, &m->repeat_count); + path = pg->ps.type->select_path(&pg->ps, &m->repeat_count, nr_bytes); if (!path) return -ENXIO; @@ -262,7 +264,7 @@ static int __choose_path_in_pg(struct mu return 0; } -static void __choose_pgpath(struct multipath *m) +static void __choose_pgpath(struct multipath *m, size_t nr_bytes) { struct priority_group *pg; unsigned bypassed = 1; @@ -274,12 +276,12 @@ static void __choose_pgpath(struct multi if (m->next_pg) { pg = m->next_pg; m->next_pg = NULL; - if (!__choose_path_in_pg(m, pg)) + if (!__choose_path_in_pg(m, pg, nr_bytes)) return; } /* Don't change PG until it has no remaining paths */ - if (m->current_pg && !__choose_path_in_pg(m, m->current_pg)) + if (m->current_pg && !__choose_path_in_pg(m, m->current_pg, nr_bytes)) return; /* @@ -291,7 +293,7 @@ static void __choose_pgpath(struct multi list_for_each_entry(pg, &m->priority_groups, list) { if (pg->bypassed == bypassed) continue; - if (!__choose_path_in_pg(m, pg)) + if (!__choose_path_in_pg(m, pg, nr_bytes)) return; } } while (bypassed--); @@ -322,6 +324,7 @@ static int map_io(struct multipath *m, s struct dm_mpath_io *mpio, unsigned was_queued) { int r = DM_MAPIO_REMAPPED; + size_t nr_bytes = blk_rq_bytes(clone); unsigned long flags; struct pgpath *pgpath; struct block_device *bdev; @@ -331,7 +334,7 @@ static int map_io(struct multipath *m, s /* Do we need to select a new pgpath? */ if (!m->current_pgpath || (!m->queue_io && (m->repeat_count && --m->repeat_count == 0))) - __choose_pgpath(m); + __choose_pgpath(m, nr_bytes); pgpath = m->current_pgpath; @@ -358,9 +361,11 @@ static int map_io(struct multipath *m, s r = -EIO; /* Failed */ mpio->pgpath = pgpath; + mpio->nr_bytes = nr_bytes; if (r == DM_MAPIO_REMAPPED && pgpath->pg->ps.type->start_io) - pgpath->pg->ps.type->start_io(&pgpath->pg->ps, &pgpath->path); + pgpath->pg->ps.type->start_io(&pgpath->pg->ps, &pgpath->path, + nr_bytes); spin_unlock_irqrestore(&m->lock, flags); @@ -440,7 +445,7 @@ static void process_queued_ios(struct wo goto out; if (!m->current_pgpath) - __choose_pgpath(m); + __choose_pgpath(m, 1 << 19); /* Assume 512 KB */ pgpath = m->current_pgpath; @@ -1193,7 +1198,7 @@ static int multipath_end_io(struct dm_ta if (pgpath) { ps = &pgpath->pg->ps; if (ps->type->end_io) - ps->type->end_io(ps, &pgpath->path); + ps->type->end_io(ps, &pgpath->path, mpio->nr_bytes); } mempool_free(mpio, m->mpio_pool); @@ -1412,7 +1417,7 @@ static int multipath_ioctl(struct dm_tar spin_lock_irqsave(&m->lock, flags); if (!m->current_pgpath) - __choose_pgpath(m); + __choose_pgpath(m, 1 << 19); /* Assume 512KB */ if (m->current_pgpath) { bdev = m->current_pgpath->path.dev->bdev; --- a/drivers/md/dm-path-selector.h +++ b/drivers/md/dm-path-selector.h @@ -56,7 +56,8 @@ struct path_selector_type { * the path fails. */ struct dm_path *(*select_path) (struct path_selector *ps, - unsigned *repeat_count); + unsigned *repeat_count, + size_t nr_bytes); /* * Notify the selector that a path has failed. @@ -75,8 +76,10 @@ struct path_selector_type { int (*status) (struct path_selector *ps, struct dm_path *path, status_type_t type, char *result, unsigned int maxlen); - int (*start_io) (struct path_selector *ps, struct dm_path *path); - int (*end_io) (struct path_selector *ps, struct dm_path *path); + int (*start_io) (struct path_selector *ps, struct dm_path *path, + size_t nr_bytes); + int (*end_io) (struct path_selector *ps, struct dm_path *path, + size_t nr_bytes); }; /* Register a path selector */ --- a/drivers/md/dm-queue-length.c +++ b/drivers/md/dm-queue-length.c @@ -142,7 +142,7 @@ static inline int ql_compare_qlen(struct } static struct dm_path *ql_select_path(struct path_selector *ps, - unsigned *repeat_count) + unsigned *repeat_count, size_t nr_bytes) { struct selector *s = (struct selector *) ps->context; struct path_info *cpi = NULL, *spi = NULL; @@ -166,7 +166,8 @@ static struct dm_path *ql_select_path(st return spi ? spi->path : NULL; } -static int ql_start_io(struct path_selector *ps, struct dm_path *path) +static int ql_start_io(struct path_selector *ps, struct dm_path *path, + size_t nr_bytes) { struct path_info *pi = path->pscontext; @@ -175,7 +176,8 @@ static int ql_start_io(struct path_selec return 0; } -static int ql_end_io(struct path_selector *ps, struct dm_path *path) +static int ql_end_io(struct path_selector *ps, struct dm_path *path, + size_t nr_bytes) { struct path_info *pi = path->pscontext; --- a/drivers/md/dm-round-robin.c +++ b/drivers/md/dm-round-robin.c @@ -160,7 +160,7 @@ static int rr_reinstate_path(struct path } static struct dm_path *rr_select_path(struct path_selector *ps, - unsigned *repeat_count) + unsigned *repeat_count, size_t nr_bytes) { struct selector *s = (struct selector *) ps->context; struct path_info *pi = NULL;