Skip to content

Commit 8b9276e

Browse files
simonjbeaumontjohnelse
authored andcommitted
Fix host choice for vGPU allocation
The ordering for the group_by function when grouping hosts based on "best" PGPU was not specified. Now the hosts should be ordered and grouped correctly according to GPU_group.allocation_algorithm. Signed-off-by: Si Beaumont <[email protected]>
1 parent d76f3c8 commit 8b9276e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

ocaml/xapi/helpers.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,10 @@ let group_by f list =
510510

511511
(** Groups list elements by equality of result of function application sorted
512512
* in order of that result *)
513-
let group_by ?(descending=false) f list =
514-
match descending with
515-
| true -> group_by f list
516-
| false -> List.rev (group_by f list)
513+
let group_by ~ordering f list =
514+
match ordering with
515+
| `descending -> group_by f list
516+
| `ascending -> List.rev (group_by f list)
517517

518518
(** Schwarzian transform sort *)
519519
let sort_by_schwarzian ?(descending=false) f list =

ocaml/xapi/xapi_vm_helpers.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,13 @@ let group_hosts_by_best_pgpu_in_group ~__context gpu_group vgpu_type =
609609
(List.map (fun pgpu -> Db.PGPU.get_host ~__context ~self:pgpu)
610610
viable_pgpus)
611611
in
612-
Helpers.group_by
612+
let ordering =
613+
match Db.GPU_group.get_allocation_algorithm ~__context ~self:gpu_group with
614+
| `depth_first -> `ascending | `breadth_first -> `descending
615+
in
616+
Helpers.group_by ~ordering
613617
(fun host ->
614-
let group_by_capacity pgpus =
615-
(match Db.GPU_group.get_allocation_algorithm ~__context ~self:gpu_group with
616-
| `depth_first -> Helpers.group_by ~descending:false
617-
| `breadth_first -> Helpers.group_by ~descending:true)
618+
let group_by_capacity pgpus = Helpers.group_by ~ordering
618619
(fun pgpu -> Xapi_pgpu_helpers.get_remaining_capacity ~__context ~self:pgpu ~vgpu_type)
619620
pgpus
620621
in

0 commit comments

Comments
 (0)